|
| 1 | +name: Sync from production |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # A poll, not a release — tune to how often releases/contributions land on |
| 6 | + # production. Every few hours is plenty; daily is fine. |
| 7 | + - cron: '17 */6 * * *' |
| 8 | + workflow_dispatch: {} |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write # push the back-sync branch on staging |
| 12 | + pull-requests: write # open/merge the back-sync PR on staging |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: stlc-sync-from-production |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + sync: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: github.repository == 'run-llama/llamacloud-prod-java' |
| 22 | + env: |
| 23 | + PRODUCTION_REPO: run-llama/llama-parse-java |
| 24 | + PRODUCTION_REPO_TOKEN: ${{ secrets.PRODUCTION_REPO_TOKEN }} |
| 25 | + # The built-in token writes the branch + PR on this (staging) repo. |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + steps: |
| 28 | + - name: Check out staging |
| 29 | + uses: actions/checkout@v6 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Fetch production main |
| 34 | + run: | |
| 35 | + git remote add production \ |
| 36 | + "https://x-access-token:${PRODUCTION_REPO_TOKEN}@github.com/${PRODUCTION_REPO}.git" |
| 37 | + git fetch production main |
| 38 | +
|
| 39 | + - name: Check whether production has content staging lacks |
| 40 | + id: diff |
| 41 | + run: | |
| 42 | + # Inverse of the promote guard, by content not commit SHA: would |
| 43 | + # merging production into staging change staging's tree? If not, |
| 44 | + # staging already has production's content — nothing to pull back. |
| 45 | + MERGED=$(git merge-tree --write-tree origin/main production/main) || MERGED=conflict |
| 46 | + STAGING_TREE=$(git rev-parse 'origin/main^{tree}') |
| 47 | + if [ "$MERGED" = "$STAGING_TREE" ]; then |
| 48 | + echo "Staging already has production's content. Nothing to pull back." |
| 49 | + echo "behind=false" >> "$GITHUB_OUTPUT" |
| 50 | + else |
| 51 | + echo "behind=true" >> "$GITHUB_OUTPUT" |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Push production main to the back-sync branch on staging |
| 55 | + if: steps.diff.outputs.behind == 'true' |
| 56 | + run: git push origin production/main:refs/heads/stlc/from-prod --force |
| 57 | + |
| 58 | + - name: Open or update the back-sync PR on staging |
| 59 | + if: steps.diff.outputs.behind == 'true' |
| 60 | + run: | |
| 61 | + EXISTING_PR=$(gh pr list --head stlc/from-prod --base main --state open --json number --jq '.[0].number') |
| 62 | + if [ -z "${EXISTING_PR}" ]; then |
| 63 | + gh pr create \ |
| 64 | + --base main \ |
| 65 | + --head stlc/from-prod \ |
| 66 | + --title "Sync release changes from production" \ |
| 67 | + --body "Pulls production's release-please commits (and any merged contributions) back onto staging \`main\` so the next \`stlc build\` reseals against the released state. Bot-authored; safe to auto-merge." |
| 68 | + fi |
| 69 | + # Auto-merge so the loop is hands-off. If auto-merge isn't enabled on |
| 70 | + # the repo, the PR is left open for a one-click merge instead. |
| 71 | + gh pr merge stlc/from-prod --merge --auto \ |
| 72 | + || echo "Auto-merge unavailable — merge the back-sync PR manually." |
0 commit comments