ci: 新增 Gitea Actions 自动编译 linux amd64/arm64
- 每次推送在 debian runner 上交叉编译两个架构的二进制 - 通过 ldflags 注入版本号(分支为 分支名-短SHA,tag 为 tag 名) - 推送 v* 标签时自动创建 Release 并上传二进制
This commit is contained in:
@@ -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"
|
||||||
Reference in New Issue
Block a user