From 33117740e5877371676d960e1db5ce27a56d5054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B4=BA?= Date: Sun, 19 Oct 2025 18:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ci=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflow/ci.yml | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/.gitea/workflow/ci.yml b/.gitea/workflow/ci.yml index e69de29..4d45198 100644 --- a/.gitea/workflow/ci.yml +++ b/.gitea/workflow/ci.yml @@ -0,0 +1,59 @@ +name: CI Cross-Compile + +on: + push: + branches: [ main ] + pull_request: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + goos: [linux, windows, darwin] + goarch: [amd64] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.22.x' + + - name: Cache Go build/mod + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ matrix.goos }}-${{ matrix.goarch }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download deps + run: go mod download + + - name: Cross-compile (${{ matrix.goos }}/${{ matrix.goarch }}) + env: + CGO_ENABLED: "0" # 关闭 cgo,便于纯交叉构建 + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: | + mkdir -p dist/${GOOS}-${GOARCH} + OUT="dist/${GOOS}-${GOARCH}/app" + if [ "${GOOS}" = "windows" ]; then OUT="${OUT}.exe"; fi + # -trimpath/-ldflags 让产物更小更可复现;按你的入口调整 ./cmd/app + go build -trimpath -ldflags="-s -w" -o "${OUT}" ./cmd/app + echo "Built ${OUT}" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: app-${{ matrix.goos }}-${{ matrix.goarch }} + path: dist/${{ matrix.goos }}-${{ matrix.goarch }}/* + if-no-files-found: error