From 332469c4e9577c78e20a4ce3e65a30ff14128d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Fri, 15 May 2026 10:08:27 +0800 Subject: [PATCH] ci: add publish binary workflow Add workflow_dispatch workflow for building and publishing cross-platform binaries. Supports selecting branch/tag and target platform (all or specific). Windows artifacts are zipped, Linux/macOS are tar.gz. When triggered by a tag, artifacts are attached to the GitHub Release. Co-authored-by: CoStrict --- .github/workflows/publish-binary.yml | 196 +++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 .github/workflows/publish-binary.yml diff --git a/.github/workflows/publish-binary.yml b/.github/workflows/publish-binary.yml new file mode 100644 index 000000000..5b6016b5b --- /dev/null +++ b/.github/workflows/publish-binary.yml @@ -0,0 +1,196 @@ +name: Publish Binary + +on: + workflow_dispatch: + inputs: + ref: + description: '分支或 tag (例如: main 或 v4.0.23)' + required: true + type: string + platform: + description: '编译平台' + required: true + type: choice + options: + - all + - linux + - linux-baseline + - linux-musl + - linux-musl-baseline + - win + - win-baseline + - mac-arm64 + - mac-x64 + - mac-x64-baseline + +permissions: + contents: write + +jobs: + resolve: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.resolve.outputs.version }} + is_tag: ${{ steps.resolve.outputs.is_tag }} + matrix: ${{ steps.resolve.outputs.matrix }} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + ref: ${{ inputs.ref }} + + - name: Resolve version and matrix + id: resolve + run: | + REF="${{ inputs.ref }}" + + # Determine if ref is a tag + if git rev-parse --verify "refs/tags/${REF}" >/dev/null 2>&1; then + VERSION="${REF#v}" + IS_TAG=true + else + VERSION=$(git rev-parse --short HEAD) + IS_TAG=false + fi + + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "is_tag=${IS_TAG}" >> "$GITHUB_OUTPUT" + + # Build matrix based on platform input + case "${{ inputs.platform }}" in + all) + MATRIX='["linux-x64","linux-x64-baseline","linux-x64-musl","linux-x64-musl-baseline","windows-x64","windows-x64-baseline","darwin-arm64","darwin-x64","darwin-x64-baseline"]' + ;; + linux) + MATRIX='["linux-x64"]' + ;; + linux-baseline) + MATRIX='["linux-x64-baseline"]' + ;; + linux-musl) + MATRIX='["linux-x64-musl"]' + ;; + linux-musl-baseline) + MATRIX='["linux-x64-musl-baseline"]' + ;; + win) + MATRIX='["windows-x64"]' + ;; + win-baseline) + MATRIX='["windows-x64-baseline"]' + ;; + mac-arm64) + MATRIX='["darwin-arm64"]' + ;; + mac-x64) + MATRIX='["darwin-x64"]' + ;; + mac-x64-baseline) + MATRIX='["darwin-x64-baseline"]' + ;; + *) + echo "Unknown platform: ${{ inputs.platform }}" + exit 1 + ;; + esac + + echo "matrix=${MATRIX}" >> "$GITHUB_OUTPUT" + + build: + needs: resolve + runs-on: ubuntu-latest + strategy: + matrix: + target: ${{ fromJson(needs.resolve.outputs.matrix) }} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: ${{ inputs.ref }} + + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + bun-version: "1.3.11" + + - name: Setup SSH for review agent generation + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.MY_SSH_PRIVATE_KEY }} + continue-on-error: true + + - name: Install dependencies + env: + CLAUDE_CODE_SKIP_CHROME_MCP_SETUP: "1" + run: bun install --frozen-lockfile + + - name: Build + run: bun run build + + - name: Compile + run: | + TARGET="${{ matrix.target }}" + case "$TARGET" in + linux-x64) + bun build dist/cli.js --compile --target=bun-linux-x64 --outfile "dist/csc-${TARGET}" + ;; + linux-x64-baseline) + bun build dist/cli.js --compile --target=bun-linux-x64-baseline --outfile "dist/csc-${TARGET}" + ;; + linux-x64-musl) + bun build dist/cli.js --compile --target=bun-linux-x64-musl --outfile "dist/csc-${TARGET}" + ;; + linux-x64-musl-baseline) + bun build dist/cli.js --compile --target=bun-linux-x64-musl-baseline --outfile "dist/csc-${TARGET}" + ;; + windows-x64) + bun build dist/cli.js --compile --target=bun-windows-x64 --outfile "dist/csc-${TARGET}.exe" + ;; + windows-x64-baseline) + bun build dist/cli.js --compile --target=bun-windows-x64-baseline --outfile "dist/csc-${TARGET}.exe" + ;; + darwin-arm64) + bun build dist/cli.js --compile --target=bun-darwin-arm64 --outfile "dist/csc-${TARGET}" + ;; + darwin-x64) + bun build dist/cli.js --compile --target=bun-darwin-x64 --outfile "dist/csc-${TARGET}" + ;; + darwin-x64-baseline) + bun build dist/cli.js --compile --target=bun-darwin-x64-baseline --outfile "dist/csc-${TARGET}" + ;; + esac + + - name: Package + run: | + VERSION="${{ needs.resolve.outputs.version }}" + TARGET="${{ matrix.target }}" + mkdir -p release + + if [[ "$TARGET" == windows* ]]; then + zip -j "release/csc-v${VERSION}-${TARGET}.zip" "dist/csc-${TARGET}.exe" + else + tar -czf "release/csc-v${VERSION}-${TARGET}.tar.gz" -C dist "csc-${TARGET}" + fi + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: csc-${{ matrix.target }} + path: release/* + + release: + needs: [resolve, build] + runs-on: ubuntu-latest + if: needs.resolve.outputs.is_tag == 'true' + steps: + - uses: actions/download-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + path: release + pattern: csc-* + merge-multiple: true + + - name: Create GitHub Release + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 + with: + tag_name: v${{ needs.resolve.outputs.version }} + name: v${{ needs.resolve.outputs.version }} + files: release/* + draft: false + prerelease: ${{ contains(needs.resolve.outputs.version, 'rc') || contains(needs.resolve.outputs.version, 'beta') || contains(needs.resolve.outputs.version, 'alpha') }}