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

Commit eb84b71

Browse files
authored
Upstream integration action (#18)
* upstream_integration workflow Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent cc5a7ed commit eb84b71

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-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

.github/mock_secrets

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

0 commit comments

Comments
 (0)