Skip to content

Commit 1cd65b3

Browse files
committed
ci: base-commit
1 parent 958ba04 commit 1cd65b3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: mergebase
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
get_merge_base:
8+
runs-on: ubuntu-latest
9+
env:
10+
UPSTREAM_REMOTE: torvalds
11+
UPSTREAM_URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
12+
UPSTREAM_BRANCH: master
13+
FETCH_STEP: 100
14+
FETCH_MAX: 2000
15+
16+
steps:
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Add upstream remote (torvalds)
22+
run: |
23+
git remote add $UPSTREAM_REMOTE $UPSTREAM_URL 2>/dev/null || true
24+
25+
- name: Find upstream merge-base (torvalds/master)
26+
run: |
27+
set -e
28+
29+
DEPTH=$FETCH_STEP
30+
31+
# get Upstream initial flat
32+
git fetch $UPSTREAM_REMOTE $UPSTREAM_BRANCH --depth=$DEPTH
33+
34+
while true; do
35+
BASE=$(git merge-base HEAD FETCH_HEAD || true)
36+
37+
if [ -n "$BASE" ]; then
38+
echo "Found merge-base: $BASE"
39+
echo "BASE=$BASE" >> $GITHUB_ENV
40+
break
41+
fi
42+
43+
if [ $DEPTH -ge $FETCH_MAX ]; then
44+
echo "Fallback to full fetch..."
45+
git fetch $UPSTREAM_REMOTE $UPSTREAM_BRANCH --unshallow
46+
BASE=$(git merge-base HEAD FETCH_HEAD)
47+
echo "BASE=$BASE" >> $GITHUB_ENV
48+
break
49+
fi
50+
51+
echo "No base yet, deepening by $FETCH_STEP..."
52+
git fetch $UPSTREAM_REMOTE $UPSTREAM_BRANCH --deepen=$FETCH_STEP
53+
DEPTH=$((DEPTH + FETCH_STEP))
54+
done

0 commit comments

Comments
 (0)