|
| 1 | +name: deploy |
| 2 | + |
| 3 | +# Build + sign + publish a release artifact. PULL-BASED deploy: |
| 4 | +# this workflow never touches the production box and never holds an SSH key. |
| 5 | +# The box runs cosift-self-update.timer, which polls the latest GitHub Release, |
| 6 | +# verifies sha256 + minisign signature against a public key baked on the box, |
| 7 | +# snapshots, atomically swaps the binary, restarts, and health-gates with |
| 8 | +# auto-rollback. See deploy/scripts/README.md. |
| 9 | +# |
| 10 | +# Triggers: |
| 11 | +# - push of a version tag (v*) → cut a release for that tag |
| 12 | +# - manual workflow_dispatch → build from a chosen ref (no release |
| 13 | +# unless a tag is also present) |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + tags: |
| 18 | + - 'v*' |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write # needed to create the GitHub Release + upload assets |
| 23 | + |
| 24 | +jobs: |
| 25 | + # (a) verify — gate the release on vet + race tests + a smoke subset. |
| 26 | + verify: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v6 |
| 30 | + |
| 31 | + - uses: actions/setup-go@v6 |
| 32 | + with: |
| 33 | + go-version: '1.25' |
| 34 | + cache: true |
| 35 | + |
| 36 | + - name: go vet |
| 37 | + run: go vet ./... |
| 38 | + |
| 39 | + - name: Tests (race) |
| 40 | + run: go test -race -timeout 5m ./... |
| 41 | + |
| 42 | + - name: Smoke subset (build + serve roundtrip) |
| 43 | + # make smoke builds the binary, crawls, and asserts /healthz + /search. |
| 44 | + # Guarded with a timeout so a hung crawl can't wedge the release. |
| 45 | + run: timeout 300 make smoke |
| 46 | + |
| 47 | + # (b) build — reproducible static arm64 binary, sha256, minisign signature. |
| 48 | + build: |
| 49 | + needs: verify |
| 50 | + runs-on: ubuntu-latest |
| 51 | + outputs: |
| 52 | + version: ${{ steps.ver.outputs.version }} |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v6 |
| 55 | + with: |
| 56 | + fetch-depth: 0 # full history so version stamping is meaningful |
| 57 | + |
| 58 | + - uses: actions/setup-go@v6 |
| 59 | + with: |
| 60 | + go-version: '1.25' |
| 61 | + cache: true |
| 62 | + |
| 63 | + - name: Resolve version stamp |
| 64 | + id: ver |
| 65 | + # Tag name when triggered by a tag push; otherwise the short SHA. |
| 66 | + run: | |
| 67 | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then |
| 68 | + echo "version=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" |
| 69 | + else |
| 70 | + echo "version=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Build (linux/arm64, static, trimmed) |
| 74 | + env: |
| 75 | + CGO_ENABLED: '0' |
| 76 | + GOOS: linux |
| 77 | + GOARCH: arm64 |
| 78 | + VERSION: ${{ steps.ver.outputs.version }} |
| 79 | + # Stamp both main.version and internal/server.Version so /healthz and |
| 80 | + # /metrics report the shipped version. Matches the Makefile `build` |
| 81 | + # target's ldflags exactly (kept in sync deliberately). |
| 82 | + run: | |
| 83 | + go build -trimpath \ |
| 84 | + -ldflags "-s -w -X main.version=${VERSION} -X github.com/pilot-protocol/cosift/internal/server.Version=${VERSION}" \ |
| 85 | + -o cosift-linux-arm64 ./cmd/cosift |
| 86 | +
|
| 87 | + - name: sha256 |
| 88 | + run: sha256sum cosift-linux-arm64 | tee cosift-linux-arm64.sha256 |
| 89 | + |
| 90 | + - name: Install minisign |
| 91 | + run: sudo apt-get update && sudo apt-get install -y minisign |
| 92 | + |
| 93 | + - name: Sign with minisign |
| 94 | + env: |
| 95 | + # Repo secret. The matching PUBLIC key is baked on the box at |
| 96 | + # /etc/cosift/minisign.pub. Generate with `minisign -G` (see |
| 97 | + # deploy/scripts/README.md). NEVER commit the secret key. |
| 98 | + MINISIGN_SECRET_KEY: ${{ secrets.MINISIGN_SECRET_KEY }} |
| 99 | + run: | |
| 100 | + if [ -z "${MINISIGN_SECRET_KEY}" ]; then |
| 101 | + echo "::error::MINISIGN_SECRET_KEY secret is not set" >&2 |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + printf '%s' "${MINISIGN_SECRET_KEY}" > minisign.key |
| 105 | + # -W: secret key is unencrypted (no interactive passphrase prompt). |
| 106 | + # Trusted comment carries the version so the box can sanity-check it. |
| 107 | + minisign -S -W -s minisign.key \ |
| 108 | + -m cosift-linux-arm64 \ |
| 109 | + -t "cosift ${{ steps.ver.outputs.version }} linux/arm64" |
| 110 | + rm -f minisign.key |
| 111 | + # Verification against the embedded public key is done on the box; |
| 112 | + # here we just confirm the .minisig was produced. |
| 113 | + test -f cosift-linux-arm64.minisig |
| 114 | +
|
| 115 | + - uses: actions/upload-artifact@v7 |
| 116 | + with: |
| 117 | + name: cosift-release-artifacts |
| 118 | + path: | |
| 119 | + cosift-linux-arm64 |
| 120 | + cosift-linux-arm64.sha256 |
| 121 | + cosift-linux-arm64.minisig |
| 122 | + retention-days: 30 |
| 123 | + |
| 124 | + # (c) release — publish the signed binary as a GitHub Release asset. |
| 125 | + # Only on a tag push (workflow_dispatch builds the artifact but does not |
| 126 | + # cut a release). |
| 127 | + release: |
| 128 | + needs: build |
| 129 | + if: github.ref_type == 'tag' |
| 130 | + runs-on: ubuntu-latest |
| 131 | + permissions: |
| 132 | + contents: write |
| 133 | + steps: |
| 134 | + - uses: actions/download-artifact@v7 |
| 135 | + with: |
| 136 | + name: cosift-release-artifacts |
| 137 | + |
| 138 | + - name: Create / update GitHub Release |
| 139 | + uses: softprops/action-gh-release@v2 |
| 140 | + with: |
| 141 | + tag_name: ${{ github.ref_name }} |
| 142 | + name: cosift ${{ github.ref_name }} |
| 143 | + generate_release_notes: true |
| 144 | + fail_on_unmatched_files: true |
| 145 | + files: | |
| 146 | + cosift-linux-arm64 |
| 147 | + cosift-linux-arm64.sha256 |
| 148 | + cosift-linux-arm64.minisig |
0 commit comments