From 4a2b143250de7fa866962707090421732bec4e02 Mon Sep 17 00:00:00 2001 From: Yunlq <140733746+Yunlq@users.noreply.github.com> Date: Mon, 25 Aug 2025 16:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86workflow=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=92=8C=E4=BA=A4=E5=8F=89=E7=BC=96=E8=AF=91=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cross_compile.sh | 15 +++- .github/workflows/build.yml | 114 +++++++++++++++++------- .github/workflows/publishNewFormula.yml | 17 ++-- .github/workflows/test.yml | 24 +++-- .github/workflows/triggerDebRepo.yml | 10 ++- 5 files changed, 132 insertions(+), 48 deletions(-) diff --git a/.cross_compile.sh b/.cross_compile.sh index d8f6eee..d291451 100644 --- a/.cross_compile.sh +++ b/.cross_compile.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail + +set -Eeuo pipefail # -------- Config -------- DIST_PREFIX="nexttrace" @@ -32,8 +33,9 @@ mkdir -p -- "${TARGET_DIR}" # -------- Pure Go targets (CGO off) -------- for pl in ${PLATFORMS}; do export CGO_ENABLED=0 - export GOOS="$(echo "${pl}" | cut -d'/' -f1)" - export GOARCH="$(echo "${pl}" | cut -d'/' -f2)" + GOOS="${pl%%/*}" + GOARCH="${pl#*/}" + export GOOS GOARCH TARGET="${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}" if [[ "${GOOS}" == "windows" ]]; then @@ -42,6 +44,13 @@ for pl in ${PLATFORMS}; do echo "build => ${TARGET}" go build "${GO_BUILD_FLAGS[@]}" -o "${TARGET}" -ldflags "${LD_BASE}" + + # Extra soft-float variants for linux/mips and linux/mipsle + if [[ "${GOOS}" == "linux" && ( "${GOARCH}" == "mips" || "${GOARCH}" == "mipsle" ) ]]; then + TARGET_SOFT="${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}_softfloat" + echo "build => ${TARGET_SOFT} (GOMIPS=softfloat)" + GOMIPS=softfloat go build "${GO_BUILD_FLAGS[@]}" -o "${TARGET_SOFT}" -ldflags "${LD_BASE}" + fi done # -------- linux/armv7(CGO off)-------- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 47957a4..23f93de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,16 @@ name: Build & Release +permissions: + contents: read + +defaults: + run: + shell: bash + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + on: workflow_dispatch: push: @@ -18,17 +29,12 @@ on: - "go.sum" - ".github/workflows/*.yml" -permissions: - contents: write - -concurrency: - group: build-release-${{ github.ref }} - cancel-in-progress: true - jobs: build: runs-on: ubuntu-latest + continue-on-error: ${{ matrix.allow_fail || false }} strategy: + fail-fast: false matrix: goos: [windows, freebsd, openbsd, linux, dragonfly] goarch: [amd64, 386] @@ -41,7 +47,7 @@ jobs: - { goos: linux, goarch: arm, goarm: 5 } - { goos: android, goarch: arm64 } - { goos: windows, goarch: arm64 } - - { goos: windows, goarch: arm, goarm: 7 } + - { goos: windows, goarch: arm, goarm: 7, allow_fail: true } # windows/arm 计划于 Go 1.26 移除 - { goos: linux, goarch: arm64 } - { goos: linux, goarch: riscv64 } - { goos: linux, goarch: mips64 } @@ -64,7 +70,11 @@ jobs: GOARM: ${{ matrix.goarm }} GOMIPS: ${{ matrix.gomips }} steps: - - uses: actions/checkout@v5 + - name: Checkout codebase + uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true - name: Set up Go (built-in cache) uses: actions/setup-go@v5 @@ -73,9 +83,20 @@ jobs: check-latest: true cache: true + - name: Go toolchain info + run: | + set -Eeuo pipefail + go version && go env && echo "Supported targets (dist list):" && go tool dist list | sort -u + + - name: Verify target is supported + run: | + set -Eeuo pipefail + if ! go tool dist list | grep -qx -- "${GOOS}/${GOARCH}"; then echo "Unsupported target: ${GOOS}/${GOARCH}"; exit 1; fi + echo "OK: ${GOOS}/${GOARCH} is supported." + - name: Resolve build metadata run: | - set -e + set -Eeuo pipefail BUILD_VERSION="$(git describe --tags --always 2>/dev/null || echo dev)" BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" COMMIT_SHA1="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)" @@ -86,10 +107,10 @@ jobs: if [ "${GOOS}" = "windows" ]; then NAME="${NAME}.exe"; fi if [ "${GOMIPS:-}" = "softfloat" ]; then NAME="${NAME}_softfloat"; fi - echo "BUILD_VERSION=${BUILD_VERSION}" >> $GITHUB_ENV - echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV - echo "COMMIT_SHA1=${COMMIT_SHA1}" >> $GITHUB_ENV - echo "ASSET_NAME=${NAME}" >> $GITHUB_ENV + echo "BUILD_VERSION=${BUILD_VERSION}" >> "$GITHUB_ENV" + echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV" + echo "COMMIT_SHA1=${COMMIT_SHA1}" >> "$GITHUB_ENV" + echo "ASSET_NAME=${NAME}" >> "$GITHUB_ENV" - name: Get project dependencies run: go mod download @@ -108,17 +129,23 @@ jobs: with: name: ${{ env.ASSET_NAME }} path: dist/${{ env.ASSET_NAME }} + if-no-files-found: error build-darwin: runs-on: macos-latest strategy: + fail-fast: false matrix: { goarch: [ amd64, arm64 ] } env: GOOS: darwin GOARCH: ${{ matrix.goarch }} CGO_ENABLED: 1 steps: - - uses: actions/checkout@v5 + - name: Checkout codebase + uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true - name: Set up Go (built-in cache) uses: actions/setup-go@v5 @@ -127,9 +154,20 @@ jobs: check-latest: true cache: true + - name: Go toolchain info + run: | + set -Eeuo pipefail + go version && go env && echo "Supported targets (dist list):" && go tool dist list | sort -u + + - name: Verify target is supported + run: | + set -Eeuo pipefail + if ! go tool dist list | grep -qx -- "${GOOS}/${GOARCH}"; then echo "Unsupported target: ${GOOS}/${GOARCH}"; exit 1; fi + echo "OK: ${GOOS}/${GOARCH} is supported." + - name: Sanity check (Xcode/SDK/lipo/pcap) run: | - set -e + set -Eeuo pipefail xcode-select -p SDKROOT="$(xcrun --sdk macosx --show-sdk-path)" echo "$SDKROOT" @@ -140,22 +178,23 @@ jobs: - name: Resolve build metadata + Darwin CGO flags run: | - set -e + set -Eeuo pipefail SDKROOT="$(xcrun --sdk macosx --show-sdk-path)" if [ "${GOARCH}" = "amd64" ]; then ARCH_FLAG="-arch x86_64"; else ARCH_FLAG="-arch arm64"; fi - echo "CC=clang" >> $GITHUB_ENV - echo "CXX=clang++" >> $GITHUB_ENV - echo "CGO_CFLAGS=-isysroot ${SDKROOT} ${ARCH_FLAG} -mmacosx-version-min=11.0" >> $GITHUB_ENV - echo "CGO_LDFLAGS=-isysroot ${SDKROOT} ${ARCH_FLAG} -mmacosx-version-min=11.0" >> $GITHUB_ENV + CC="$(xcrun -f clang)"; CXX="$(xcrun -f clang++)" + echo "CC=${CC}" >> "$GITHUB_ENV" + echo "CXX=${CXX}" >> "$GITHUB_ENV" + echo "CGO_CFLAGS=-isysroot ${SDKROOT} ${ARCH_FLAG} -mmacosx-version-min=11.0" >> "$GITHUB_ENV" + echo "CGO_LDFLAGS=-isysroot ${SDKROOT} ${ARCH_FLAG} -mmacosx-version-min=11.0" >> "$GITHUB_ENV" BUILD_VERSION="$(git describe --tags --always 2>/dev/null || echo dev)" BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" COMMIT_SHA1="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)" NAME="nexttrace_${GOOS}_${GOARCH}" - echo "BUILD_VERSION=${BUILD_VERSION}" >> $GITHUB_ENV - echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV - echo "COMMIT_SHA1=${COMMIT_SHA1}" >> $GITHUB_ENV - echo "ASSET_NAME=${NAME}" >> $GITHUB_ENV + echo "BUILD_VERSION=${BUILD_VERSION}" >> "$GITHUB_ENV" + echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV" + echo "COMMIT_SHA1=${COMMIT_SHA1}" >> "$GITHUB_ENV" + echo "ASSET_NAME=${NAME}" >> "$GITHUB_ENV" - name: Get project dependencies run: go mod download @@ -174,6 +213,7 @@ jobs: with: name: ${{ env.ASSET_NAME }} path: dist/${{ env.ASSET_NAME }} + if-no-files-found: error # NEW: 构建 Universal,并上传为 Artifact(不依赖 tag) darwin-universal: @@ -189,7 +229,7 @@ jobs: - name: Make macOS Universal (amd64+arm64) run: | - set -e + set -Eeuo pipefail AMD64="dist/nexttrace_darwin_amd64" ARM64="dist/nexttrace_darwin_arm64" if [ -f "$AMD64" ] && [ -f "$ARM64" ]; then @@ -207,6 +247,7 @@ jobs: with: name: nexttrace_darwin_universal path: dist/nexttrace_darwin_universal + if-no-files-found: error # 发布时仅下载所有 Artifact(包含 universal),直接发布 release: @@ -221,16 +262,21 @@ jobs: merge-multiple: true path: dist_release - - name: List payload - run: ls -l dist_release | sed -n '1,300p' + - name: Show downloaded files + run: | + set -Eeuo pipefail + ls -lah dist_release + test -n "$(find dist_release -type f -print -quit)" || { echo "No artifacts found in dist_release"; exit 1; } - name: Create GitHub Release (draft) uses: softprops/action-gh-release@v2 with: draft: true + name: ${{ github.ref_name }} + tag_name: ${{ github.ref_name }} files: dist_release/* - env: - GITHUB_TOKEN: ${{ github.token }} + token: ${{ secrets.GT_TOKEN }} + fail_on_unmatched_files: true publish-new-formula: runs-on: ubuntu-latest @@ -239,19 +285,21 @@ jobs: steps: - name: config git run: | - git config --global user.email "${{ secrets.git_mail }}" - git config --global user.name "${{ secrets.git_name }}" + git config --global user.email "${{ secrets.GIT_MAIL }}" + git config --global user.name "${{ secrets.GIT_NAME }}" - name: Clone repo run: git clone https://github.com/nxtrace/homebrew-nexttrace.git - name: Exec script run: | + set -Eeuo pipefail cd homebrew-nexttrace bash genFormula.sh - name: Git Push run: | + set -Eeuo pipefail cd homebrew-nexttrace git add -A git commit -m 'Publish a new version with Formula' || true - git remote set-url origin https://${{ secrets.gt_token }}@github.com/nxtrace/homebrew-nexttrace.git + git remote set-url origin https://${{ secrets.GT_TOKEN }}@github.com/nxtrace/homebrew-nexttrace.git git push - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/.github/workflows/publishNewFormula.yml b/.github/workflows/publishNewFormula.yml index 65c6004..ee1983e 100644 --- a/.github/workflows/publishNewFormula.yml +++ b/.github/workflows/publishNewFormula.yml @@ -1,5 +1,9 @@ name: Publish New Formula +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + # Controls when the action will run. Workflow runs when manually triggered using the UI # or API. on: @@ -17,13 +21,14 @@ jobs: # Runs a single command using the runners shell - name: config git run: | - git config --global user.email "${{ secrets.git_mail }}" - git config --global user.name "${{ secrets.git_name }}" + git config --global user.email "${{ secrets.GIT_MAIL }}" + git config --global user.name "${{ secrets.GIT_NAME }}" - name: Clone repo run: | git clone https://github.com/nxtrace/homebrew-nexttrace.git - - name: Exec scipt + - name: Exec script run: | + set -Eeuo pipefail cd homebrew-nexttrace bash genFormula.sh # - name: setup SSH keys and known_hosts @@ -36,9 +41,11 @@ jobs: # SSH_AUTH_SOCK: /tmp/ssh_agent.sock - name: Git Push run: | + set -Eeuo pipefail cd homebrew-nexttrace - git commit -am 'Publish a new version with Formula' || true - git remote set-url origin https://${{ secrets.gt_token }}@github.com/nxtrace/homebrew-nexttrace.git + git add -A + git commit -m 'Publish a new version with Formula' || true + git remote set-url origin https://${{ secrets.GT_TOKEN }}@github.com/nxtrace/homebrew-nexttrace.git git push # env: # SSH_AUTH_SOCK: /tmp/ssh_agent.sock diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 08a75a4..ff4d9e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,12 @@ name: Test +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + on: push: branches: @@ -20,25 +27,32 @@ on: jobs: test: - permissions: - contents: read runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [windows-latest, ubuntu-latest, macos-latest] steps: - - name: Set up Go + - name: Checkout codebase + uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Set up Go (built-in cache) uses: actions/setup-go@v5 with: go-version: '1.25.x' - - name: Checkout codebase - uses: actions/checkout@v5 + check-latest: true + cache: true + - name: Test with unix if: ${{ matrix.os != 'windows-latest' }} + shell: bash run: | sudo go env -w GOTOOLCHAIN=go1.25.0+auto sudo go test -v -ldflags=-checklinkname=0 -covermode=count -coverprofile='coverage.out' ./... + - name: Test with windows if: ${{ matrix.os == 'windows-latest' }} run: | diff --git a/.github/workflows/triggerDebRepo.yml b/.github/workflows/triggerDebRepo.yml index db42df5..9756b7f 100644 --- a/.github/workflows/triggerDebRepo.yml +++ b/.github/workflows/triggerDebRepo.yml @@ -1,13 +1,19 @@ name: Trigger Deb Repo + +concurrency: + group: ${{ github.workflow }}-${{ github.event.release.id }} + cancel-in-progress: true + on: release: - types: [published] + types: [published, prereleased] + jobs: trigger-deb-repo: runs-on: ubuntu-latest steps: - env: - GITHUB_TOKEN: ${{ secrets.GT_Token }} # 操作 deb 仓库的 PAT + GITHUB_TOKEN: ${{ secrets.GT_TOKEN }} # 操作 deb 仓库的 PAT run: | curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \