|
| 1 | +name: Binary Release |
| 2 | + |
| 3 | +# Auto Release creates the vX.Y.Z tag/release with GITHUB_TOKEN, and a tag |
| 4 | +# pushed by GITHUB_TOKEN cannot start a `push: tags` workflow. So this chains |
| 5 | +# off Auto Release's completion: it cross-compiles the mcpproxy commands |
| 6 | +# (mcpproxyd plus the configcheck / import-catalog / mcpsmoke operator tools) |
| 7 | +# and uploads the archives and checksums to that release. |
| 8 | +# |
| 9 | +# No Homebrew tap here, unlike alcatraz: this repo is private, so a formula |
| 10 | +# pointing at its release assets could not be downloaded by `brew install`. |
| 11 | +# Add the tap step if and when the repo goes public. |
| 12 | +# |
| 13 | +# The manual trigger re-publishes binaries for an existing tag — the recovery |
| 14 | +# path when a release was cut while this workflow was broken. |
| 15 | +on: |
| 16 | + workflow_run: |
| 17 | + workflows: ["Auto Release"] |
| 18 | + types: [completed] |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + version: |
| 22 | + description: "Existing release tag to (re)publish binaries for, without the leading v (e.g. 0.5.0)" |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: write |
| 28 | + |
| 29 | +# Serialize runs so back-to-back releases can't race on uploading assets to |
| 30 | +# the same release. |
| 31 | +concurrency: |
| 32 | + group: binary-release |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +jobs: |
| 36 | + resolve: |
| 37 | + name: Resolve release tag |
| 38 | + runs-on: ubuntu-latest |
| 39 | + # Auto Release runs on every push to main; act only on successful runs. |
| 40 | + # Manual dispatches name their tag explicitly and always proceed. |
| 41 | + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} |
| 42 | + outputs: |
| 43 | + publish: ${{ steps.dispatch.outputs.publish || steps.tag.outputs.publish }} |
| 44 | + version: ${{ steps.dispatch.outputs.version || steps.tag.outputs.version }} |
| 45 | + ref: ${{ steps.dispatch.outputs.ref || steps.tag.outputs.ref }} |
| 46 | + steps: |
| 47 | + - name: Use the dispatched tag |
| 48 | + id: dispatch |
| 49 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 50 | + env: |
| 51 | + RAW: ${{ inputs.version }} |
| 52 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | + # This job has write permissions: refuse to build/upload for a |
| 56 | + # malformed version or a tag that has no release. |
| 57 | + VERSION="${RAW#v}" |
| 58 | + if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 59 | + echo "::error::'${RAW}' is not a semver version (want X.Y.Z)" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + if ! gh release view "v${VERSION}" --repo "${{ github.repository }}" >/dev/null 2>&1; then |
| 63 | + echo "::error::release v${VERSION} does not exist in ${{ github.repository }} — create the release first, this workflow only attaches binaries" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + { |
| 67 | + echo "publish=true" |
| 68 | + echo "version=${VERSION}" |
| 69 | + echo "ref=v${VERSION}" |
| 70 | + } >> "$GITHUB_OUTPUT" |
| 71 | + echo "Publishing v${VERSION} (manual dispatch)" |
| 72 | +
|
| 73 | + - uses: actions/checkout@v4 |
| 74 | + if: ${{ github.event_name == 'workflow_run' }} |
| 75 | + with: |
| 76 | + # The exact commit Auto Release ran on. fetch-depth: 0 brings the |
| 77 | + # tags so we can read the version tag it created at that commit. |
| 78 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 79 | + fetch-depth: 0 |
| 80 | + |
| 81 | + - name: Find the release tag at this commit |
| 82 | + id: tag |
| 83 | + if: ${{ github.event_name == 'workflow_run' }} |
| 84 | + run: | |
| 85 | + set -euo pipefail |
| 86 | + # Auto Release tags the released commit vX.Y.Z, or tags nothing for |
| 87 | + # a skip-release PR or a direct push. Bind the published version to |
| 88 | + # that tag so source and version always match; skip when absent. |
| 89 | + TAG=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || true) |
| 90 | + if [ -z "$TAG" ]; then |
| 91 | + echo "No release tag at ${{ github.event.workflow_run.head_sha }}; nothing to publish." |
| 92 | + echo "publish=false" >> "$GITHUB_OUTPUT" |
| 93 | + else |
| 94 | + echo "publish=true" >> "$GITHUB_OUTPUT" |
| 95 | + echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" |
| 96 | + echo "ref=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT" |
| 97 | + echo "Publishing ${TAG}" |
| 98 | + fi |
| 99 | +
|
| 100 | + binaries: |
| 101 | + name: Build archives |
| 102 | + needs: resolve |
| 103 | + if: ${{ needs.resolve.outputs.publish == 'true' }} |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + ref: ${{ needs.resolve.outputs.ref }} |
| 109 | + |
| 110 | + - uses: actions/setup-go@v5 |
| 111 | + with: |
| 112 | + go-version: "1.26" |
| 113 | + |
| 114 | + - name: Cross-compile and package archives |
| 115 | + env: |
| 116 | + VERSION: ${{ needs.resolve.outputs.version }} |
| 117 | + run: | |
| 118 | + set -euo pipefail |
| 119 | + mkdir -p dist |
| 120 | + # CGO_ENABLED=0: the daemon uses no cgo, and a static binary runs on |
| 121 | + # any glibc/musl base image. -X main.version is read by |
| 122 | + # `mcpproxyd -version`; the other three commands have no version var, |
| 123 | + # so the flag is scoped to mcpproxyd only. |
| 124 | + for target in darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64; do |
| 125 | + os="${target%%/*}"; arch="${target##*/}" |
| 126 | + ext=""; [ "$os" = windows ] && ext=".exe" |
| 127 | + stage="dist/stage_${os}_${arch}" |
| 128 | + mkdir -p "$stage" |
| 129 | + for cmd in mcpproxyd configcheck import-catalog mcpsmoke; do |
| 130 | + ldflags="-s -w" |
| 131 | + [ "$cmd" = mcpproxyd ] && ldflags="$ldflags -X main.version=v${VERSION}" |
| 132 | + CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \ |
| 133 | + go build -trimpath -ldflags "$ldflags" \ |
| 134 | + -o "${stage}/${cmd}${ext}" "./cmd/${cmd}" |
| 135 | + done |
| 136 | + cp README.md config.example.yaml "$stage/" |
| 137 | + cp -r examples "$stage/examples" |
| 138 | + if [ "$os" = windows ]; then |
| 139 | + (cd "$stage" && zip -qr "../mcpproxy_${VERSION}_${os}_${arch}.zip" .) |
| 140 | + else |
| 141 | + tar -czf "dist/mcpproxy_${VERSION}_${os}_${arch}.tar.gz" -C "$stage" . |
| 142 | + fi |
| 143 | + done |
| 144 | + rm -rf dist/stage_* |
| 145 | + # Bare globs (no ./ prefix): installers grep checksums.txt for the |
| 146 | + # exact archive name. |
| 147 | + (cd dist && sha256sum -- *.tar.gz *.zip > checksums.txt && cat checksums.txt) |
| 148 | +
|
| 149 | + - name: Smoke test the linux/amd64 build |
| 150 | + env: |
| 151 | + VERSION: ${{ needs.resolve.outputs.version }} |
| 152 | + run: | |
| 153 | + set -euo pipefail |
| 154 | + # Prove the uploaded archive contains a runnable daemon carrying the |
| 155 | + # version we claim, rather than trusting that `go build` succeeded. |
| 156 | + mkdir -p smoke |
| 157 | + tar -xzf "dist/mcpproxy_${VERSION}_linux_amd64.tar.gz" -C smoke |
| 158 | + got=$(./smoke/mcpproxyd -version) |
| 159 | + echo "$got" |
| 160 | + if [ "$got" != "mcpproxyd v${VERSION}" ]; then |
| 161 | + echo "::error::built binary reports '${got}', want 'mcpproxyd v${VERSION}'" |
| 162 | + exit 1 |
| 163 | + fi |
| 164 | + ./smoke/configcheck smoke/examples/01-minimal-stdio.yaml |
| 165 | +
|
| 166 | + - name: Attach archives to the release |
| 167 | + env: |
| 168 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 169 | + TAG: v${{ needs.resolve.outputs.version }} |
| 170 | + run: | |
| 171 | + set -euo pipefail |
| 172 | + # --clobber lets a re-run replace assets instead of failing on |
| 173 | + # "asset already exists". checksums.txt is consumed by installers. |
| 174 | + gh release upload "$TAG" dist/*.tar.gz dist/*.zip dist/checksums.txt \ |
| 175 | + --clobber --repo "${{ github.repository }}" |
0 commit comments