|
| 1 | +name: Promote SDKs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + promote: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: github.repository == 'run-llama/llamacloud-prod-java' |
| 14 | + env: |
| 15 | + PRODUCTION_REPO: run-llama/llama-parse-java |
| 16 | + GH_TOKEN: ${{ secrets.PRODUCTION_REPO_TOKEN }} |
| 17 | + steps: |
| 18 | + - name: Check out staging |
| 19 | + uses: actions/checkout@v6 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + persist-credentials: false |
| 23 | + |
| 24 | + - name: Fetch production main |
| 25 | + run: | |
| 26 | + git remote add production \ |
| 27 | + "https://x-access-token:${GH_TOKEN}@github.com/${PRODUCTION_REPO}.git" |
| 28 | + git fetch production main |
| 29 | +
|
| 30 | + - name: Check whether production already has staging's content |
| 31 | + id: diff |
| 32 | + run: | |
| 33 | + # Compare by CONTENT, not commit SHA. After a release, production |
| 34 | + # carries release-please's version/changelog commits that staging |
| 35 | + # lacks, so the SHAs always differ — a SHA check would re-open a |
| 36 | + # spurious release PR (and push staging's now-stale manifest) on |
| 37 | + # every push. Instead, ask whether merging staging into production |
| 38 | + # would change production's tree: if not, production already contains |
| 39 | + # everything on staging (it's equal, or only ahead by release |
| 40 | + # metadata) and there is nothing to release. |
| 41 | + MERGED=$(git merge-tree --write-tree production/main origin/main) || MERGED=conflict |
| 42 | + PRODUCTION_TREE=$(git rev-parse 'production/main^{tree}') |
| 43 | + if [ "$MERGED" = "$PRODUCTION_TREE" ]; then |
| 44 | + echo "Production already contains staging's content. Nothing to release." |
| 45 | + echo "synced=true" >> "$GITHUB_OUTPUT" |
| 46 | + else |
| 47 | + echo "synced=false" >> "$GITHUB_OUTPUT" |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Push staging main to the release branch on production |
| 51 | + if: steps.diff.outputs.synced == 'false' |
| 52 | + run: | |
| 53 | + git push production origin/main:refs/heads/stainless/release --force |
| 54 | +
|
| 55 | + - name: Open or update the release PR on production |
| 56 | + if: steps.diff.outputs.synced == 'false' |
| 57 | + run: | |
| 58 | + EXISTING_PR=$(gh pr list \ |
| 59 | + --repo "${PRODUCTION_REPO}" \ |
| 60 | + --head stainless/release \ |
| 61 | + --state open \ |
| 62 | + --json number \ |
| 63 | + --jq '.[0].number') |
| 64 | + if [ -z "${EXISTING_PR}" ]; then |
| 65 | + gh pr create \ |
| 66 | + --repo "${PRODUCTION_REPO}" \ |
| 67 | + --base main \ |
| 68 | + --head stainless/release \ |
| 69 | + --title "Release SDK updates" \ |
| 70 | + --body "$(git log --oneline production/main..origin/main)" |
| 71 | + else |
| 72 | + echo "Release PR #${EXISTING_PR} already exists. Force-push has updated it." |
| 73 | + fi |
0 commit comments