|
1 | | -name: Promote SDKs |
| 1 | +name: Promote SDK changes |
2 | 2 |
|
3 | | -# Production requires pull requests, so staging is promoted through a merge- |
4 | | -# commit PR. Never squash or rebase this cross-repo PR: preserving the incoming |
5 | | -# commits keeps production and staging on one ancestry chain. |
| 3 | +# Staging is the generator's integration history. Production `next` is the |
| 4 | +# developer-facing queue for the next release. This workflow combines the |
| 5 | +# latest released state with validated staging changes, then advances `next`. |
| 6 | +# Release automation maintains the single versioned PR from `next` to `main`. |
6 | 7 | on: |
7 | 8 | push: |
8 | 9 | branches: [main] |
@@ -35,49 +36,49 @@ jobs: |
35 | 36 | repositories: kernel-python-sdk |
36 | 37 | permission-contents: write |
37 | 38 | permission-workflows: write |
38 | | - permission-pull-requests: write |
39 | 39 |
|
40 | | - - name: Fetch production main |
| 40 | + - name: Fetch production branches |
| 41 | + id: production |
41 | 42 | env: |
42 | 43 | GH_TOKEN: ${{ steps.production-token.outputs.token }} |
43 | 44 | PRODUCTION_REPO: kernel/kernel-python-sdk |
44 | 45 | run: | |
45 | | - git remote add production "https://x-access-token:${GH_TOKEN}@github.com/${PRODUCTION_REPO}.git" |
| 46 | + set -euo pipefail |
| 47 | + git remote add production \ |
| 48 | + "https://x-access-token:${GH_TOKEN}@github.com/${PRODUCTION_REPO}.git" |
46 | 49 | git fetch production main |
47 | | -
|
48 | | - - name: Check whether production already has staging's content |
49 | | - id: diff |
50 | | - run: | |
51 | | - MERGED=$(git merge-tree --write-tree production/main origin/main) || MERGED=conflict |
52 | | - PRODUCTION_TREE=$(git rev-parse 'production/main^{tree}') |
53 | | - if [ "$MERGED" = "$PRODUCTION_TREE" ]; then |
54 | | - echo "Production already contains staging's content. Nothing to promote." |
55 | | - echo "synced=true" >> "$GITHUB_OUTPUT" |
| 50 | + if git ls-remote --exit-code --heads production next >/dev/null 2>&1; then |
| 51 | + git fetch production next |
| 52 | + echo "has_next=true" >> "$GITHUB_OUTPUT" |
56 | 53 | else |
57 | | - echo "synced=false" >> "$GITHUB_OUTPUT" |
| 54 | + echo "has_next=false" >> "$GITHUB_OUTPUT" |
58 | 55 | fi |
59 | 56 |
|
60 | | - - name: Push the production release branch |
61 | | - if: steps.diff.outputs.synced == 'false' |
| 57 | + - name: Prepare the next release branch |
62 | 58 | env: |
| 59 | + APP_SLUG: ${{ steps.production-token.outputs.app-slug }} |
63 | 60 | GH_TOKEN: ${{ steps.production-token.outputs.token }} |
64 | | - PRODUCTION_REPO: kernel/kernel-python-sdk |
65 | | - run: git push production origin/main:refs/heads/stainless/release --force |
| 61 | + HAS_NEXT: ${{ steps.production.outputs.has_next }} |
| 62 | + run: | |
| 63 | + set -euo pipefail |
| 64 | + bot_id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id) |
| 65 | + git config user.name "${APP_SLUG}[bot]" |
| 66 | + git config user.email "${bot_id}+${APP_SLUG}[bot]@users.noreply.github.com" |
| 67 | +
|
| 68 | + git checkout -B stlc/promote-next origin/main |
| 69 | + if ! git merge-base --is-ancestor production/main HEAD; then |
| 70 | + git merge --no-edit production/main |
| 71 | + fi |
66 | 72 |
|
67 | | - - name: Open or update the promote PR |
68 | | - if: steps.diff.outputs.synced == 'false' |
| 73 | + if [ "$HAS_NEXT" = "true" ] && ! git merge-base --is-ancestor production/next HEAD; then |
| 74 | + echo "::error title=Promotion blocked::production next has commits that are not present in staging or production main." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Update the pending release |
69 | 79 | env: |
70 | 80 | GH_TOKEN: ${{ steps.production-token.outputs.token }} |
71 | | - PRODUCTION_REPO: kernel/kernel-python-sdk |
72 | 81 | run: | |
73 | | - body=$(mktemp) |
74 | | - git log --oneline production/main..origin/main > "$body" |
75 | | - existing=$(gh pr list --repo "$PRODUCTION_REPO" --head stainless/release --state open --json number --jq 'if length == 0 then "" else .[0].number end') |
76 | | - if [ -z "$existing" ]; then |
77 | | - gh pr create --repo "$PRODUCTION_REPO" --base main --head stainless/release --title "Release SDK updates" --body-file "$body" |
78 | | - else |
79 | | - gh pr edit "$existing" --repo "$PRODUCTION_REPO" --title "Release SDK updates" --body-file "$body" |
80 | | - fi |
81 | | - if ! gh pr merge stainless/release --repo "$PRODUCTION_REPO" --merge --auto; then |
82 | | - echo "::warning title=Manual promotion required::Merge the promote PR with a merge commit." |
83 | | - fi |
| 82 | + set -euo pipefail |
| 83 | + git push production HEAD:refs/heads/next |
| 84 | + echo "Updated production next; the versioned release PR will be opened or refreshed." |
0 commit comments