From 545043fd430c5d570d02b2e414dfe3c30f071c34 Mon Sep 17 00:00:00 2001 From: Junlong Zhang Date: Mon, 11 Nov 2024 22:31:49 +0800 Subject: [PATCH] =?UTF-8?q?ci(release):=20=E6=B7=BB=E5=8A=A0=20GitHub=20Ac?= =?UTF-8?q?tions=20=E6=9E=84=E5=BB=BA=E5=92=8C=E5=8F=91=E5=B8=83=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2f9e66d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,53 @@ +name: Build and release + +on: + workflow_dispatch: + push: + tags: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-and-release: + runs-on: ubuntu-latest + strategy: + matrix: + goos: [ windows ] + goarch: [ amd64, arm64 ] + + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Get short commit SHA + id: commit-sha + run: echo "COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Build for ${{ matrix.goos }}/${{ matrix.goarch }} + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + LDFLAGS: '-s -w -X main.build=${{ env.COMMIT_SHA_SHORT }} -H=windowsgui' + run: | + mkdir -p bin + go version + go build -ldflags="$LDFLAGS" -trimpath -o bin/gohomo-${{ matrix.goos }}-${{ matrix.goarch }}-${{ env.COMMIT_SHA_SHORT }}.exe . + echo "${{ env.COMMIT_SHA_SHORT }}" > bin/version.txt + + - name: Upload release assets + uses: softprops/action-gh-release@v2 + with: + files: bin/* + make_latest: true