From 6d928e59352da3bfd6c541c383828b31eff7a46c Mon Sep 17 00:00:00 2001 From: m1saka Date: Sat, 4 Jul 2026 21:30:59 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=20Gitea=20Actions=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=BC=96=E8=AF=91=20linux=20amd64/arm64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 每次推送在 debian runner 上交叉编译两个架构的二进制 - 通过 ldflags 注入版本号(分支为 分支名-短SHA,tag 为 tag 名) - 推送 v* 标签时自动创建 Release 并上传二进制 --- .gitea/workflows/build.yml | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .gitea/workflows/build.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..e8570d7 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,56 @@ +name: build + +on: + push: + branches: + - "**" + tags: + - "v*" + +jobs: + build: + runs-on: debian + strategy: + matrix: + include: + - goarch: amd64 + output: docker-compose-backup-linux-amd64 + - goarch: arm64 + output: docker-compose-backup-linux-arm64 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.26" + + - name: Build ${{ matrix.output }} + env: + CGO_ENABLED: "0" + GOOS: linux + GOARCH: ${{ matrix.goarch }} + run: | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then + VERSION="${GITHUB_REF_NAME}" + else + VERSION="${GITHUB_REF_NAME}-${GITHUB_SHA::7}" + fi + go build -trimpath \ + -ldflags "-s -w -X git.misaka.ren/M1saka/docker_backup/cmd/backup.Version=${VERSION}" \ + -o "${{ matrix.output }}" . + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.output }} + path: ${{ matrix.output }} + + - name: Attach to release + if: startsWith(github.ref, 'refs/tags/v') + uses: akkuman/gitea-release-action@v1 + with: + files: ${{ matrix.output }} + env: + NODE_OPTIONS: "--experimental-fetch"