Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 18c022f

Browse files
authored
Merge pull request #16 from Consensys/upstream_integration_action
Upstream integration action, force merge since this is only testable in main
2 parents cc5a7ed + aee9df8 commit 18c022f

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

.github/last_upstream_sha

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
442e8f366950dea8624ea757b91fbacec11d604c
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Cherry-pick new commits from upstream
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * *' # Nightly
6+
workflow_dispatch:
7+
8+
jobs:
9+
cherry-pick:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout your repo
14+
uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
fetch-depth: 0
18+
19+
- name: Set up Git config
20+
run: |
21+
git config --global user.name "github-actions[bot]"
22+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
23+
24+
- name: Generate GitHub App token (real GitHub only)
25+
if: ${{ env.ACT != 'true' }}
26+
id: app-token
27+
uses: tibdex/github-app-token@v1
28+
with:
29+
app_id: ${{ secrets.UPSTREAM_INTEGRATION_APP_ID }}
30+
private_key: ${{ secrets.UPSTREAM_INTEGRATION_APP_PRIVATE_KEY }}
31+
32+
- name: Set mock token for local act test runs
33+
if: ${{ env.ACT == 'true' }}
34+
id: app-token
35+
run: echo "token=${MOCK_GITHUB_TOKEN}" >> $GITHUB_OUTPUT
36+
37+
- name: Add upstream remote and fetch
38+
run: |
39+
git remote add upstream https://github.com/hyperledger/besu.git
40+
git fetch upstream
41+
42+
- name: Checkout or create upstream_integration branch
43+
run: |
44+
BRANCH="upstream_integration"
45+
46+
if git show-ref --quiet refs/heads/$BRANCH; then
47+
git checkout $BRANCH
48+
elif git ls-remote --exit-code --heads origin $BRANCH; then
49+
git fetch origin $BRANCH
50+
git checkout -b $BRANCH origin/$BRANCH
51+
else
52+
git checkout --orphan $BRANCH
53+
git reset --hard
54+
fi
55+
56+
- name: Read last cherry-picked SHA
57+
id: lastsha
58+
run: |
59+
SHA_FILE=".github/last_upstream_sha"
60+
INITIAL_SHA="442e8f366950dea8624ea757b91fbacec11d604c"
61+
62+
if [ -f "$SHA_FILE" ]; then
63+
LAST_SHA=$(cat "$SHA_FILE" | tr -d '\n')
64+
65+
if [ -z "$LAST_SHA" ]; then
66+
echo "⚠️ SHA file is empty; falling back to default."
67+
LAST_SHA="$INITIAL_SHA"
68+
elif ! [[ "$LAST_SHA" =~ ^[0-9a-f]{40}$ ]]; then
69+
echo "⚠️ SHA file contains invalid value: $LAST_SHA; using default."
70+
LAST_SHA="$INITIAL_SHA"
71+
fi
72+
else
73+
echo "ℹ️ SHA file not found; using default."
74+
LAST_SHA="$INITIAL_SHA"
75+
fi
76+
77+
echo "Using last upstream SHA: $LAST_SHA"
78+
echo "last_sha=$LAST_SHA" >> $GITHUB_OUTPUT
79+
80+
- name: Find commits to cherry-pick
81+
id: commits
82+
run: |
83+
# Get upstream commits since last SHA (still needed)
84+
CANDIDATES=$(git rev-list --reverse --no-merges upstream/main ^${{ steps.lastsha.outputs.last_sha }})
85+
86+
# Build a set of cherry-picked SHAs already present in integration branch
87+
PICKED=$(git log upstream_integration --grep='^cherry picked from commit ' --format='%b' \
88+
| grep -oE '[0-9a-f]{40}' | sort -u)
89+
90+
# Filter out duplicates
91+
TO_PICK=""
92+
for sha in $CANDIDATES; do
93+
if echo "$PICKED" | grep -q "^$sha$"; then
94+
echo "🔁 Skipping already cherry-picked commit: $sha"
95+
else
96+
TO_PICK="$TO_PICK $sha"
97+
fi
98+
done
99+
100+
echo "commits=$TO_PICK" >> $GITHUB_OUTPUT
101+
102+
- name: Cherry-pick new commits
103+
if: steps.commits.outputs.commits != ''
104+
run: |
105+
for sha in ${{ steps.commits.outputs.commits }}; do
106+
echo "Cherry-picking $sha"
107+
git cherry-pick -x $sha || exit 1
108+
done
109+
110+
- name: Update last cherry-picked SHA
111+
if: steps.commits.outputs.commits != ''
112+
run: |
113+
echo "${{ steps.commits.outputs.commits }}" | tail -n 1 > .github/last_upstream_sha
114+
git add .github/last_upstream_sha
115+
git commit -m "Update last_upstream_sha"
116+
git push origin upstream_integration
117+

0 commit comments

Comments
 (0)