|
| 1 | +name: "Docs: open prod release PR" |
| 2 | + |
| 3 | +on: |
| 4 | + # Chain: push -> Build & Push -> Verify Deploy -> this workflow. GitHub |
| 5 | + # limits workflow_run chaining to three downstream levels; do not grow |
| 6 | + # this pipeline without checking that limit. Promotion uses a PR event. |
| 7 | + workflow_run: |
| 8 | + workflows: ["Showcase: Verify Deploy"] |
| 9 | + types: [completed] |
| 10 | + branches: [main] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: docs-open-release-pr |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + pending-release: |
| 22 | + if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.head_branch == 'main' |
| 23 | + runs-on: ubuntu-latest |
| 24 | + timeout-minutes: 5 |
| 25 | + permissions: |
| 26 | + pull-requests: read |
| 27 | + outputs: |
| 28 | + exists: ${{ steps.pending.outputs.exists }} |
| 29 | + steps: |
| 30 | + # Never push a new pin over a reviewed release. A maintainer must merge |
| 31 | + # or close it before another candidate is prepared. |
| 32 | + - name: Keep an open release PR stable |
| 33 | + id: pending |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ github.token }} |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | + count=$(gh pr list --repo "$GITHUB_REPOSITORY" --base main \ |
| 39 | + --head release/docs/prod --state open --json number --jq 'length') |
| 40 | + if [ "$count" -gt 0 ]; then |
| 41 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 42 | + echo "::notice::An open docs release PR is awaiting review; leaving its pin unchanged." |
| 43 | + else |
| 44 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 45 | + fi |
| 46 | +
|
| 47 | + open-pr: |
| 48 | + needs: pending-release |
| 49 | + if: needs.pending-release.outputs.exists == 'false' |
| 50 | + runs-on: ubuntu-latest |
| 51 | + timeout-minutes: 15 |
| 52 | + environment: railway |
| 53 | + permissions: |
| 54 | + contents: write |
| 55 | + pull-requests: write |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 58 | + with: |
| 59 | + persist-credentials: false |
| 60 | + ref: main |
| 61 | + |
| 62 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
| 63 | + with: |
| 64 | + node-version: 22.x |
| 65 | + |
| 66 | + - working-directory: showcase/scripts |
| 67 | + env: |
| 68 | + EMIT_SKIP_OXFMT: "1" |
| 69 | + run: | |
| 70 | + npm ci |
| 71 | + npx tsx emit-railway-envs-json.ts |
| 72 | +
|
| 73 | + - name: Probe docs staging |
| 74 | + id: probe |
| 75 | + working-directory: showcase/scripts |
| 76 | + env: |
| 77 | + RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} |
| 78 | + run: | |
| 79 | + set -euo pipefail |
| 80 | + if [ -z "${RAILWAY_TOKEN:-}" ]; then |
| 81 | + echo "::notice::RAILWAY_TOKEN is not set; skipping docs release PR." |
| 82 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | + # Bracket the health probe with digest reads. The pin CLI checks |
| 86 | + # this snapshot against Railway again rather than pinning a newer, |
| 87 | + # unprobed deployment that arrived while verification was running. |
| 88 | + STAGING_DIGEST=$(npx tsx -e ' |
| 89 | + import { resolveRailwayToken } from "./lib/railway-token.ts"; |
| 90 | + import { liveFetchDeployedDigest } from "./reconcile-staging.ts"; |
| 91 | + import { ENV_ID_BY_NAME, SERVICES } from "./railway-envs.ts"; |
| 92 | + liveFetchDeployedDigest(resolveRailwayToken().token, SERVICES.docs.serviceId, ENV_ID_BY_NAME.staging) |
| 93 | + .then(digest => console.log(digest ?? "")) |
| 94 | + .catch(error => { console.error(error); process.exit(1); }); |
| 95 | + ') |
| 96 | + if [ -z "$STAGING_DIGEST" ]; then |
| 97 | + echo "::notice::docs staging has no deployed digest; skipping release PR." |
| 98 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 99 | + exit 0 |
| 100 | + fi |
| 101 | + if npx tsx verify-deploy.ts --env staging --services docs; then |
| 102 | + echo "staging-digest=$STAGING_DIGEST" >> "$GITHUB_OUTPUT" |
| 103 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 104 | + else |
| 105 | + echo "::notice::docs staging probe is red; not opening a release PR." |
| 106 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Prepare pin file |
| 110 | + id: pin |
| 111 | + if: steps.probe.outputs.skip != 'true' |
| 112 | + working-directory: showcase/scripts |
| 113 | + env: |
| 114 | + RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} |
| 115 | + GIT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} |
| 116 | + VERIFIED_STAGING_DIGEST: ${{ steps.probe.outputs.staging-digest }} |
| 117 | + run: | |
| 118 | + set -euo pipefail |
| 119 | + npx tsx prepare-docs-release-pin.ts \ |
| 120 | + --pin-path=../../showcase/pins/docs-prod.json \ |
| 121 | + --verified-staging-digest="$VERIFIED_STAGING_DIGEST" \ |
| 122 | + --git-sha="$GIT_SHA" |
| 123 | +
|
| 124 | + - name: Mint devops-bot token |
| 125 | + if: steps.probe.outputs.skip != 'true' && steps.pin.outputs.skip != 'true' |
| 126 | + id: app-token |
| 127 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 128 | + with: |
| 129 | + app-id: "1108748" |
| 130 | + private-key: ${{ secrets.DEVOPS_BOT_PRIVATE_KEY }} |
| 131 | + permission-contents: write |
| 132 | + permission-pull-requests: write |
| 133 | + permission-issues: write |
| 134 | + |
| 135 | + - name: Open docs release PR |
| 136 | + if: steps.probe.outputs.skip != 'true' && steps.pin.outputs.skip != 'true' |
| 137 | + uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8 |
| 138 | + env: |
| 139 | + LEFTHOOK: "0" |
| 140 | + with: |
| 141 | + token: ${{ steps.app-token.outputs.token }} |
| 142 | + branch: release/docs/prod |
| 143 | + delete-branch: false |
| 144 | + add-paths: showcase/pins/docs-prod.json |
| 145 | + commit-message: "chore: release docs ${{ github.event.workflow_run.head_sha || github.sha }}" |
| 146 | + title: "chore: release docs to prod" |
| 147 | + labels: docs-release |
| 148 | + body: | |
| 149 | + Staging docs is green. Merge this PR to pin `docs.copilotkit.ai` |
| 150 | + to the digest in `showcase/pins/docs-prod.json`. |
| 151 | +
|
| 152 | + - Staging: https://docs.staging.copilotkit.ai |
| 153 | + - Verification trigger SHA: `${{ github.event.workflow_run.head_sha || github.sha }}` |
| 154 | + - Digest: `${{ steps.pin.outputs.digest }}` |
| 155 | +
|
| 156 | + This is the docs prod gate. It does not promote the showcase fleet. |
| 157 | + The trigger SHA can be a scripts-only change, not the image's source |
| 158 | + revision; the digest above is the release identity. |
| 159 | +
|
| 160 | + The bot will not refresh this PR while it is open. Update its branch |
| 161 | + to main if required, then obtain approval of the latest push and merge |
| 162 | + once required checks pass. To replace this candidate, close the PR and |
| 163 | + dispatch **Docs: open prod release PR** again on main. |
| 164 | + Staging can advance during review, so inspect the pinned digest as |
| 165 | + well as the current staging page. See showcase/bin/README.md for gates. |
| 166 | +
|
| 167 | + - [ ] Staging page looks right |
| 168 | + - [ ] Digest in the pin file is the one you want |
0 commit comments