Skip to content

Commit 8985c98

Browse files
tmigoneRembrandtK
authored andcommitted
feat: automate artifact backport to main
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
1 parent d8b75fe commit 8985c98

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

DEPLOYMENT.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ PRs to `main` that modify Solidity contract files require an `audited` label bef
138138
- **Label:** `audited`
139139

140140
This enforces principle #2: code in `main` must be audited.
141+
142+
### Artifact Backporting
143+
144+
When deployment artifacts are committed to a deployment branch, a PR is automatically created to backport them to `main` (`.github/workflows/backport-artifacts.yml`).
145+
146+
This ensures `main` stays in sync with deployed artifacts (e.g., updated `addresses.json`) without manual backporting.

0 commit comments

Comments
 (0)