|
| 1 | +name: Backport Deployment Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - deployed/testnet |
| 7 | + - deployed/mainnet |
| 8 | + |
| 9 | +jobs: |
| 10 | + backport: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Check for commits to backport |
| 21 | + id: check |
| 22 | + run: | |
| 23 | + BRANCH="${GITHUB_REF#refs/heads/}" |
| 24 | +
|
| 25 | + # Count commits in deployment branch that aren't in main |
| 26 | + COMMITS_AHEAD=$(git rev-list --count main..$BRANCH) |
| 27 | +
|
| 28 | + echo "branch=$BRANCH" >> $GITHUB_OUTPUT |
| 29 | + echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT |
| 30 | +
|
| 31 | + if [ "$COMMITS_AHEAD" -gt 0 ]; then |
| 32 | + echo "has_commits=true" >> $GITHUB_OUTPUT |
| 33 | + echo "Found $COMMITS_AHEAD commit(s) to backport from $BRANCH to main" |
| 34 | + else |
| 35 | + echo "has_commits=false" >> $GITHUB_OUTPUT |
| 36 | + echo "No commits to backport" |
| 37 | + fi |
| 38 | +
|
| 39 | + - name: Check for existing PR |
| 40 | + if: steps.check.outputs.has_commits == 'true' |
| 41 | + id: existing |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + BRANCH="${{ steps.check.outputs.branch }}" |
| 46 | +
|
| 47 | + # Check if a backport PR already exists |
| 48 | + EXISTING_PR=$(gh pr list --base main --head "$BRANCH" --state open --json number --jq '.[0].number // empty') |
| 49 | +
|
| 50 | + if [ -n "$EXISTING_PR" ]; then |
| 51 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 52 | + echo "PR #$EXISTING_PR already exists" |
| 53 | + else |
| 54 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Create backport PR |
| 58 | + if: steps.check.outputs.has_commits == 'true' && steps.existing.outputs.exists == 'false' |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + run: | |
| 62 | + BRANCH="${{ steps.check.outputs.branch }}" |
| 63 | + NETWORK="${BRANCH#deployed/}" |
| 64 | +
|
| 65 | + gh pr create \ |
| 66 | + --base main \ |
| 67 | + --head "$BRANCH" \ |
| 68 | + --title "Backport: ${NETWORK} deployment artifacts" \ |
| 69 | + --body "$(cat <<'EOF' |
| 70 | + Automated backport of deployment artifacts from \`${{ steps.check.outputs.branch }}\`. |
| 71 | +
|
| 72 | + This PR brings deployment artifacts (e.g., updated addresses.json) back to main. |
| 73 | +
|
| 74 | + --- |
| 75 | + *Created automatically by the backport-artifacts workflow.* |
| 76 | + EOF |
| 77 | + )" |
| 78 | +
|
| 79 | + echo "## Backport PR Created" >> $GITHUB_STEP_SUMMARY |
| 80 | + echo "- **From:** $BRANCH" >> $GITHUB_STEP_SUMMARY |
| 81 | + echo "- **To:** main" >> $GITHUB_STEP_SUMMARY |
| 82 | + echo "- **Commits:** ${{ steps.check.outputs.commits_ahead }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments