forked from linux-surface/linux-surface
-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (176 loc) · 8.08 KB
/
sync-kernel-upstream.yml
File metadata and controls
214 lines (176 loc) · 8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Sync Kernel with Upstream
on:
# Manual trigger
workflow_dispatch:
# Automatic daily sync at 7:30 AM UTC
schedule:
- cron: '30 7 * * *'
jobs:
sync:
name: Sync with upstream
runs-on: ubuntu-latest
steps:
- name: Cache kernel repository
uses: actions/cache@v5
with:
path: kernel/.git
key: kernel-git-${{ github.run_number }}
restore-keys: |
kernel-git-
- name: Clean up old caches
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Cleaning up old kernel-git caches (keeping only the latest)..."
gh cache list --repo ${{ github.repository }} --key kernel-git- --json id,key,createdAt --limit 100 | \
jq -r 'sort_by(.createdAt) | reverse | .[1:] | .[].id' | \
xargs -I {} gh cache delete {} --repo ${{ github.repository }} || true
- name: Checkout linux-surface repo
uses: actions/checkout@v6
with:
repository: linux-surface/linux-surface
path: linux-surface
token: ${{ secrets.LINUX_SURFACE_BOT_TOKEN }}
- name: Checkout kernel repository
uses: actions/checkout@v6
with:
repository: linux-surface/kernel
path: kernel
fetch-depth: 0
token: ${{ secrets.LINUX_SURFACE_BOT_TOKEN }}
- name: Setup git identity
run: |
git config --global user.name "surfacebot"
git config --global user.email "surfacebot@users.noreply.github.com"
- name: Sync with upstream
id: sync
working-directory: kernel
run: |
echo "Getting current origin tags..."
git ls-remote --tags origin | awk '{print $2}' | sed 's|refs/tags/||' | grep -v '\^{}' | sort > /tmp/origin-tags.txt
echo "Adding upstream remote..."
git remote add upstream https://github.com/gregkh/linux || true
echo "Fetching from upstream..."
git fetch upstream --tags
echo "Counting new tags..."
# Get tags that exist in upstream but not in origin
git ls-remote --tags upstream | awk '{print $2}' | sed 's|refs/tags/||' | grep -v '\^{}' | sort > /tmp/upstream-tags.txt
NEW_TAGS=$(comm -13 /tmp/origin-tags.txt /tmp/upstream-tags.txt | wc -l)
echo "new_tags=${NEW_TAGS}" >> "${GITHUB_OUTPUT}"
echo "Found ${NEW_TAGS} new tags"
# Save new tags list for later processing
comm -13 /tmp/origin-tags.txt /tmp/upstream-tags.txt > /tmp/new-tags.txt
# Show some of the new tags (first 10)
echo "Sample of new tags:"
cat /tmp/new-tags.txt | head -10
echo "Updating master branch..."
git checkout -B master origin/master
git merge --ff-only upstream/master || {
echo "ERROR: Cannot fast-forward master branch"
echo "Manual intervention may be required"
exit 1
}
echo "master_updated=true" >> "${GITHUB_OUTPUT}"
- name: Push changes
if: steps.sync.outputs.new_tags != '0' || steps.sync.outputs.master_updated == 'true'
working-directory: kernel
run: |
echo "Pushing new tags..."
git push origin --tags
echo "Pushing master branch..."
git push origin master
- name: Check for maintained branch updates
id: check_maintained
if: steps.sync.outputs.new_tags != '0'
run: |
CONFIG_FILE="${GITHUB_WORKSPACE}/linux-surface/.github/data/autoupdate/maintained-branches.conf"
echo "Reading maintained branches from ${CONFIG_FILE}..."
# Read config file, skip comments and empty lines
BRANCHES_TO_REBASE=""
while IFS=: read -r BRANCH VERSION; do
# Skip comments and empty lines
[[ "$BRANCH" =~ ^#.*$ ]] && continue
[[ -z "$BRANCH" ]] && continue
echo "Checking for version ${VERSION} (branch: ${BRANCH})..."
# Check if any new tags match this version (e.g., v6.18.*, excluding -rc)
MATCHING_TAGS=$(grep -E "^v${VERSION}\.[0-9]+$" /tmp/new-tags.txt || true)
if [ -n "$MATCHING_TAGS" ]; then
LATEST_TAG=$(echo "$MATCHING_TAGS" | sort -V | tail -1)
echo " ✓ Found new release for ${BRANCH}: ${LATEST_TAG}"
BRANCHES_TO_REBASE="${BRANCHES_TO_REBASE}${BRANCH}:${LATEST_TAG},"
else
echo " - No new releases for ${BRANCH}"
fi
done < "$CONFIG_FILE"
# Remove trailing comma
BRANCHES_TO_REBASE="${BRANCHES_TO_REBASE%,}"
echo "branches_to_rebase=${BRANCHES_TO_REBASE}" >> "${GITHUB_OUTPUT}"
if [ -n "$BRANCHES_TO_REBASE" ]; then
echo ""
echo "Branches to rebase: ${BRANCHES_TO_REBASE}"
else
echo ""
echo "No maintained branches need rebasing"
fi
- name: Trigger rebase workflows
if: steps.check_maintained.outputs.branches_to_rebase != ''
env:
GH_TOKEN: ${{ secrets.LINUX_SURFACE_BOT_TOKEN }}
BRANCHES_TO_REBASE: ${{ steps.check_maintained.outputs.branches_to_rebase }}
run: |
echo "Triggering rebase workflows for updated branches..."
echo ""
IFS=',' read -ra BRANCH_PAIRS <<< "$BRANCHES_TO_REBASE"
for pair in "${BRANCH_PAIRS[@]}"; do
BRANCH=$(echo "$pair" | cut -d: -f1)
TAG=$(echo "$pair" | cut -d: -f2)
echo "Triggering rebase for ${BRANCH} to ${TAG}..."
gh workflow run rebase-kernel.yml \
--repo ${{ github.repository }} \
--field branch="${BRANCH}" \
--field target_tag="${TAG}" \
--field build=true \
--field dry_run=false
echo " ✓ Triggered"
echo ""
done
- name: Generate summary
if: always()
env:
NEW_TAGS: ${{ steps.sync.outputs.new_tags }}
MASTER_UPDATED: ${{ steps.sync.outputs.master_updated }}
BRANCHES_TO_REBASE: ${{ steps.check_maintained.outputs.branches_to_rebase }}
run: |
echo "## Kernel Upstream Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${MASTER_UPDATED}" = "true" ]; then
echo "✅ **Status:** Success" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **New tags:** ${NEW_TAGS:-0}" >> $GITHUB_STEP_SUMMARY
echo "- **Master branch:** Updated" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -n "${BRANCHES_TO_REBASE}" ]; then
echo "### Automatic Rebases Triggered" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The following branches will be automatically rebased:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
IFS=',' read -ra BRANCH_PAIRS <<< "$BRANCHES_TO_REBASE"
for pair in "${BRANCH_PAIRS[@]}"; do
BRANCH=$(echo "$pair" | cut -d: -f1)
TAG=$(echo "$pair" | cut -d: -f2)
echo "- **${BRANCH}** → ${TAG}" >> $GITHUB_STEP_SUMMARY
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the [Rebase and Build Kernel workflow runs](../../actions/workflows/rebase-kernel.yml) for progress." >> $GITHUB_STEP_SUMMARY
elif [ "${NEW_TAGS:-0}" -gt 0 ]; then
echo "### New Tags" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "New tags were synced, but none match maintained branch versions." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To update maintained branches, edit \`.github/data/autoupdate/maintained-branches.txt\`" >> $GITHUB_STEP_SUMMARY
fi
else
echo "ℹ️ **Status:** No changes" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Repository is already up-to-date with upstream." >> $GITHUB_STEP_SUMMARY
fi