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

Commit aee9df8

Browse files
committed
handle edge cases
Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent 61d16e5 commit aee9df8

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

.github/workflows/upstream_integration.yml

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
app_id: ${{ secrets.UPSTREAM_INTEGRATION_APP_ID }}
3030
private_key: ${{ secrets.UPSTREAM_INTEGRATION_APP_PRIVATE_KEY }}
3131

32-
- name: Set mock token for local act runs
32+
- name: Set mock token for local act test runs
3333
if: ${{ env.ACT == 'true' }}
3434
id: app-token
3535
run: echo "token=${MOCK_GITHUB_TOKEN}" >> $GITHUB_OUTPUT
@@ -41,47 +41,70 @@ jobs:
4141
4242
- name: Checkout or create upstream_integration branch
4343
run: |
44-
git checkout origin/upstream_integration 2>/dev/null || git checkout --orphan upstream_integration
45-
git checkout -B upstream_integration
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
4655
4756
- name: Read last cherry-picked SHA
4857
id: lastsha
4958
run: |
5059
SHA_FILE=".github/last_upstream_sha"
51-
52-
if [ ! -f "$SHA_FILE" ]; then
53-
echo "❌ Error: $SHA_FILE not found."
54-
exit 1
55-
fi
56-
57-
LAST_SHA=$(cat "$SHA_FILE" | tr -d '\n')
58-
59-
if [ -z "$LAST_SHA" ]; then
60-
echo "❌ Error: $SHA_FILE is empty."
61-
exit 1
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"
6275
fi
6376
64-
if ! [[ "$LAST_SHA" =~ ^[0-9a-f]{40}$ ]]; then
65-
echo "❌ Error: $SHA_FILE does not contain a valid Git SHA."
66-
echo "Found: '$LAST_SHA'"
67-
exit 1
68-
fi
69-
70-
echo "✅ Found last upstream SHA: $LAST_SHA"
77+
echo "Using last upstream SHA: $LAST_SHA"
7178
echo "last_sha=$LAST_SHA" >> $GITHUB_OUTPUT
7279
7380
- name: Find commits to cherry-pick
7481
id: commits
7582
run: |
76-
TO_PICK=$(git rev-list --reverse --no-merges upstream/main ^${{ steps.lastsha.outputs.last_sha }})
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+
77100
echo "commits=$TO_PICK" >> $GITHUB_OUTPUT
78101
79102
- name: Cherry-pick new commits
80103
if: steps.commits.outputs.commits != ''
81104
run: |
82105
for sha in ${{ steps.commits.outputs.commits }}; do
83106
echo "Cherry-picking $sha"
84-
git cherry-pick $sha || exit 1
107+
git cherry-pick -x $sha || exit 1
85108
done
86109
87110
- name: Update last cherry-picked SHA

0 commit comments

Comments
 (0)