From c6147de49a2bbcef988fd55ed4c1ab7b5b5fda15 Mon Sep 17 00:00:00 2001 From: DataEraserC <102341238+DataEraserC@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:07:37 +0800 Subject: [PATCH] Add github workflow --- .github/workflows/nightly.yml | 55 +++++++++++++++++++++++++++++++++++ .github/workflows/push.yml | 33 +++++++++++++++++++++ .github/workflows/release.yml | 27 +++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 .github/workflows/nightly.yml create mode 100644 .github/workflows/push.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..6335e93 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,55 @@ +name: 最新版 + +on: [push, pull_request] + +env: + BINARY_PREFIX: "zbp_" + BINARY_SUFFIX: "" + PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request." + LD_FLAGS: "-w -s" + +jobs: + build: + name: Build binary CI + runs-on: ubuntu-latest + strategy: + matrix: + # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 + goos: [linux, windows] + goarch: ["386", amd64, arm, arm64] + exclude: + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + fail-fast: true + steps: + - uses: actions/checkout@master + - name: Setup Go environment + uses: actions/setup-go@master + with: + go-version: '1.20' + - name: Cache downloaded module + uses: actions/cache@master + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }} + - name: Build binary file + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + IS_PR: ${{ !!github.head_ref }} + run: | + if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi + if $IS_PR ; then echo $PR_PROMPT; fi + export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX" + export CGO_ENABLED=0 + go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" . + - name: Upload artifact + uses: actions/upload-artifact@master + if: ${{ !github.head_ref }} + with: + name: ${{ matrix.goos }}_${{ matrix.goarch }} + path: output/ diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..e30c986 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,33 @@ +name: PushLint +on: [ push ] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: '1.20' + + - name: Check out code into the Go module directory + uses: actions/checkout@master + + - name: golangci-lint + uses: golangci/golangci-lint-action@master + with: + version: latest + + - name: Commit back + if: ${{ !github.head_ref }} + continue-on-error: true + run: | + git config --local user.name 'github-actions[bot]' + git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add --all + git commit -m "🎨 改进代码样式" + + - name: Create Pull Request + if: ${{ !github.head_ref }} + continue-on-error: true + uses: peter-evans/create-pull-request@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d56b298 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,27 @@ +name: 发行版 +on: + push: + tags: + - 'v*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: '1.20' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@master + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}