|
| 1 | +name: Promote SDKs |
| 2 | + |
| 3 | +# Promote staging to production by fast-forwarding production `main` up to the |
| 4 | +# staging trunk, preserving commit SHAs. Because the SHAs are preserved, |
| 5 | +# production `main` and staging `main` stay identical and linear, the sealed |
| 6 | +# custom-code commit stays an ancestor of both, and there is no divergence to |
| 7 | +# heal on the next `stlc build`. |
| 8 | +# |
| 9 | +# Manual dispatch (workflow_dispatch): spec/codegen changes accumulate on |
| 10 | +# staging `main`, and a maintainer promotes the batch in one fast-forward when |
| 11 | +# ready to cut a release. Optionally gate each run behind a required-reviewer |
| 12 | +# approval — see the `environment` note on the job below. release-please then |
| 13 | +# opens its version/changelog PR on production on top. |
| 14 | +on: |
| 15 | + workflow_dispatch: {} |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + promote: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: github.repository == 'sentdm/sent-dm-python-staging' |
| 24 | + # Optional: add required reviewers on each promote run before the fast-forward push. |
| 25 | + # With no reviewers it only scopes secrets/variables and adds no gate, so the manual dispatch |
| 26 | + # above is the only checkpoint. Remove this line if you don't use it. |
| 27 | + environment: production |
| 28 | + env: |
| 29 | + PRODUCTION_REPO: sentdm/sent-dm-python |
| 30 | + GH_TOKEN: ${{ secrets.PRODUCTION_REPO_TOKEN }} |
| 31 | + steps: |
| 32 | + - name: Check out staging |
| 33 | + uses: actions/checkout@v6 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + persist-credentials: false |
| 37 | + |
| 38 | + - name: Fetch production main |
| 39 | + run: | |
| 40 | + git remote add production \ |
| 41 | + "https://x-access-token:${GH_TOKEN}@github.com/${PRODUCTION_REPO}.git" |
| 42 | + git fetch production main |
| 43 | +
|
| 44 | + - name: Check whether production already has staging's content |
| 45 | + id: diff |
| 46 | + run: | |
| 47 | + # After a release, production carries release-please's version/changelog |
| 48 | + # commits that staging lacks. Ask whether merging staging into production |
| 49 | + # would change production's tree: if not, production already has staging's content. |
| 50 | + MERGED=$(git merge-tree --write-tree production/main origin/main) || MERGED=conflict |
| 51 | + PRODUCTION_TREE=$(git rev-parse 'production/main^{tree}') |
| 52 | + if [ "$MERGED" = "$PRODUCTION_TREE" ]; then |
| 53 | + echo "Production already contains staging's content. Nothing to promote." |
| 54 | + echo "synced=true" >> "$GITHUB_OUTPUT" |
| 55 | + else |
| 56 | + echo "synced=false" >> "$GITHUB_OUTPUT" |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Promote staging to production (fast-forward) |
| 60 | + if: steps.diff.outputs.synced == 'false' |
| 61 | + run: | |
| 62 | + # Refuse unless production/main is an ancestor of staging/main. If it |
| 63 | + # isn't, the trunks have forked (someone advanced production out of |
| 64 | + # band without back-syncing first) and a fast-forward is unsafe. |
| 65 | + if ! git merge-base --is-ancestor production/main origin/main; then |
| 66 | + echo "::error title=Promote blocked::production/main is not an ancestor of staging main. Back-sync production into staging first." |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + git push production origin/main:refs/heads/main |
| 70 | + echo "Fast-forwarded production/main to staging/main." |
0 commit comments