Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
funnyzak committed Feb 6, 2024
0 parents commit 3e8902f
Show file tree
Hide file tree
Showing 45 changed files with 2,016 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; https://editorconfig.org/

root = true

[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_style = tab
indent_size = 2

[*.md]
indent_size = 2
trim_trailing_whitespace = false

eclint_indent_style = unset

[Dockerfile]
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Report a bug
description: ———
labels: [bug]
body:
- type: markdown
attributes:
value: |
# Thanks for reporting this bug!
Help us replicate and find a fix for the issue by filling in this form.
- type: textarea
attributes:
label: Description
description: |
Describe the issue and how to replicate it. If possible, please include
a minimal example to reproduce the issue.
validations:
required: true
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom Issue Template
about: Tell us something related to the project or general discussion
title: ''
labels: question
---

**Are there certain things to report that are not a bug or feature?**
Please tell us as exactly as possible about your request, thanks.
We will reply as soon as possible.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Suggest an improvement or new feature
description: ———
labels: [enhancement]
body:
- type: markdown
attributes:
value: |
# Thanks for filing this feature request!
Help us understanding this feature and the need for it better by filling in this form.
- type: textarea
attributes:
label: Description
description: Describe the feature in detail
validations:
required: true
- type: textarea
attributes:
label: Why
description: Why should we add this feature? What are potential use cases for it?
validations:
required: true
- type: textarea
attributes:
label: Alternatives
description: Describe the alternatives you have considered, or existing workarounds
validations:
required: true
16 changes: 16 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
daysUntilStale: 15
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
99 changes: 99 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Build

on:
push:
paths-ignore:
- 'README*'
- 'LICENSE'
- '.editorconfig'
- '.github/**'
- '.gitignore'
- 'makefile'
- 'config.yaml.example'
- 'script/**'
pull_request:
paths-ignore:
- 'README*'
- 'LICENSE'
- '.editorconfig'
- '.github/**'
- '.gitignore'
- 'makefile'
- 'config.yaml.example'
- 'script/**'
workflow_dispatch:
inputs:
tag:
description: "build a binary with the specified git tag, enter a git tag."
required: false
type: string
default: ''
workflow_call:
inputs:
tag:
description: "Build a binary with the specified git tag, enter a git tag."
required: false
type: string
default: ''

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
VERSION_NAME: ${{ steps.set_version.outputs.VERSION_NAME }}
REPO_NAME: ${{ steps.set_version.outputs.REPO_NAME }}
steps:
- name: Set version
id: set_version
run: |
{
if [ -n "${{ github.event.inputs.tag }}" ]; then
echo "VERSION_NAME=${{ github.event.inputs.tag }}"
elif [ -n "${{ inputs.tag }}" ]; then
echo "VERSION_NAME=${{ inputs.tag }}"
else
echo "VERSION_NAME="
fi
echo "REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}')"
} >> $GITHUB_OUTPUT
build:
strategy:
matrix:
goos: [windows, linux, darwin]
goarch: [amd64, arm64]
include:
- goos: linux
goarch: arm
fail-fast: false

runs-on: ubuntu-latest
needs: [setup]
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.setup.outputs.VERSION_NAME }}

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum

- name: Build
run: |
go build -o build/${{ needs.setup.outputs.REPO_NAME }}${{ matrix.goos == 'windows' && '.exe' || ''}} cmd/main.go
ls -la build
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ needs.setup.outputs.REPO_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/*
131 changes: 131 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Docker Build and Push
on:
push:
paths-ignore:
- 'README*'
- 'LICENSE'
- '.editorconfig'
- '.github/**'
- '.gitignore'
- 'makefile'
- 'config.yaml.example'
- 'script/**'
workflow_call:
inputs:
tags:
description: 'Docker image tag list, multiple tags are separated by comma, e.g. 0.1.0,latest'
required: true
type: string
default: 'latest'
workflow_dispatch:
inputs:
tags:
required: true
type: string
default: 'latest'

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
if: github.ref_name == 'main' || github.ref_type == 'tag'|| github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
outputs:
TAG_NAME: ${{ steps.set_tag_name.outputs.TAG_NAME }}
BUILD_TRIGGER_DESCRIPTION: ${{ steps.set_tag_name.outputs.BUILD_TRIGGER_DESCRIPTION }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set tag name
id: set_tag_name
run: |
replace_comma_with_tag() {
new_tags=""
for tag in $(echo $1 | tr ',' ' '); do
new_tags="$new_tags ${{ github.repository }}:$tag"
done
echo $new_tags | tr ' ' ','
}
{
if [ -n "${{ github.event.inputs.tags }}" ]; then
echo "TAG_NAME=$(replace_comma_with_tag ${{ github.event.inputs.tags }})"
echo "BUILD_TRIGGER_DESCRIPTION=Triggered via workflow_dispatch with tag ${{ github.event.inputs.tags }}"
elif [ -n "${{ inputs.tags }}" ]; then
echo "TAG_NAME=$(replace_comma_with_tag ${{ inputs.tags }})"
echo "BUILD_TRIGGER_DESCRIPTION=Triggered via workflow_call with tag ${{ inputs.tags }}"
elif [ "${{ github.ref_type }}" == 'tag' ]; then
echo "TAG_NAME=${{ github.repository }}:${{ github.ref_name }}"
echo "BUILD_TRIGGER_DESCRIPTION=Triggered via tag ${{ github.ref_name }}"
elif [ "${{ github.event_name }}" == 'push' ]; then
echo "TAG_NAME=${{ github.repository }}:$(git rev-parse --short HEAD)"
echo "BUILD_TRIGGER_DESCRIPTION=Triggered via push to ${{ github.ref_name }}"
elif [ "${{ github.event.pull_request.merged }}" == 'true' ]; then
echo "TAG_NAME=${{ github.repository }}:$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)"
echo "BUILD_TRIGGER_DESCRIPTION=Triggered via pull request ${{ github.event.pull_request.number }}"
else
echo "TAG_NAME="
fi
} >> $GITHUB_OUTPUT
docker-release:
name: Publish Docker images
needs: [setup]
runs-on: ubuntu-latest
timeout-minutes: 20
if: needs.setup.outputs.TAG_NAME != ''
steps:
- name: Build trigger description
run: |
echo "The build trigger description is ${{ needs.setup.outputs.BUILD_TRIGGER_DESCRIPTION }}"
echo "The publish docker image tag is ${{ needs.setup.outputs.TAG_NAME }}"
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Cache go-build
uses: actions/cache@v4
with:
path: go-build
key: go-build-${{ hashFiles('**/go.sum') }}

- name: Cache go-pkg
uses: actions/cache@v4
with:
path: go-pkg
key: go-pkg-${{ hashFiles('**/go.sum') }}

- name: Inject go-build into Docker
uses: reproducible-containers/[email protected]
with:
cache-source: go-build
cache-target: /root/.cache/go-build

- name: Inject go-pkg into Docker
uses: reproducible-containers/[email protected]
with:
cache-source: go-pkg
cache-target: /go/pkg

- name: Docker build and push with tag name
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ needs.setup.outputs.TAG_NAME }}
platforms: |
linux/amd64
linux/arm64
linux/arm/v7
Loading

0 comments on commit 3e8902f

Please sign in to comment.