Skip to content

Commit bb274dc

Browse files
committed
Automate kernel updates to new minor version
This will fix #1106, in time, but only allows manual trigger for now, needs more test and verification utils/kernel-upgrade.sh at least automate all the manual manual processes for upgrading the kernel.
1 parent 483ee14 commit bb274dc

File tree

2 files changed

+385
-0
lines changed

2 files changed

+385
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Check Kernel 6.12 Release
2+
3+
on:
4+
workflow_dispatch: # Allow manual triggering
5+
6+
jobs:
7+
check-kernel:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Check out infix repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
token: ${{ secrets.KERNEL_UPDATE_TOKEN }}
16+
17+
- name: Check out linux repository
18+
uses: actions/checkout@v4
19+
with:
20+
repository: kernelkit/linux
21+
path: linux
22+
fetch-depth: 0
23+
token: ${{ secrets.KERNEL_UPDATE_TOKEN }}
24+
25+
- name: Fetch kernel.org and check for 6.12 release
26+
id: check
27+
run: |
28+
# Fetch the kernel.org frontpage and extract 6.12 version
29+
CURRENT_VERSION=$(curl -s https://www.kernel.org/ | grep -oP '6\.12\.\d+' | head -n1)
30+
31+
if [ -z "$CURRENT_VERSION" ]; then
32+
echo "Failed to fetch kernel version"
33+
exit 1
34+
fi
35+
36+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
37+
echo "Current 6.12 kernel version: $CURRENT_VERSION"
38+
39+
# Get the latest tag from our linux tree
40+
cd linux
41+
git fetch origin
42+
LATEST_TAG=$(git tag -l "v6.12.*" | sort -V | tail -n1 | sed 's/^v//')
43+
cd ..
44+
45+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
46+
echo "Latest tag in our tree: $LATEST_TAG"
47+
48+
if [ "$CURRENT_VERSION" != "$LATEST_TAG" ]; then
49+
echo "new_release=true" >> $GITHUB_OUTPUT
50+
echo "🎉 New 6.12 kernel released: $CURRENT_VERSION (our version: $LATEST_TAG)"
51+
else
52+
echo "new_release=false" >> $GITHUB_OUTPUT
53+
echo "No change - still at $CURRENT_VERSION"
54+
fi
55+
56+
- name: Set up git credentials
57+
if: steps.check.outputs.new_release == 'true'
58+
run: |
59+
git config --global user.email "[email protected]"
60+
git config --global user.name "ael-bot"
61+
62+
# Configure git to use the token for HTTPS operations
63+
git config --global url."https://ael-bot:${{ secrets.KERNEL_UPDATE_TOKEN }}@github.com/".insteadOf "[email protected]:"
64+
git config --global url."https://ael-bot:${{ secrets.KERNEL_UPDATE_TOKEN }}@github.com/".insteadOf "https://github.com/"
65+
66+
- name: Run kernel upgrade script
67+
if: steps.check.outputs.new_release == 'true'
68+
env:
69+
GIT_TERMINAL_PROMPT: 0
70+
run: |
71+
./utils/kernel-upgrade.sh linux
72+
73+
- name: Create pull request
74+
if: steps.check.outputs.new_release == 'true'
75+
uses: actions/github-script@v7
76+
with:
77+
github-token: ${{ secrets.KERNEL_UPDATE_TOKEN }}
78+
script: |
79+
// Check if PR already exists
80+
const { data: pulls } = await github.rest.pulls.list({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
head: `${context.repo.owner}:kernel-upgrade`,
84+
state: 'open'
85+
});
86+
87+
if (pulls.length === 0) {
88+
const { data: pr } = await github.rest.pulls.create({
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
title: `Upgrade to kernel ${{ steps.check.outputs.current_version }}`,
92+
head: 'kernel-upgrade',
93+
base: 'main',
94+
body: `Automated kernel upgrade to version ${{ steps.check.outputs.current_version }}.\n\n**Previous version:** ${{ steps.check.outputs.latest_tag }}\n**New version:** ${{ steps.check.outputs.current_version }}\n**Source:** https://www.kernel.org/\n\nThis PR was automatically created by the kernel release monitoring workflow.`
95+
});
96+
97+
// Add label
98+
await github.rest.issues.addLabels({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
issue_number: pr.number,
102+
labels: ['ci:main']
103+
});
104+
105+
// Request reviews
106+
await github.rest.pulls.requestReviewers({
107+
owner: context.repo.owner,
108+
repo: context.repo.repo,
109+
pull_number: pr.number,
110+
reviewers: ['troglobit', 'wkz', 'mattiaswal']
111+
});
112+
}

utils/kernel-upgrade.sh

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
#!/bin/bash
2+
#
3+
# Automated kernel upgrade test script for LTS 6.12.x
4+
# Run from the infix directory and specify the path to the linux kernel tree
5+
#
6+
# Usage: ./utils/kernel-upgrade.sh <path-to-linux-dir>
7+
#
8+
9+
set -e
10+
11+
# Parse arguments
12+
if [ $# -ne 1 ]; then
13+
echo "Usage: $0 <path-to-linux-dir>"
14+
exit 1
15+
fi
16+
17+
LINUX_DIR="$1"
18+
19+
# Configuration
20+
INFIX_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
21+
INFIX_BRANCH="kernel-upgrade"
22+
LINUX_BRANCH="kkit-linux-6.12.y"
23+
UPSTREAM_REMOTE="upstream"
24+
UPSTREAM_URL="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
25+
KKIT_REMOTE="origin"
26+
KKIT_URL="[email protected]:kernelkit/linux.git"
27+
KERNEL_VERSION_PATTERN="6.12"
28+
29+
# Colors for output
30+
RED='\033[0;31m'
31+
GREEN='\033[0;32m'
32+
YELLOW='\033[1;33m'
33+
NC='\033[0m' # No Color
34+
35+
log_info() {
36+
echo -e "${GREEN}[INFO]${NC} $1"
37+
}
38+
39+
log_warn() {
40+
echo -e "${YELLOW}[WARN]${NC} $1"
41+
}
42+
43+
log_error() {
44+
echo -e "${RED}[ERROR]${NC} $1"
45+
}
46+
47+
# Check if directories exist
48+
check_directories() {
49+
log_info "Checking directories..."
50+
51+
if [ ! -d "$LINUX_DIR" ]; then
52+
log_info "Linux directory '$LINUX_DIR' not found, cloning..."
53+
if git clone "$KKIT_URL" "$LINUX_DIR"; then
54+
log_info "Successfully cloned linux repository"
55+
else
56+
log_error "Failed to clone linux repository"
57+
exit 1
58+
fi
59+
fi
60+
61+
if [ ! -d "$INFIX_DIR" ]; then
62+
log_error "Infix directory '$INFIX_DIR' not found"
63+
exit 1
64+
fi
65+
66+
if [ ! -f "$INFIX_DIR/utils/kernel-refresh.sh" ]; then
67+
log_error "Kernel refresh script not found at $INFIX_DIR/utils/kernel-refresh.sh"
68+
exit 1
69+
fi
70+
}
71+
72+
# Setup remotes for linux kernel tree
73+
setup_linux_remotes() {
74+
log_info "Setting up linux kernel remotes..."
75+
76+
# Add or update upstream remote (kernel.org via HTTPS)
77+
if git -C "$LINUX_DIR" remote get-url "$UPSTREAM_REMOTE" &>/dev/null; then
78+
log_info "Updating $UPSTREAM_REMOTE remote URL"
79+
git -C "$LINUX_DIR" remote set-url "$UPSTREAM_REMOTE" "$UPSTREAM_URL"
80+
else
81+
log_info "Adding $UPSTREAM_REMOTE remote"
82+
git -C "$LINUX_DIR" remote add "$UPSTREAM_REMOTE" "$UPSTREAM_URL"
83+
fi
84+
85+
# Add or update kkit remote (github via SSH)
86+
if git -C "$LINUX_DIR" remote get-url "$KKIT_REMOTE" &>/dev/null; then
87+
log_info "Updating $KKIT_REMOTE remote URL"
88+
git -C "$LINUX_DIR" remote set-url "$KKIT_REMOTE" "$KKIT_URL"
89+
else
90+
log_info "Adding $KKIT_REMOTE remote"
91+
git -C "$LINUX_DIR" remote add "$KKIT_REMOTE" "$KKIT_URL"
92+
fi
93+
}
94+
95+
# Update linux kernel tree
96+
update_linux_kernel() {
97+
log_info "Processing linux kernel tree..."
98+
99+
# Ensure we're on the correct branch
100+
log_info "Checking out branch $LINUX_BRANCH"
101+
git -C "$LINUX_DIR" checkout "$LINUX_BRANCH"
102+
103+
# Get current version before update
104+
CURRENT_VERSION=$(git -C "$LINUX_DIR" describe --tags 2>/dev/null || echo "unknown")
105+
log_info "Current version: $CURRENT_VERSION"
106+
107+
# Fetch from upstream (kernel.org)
108+
log_info "Fetching latest kernel updates from upstream..."
109+
git -C "$LINUX_DIR" fetch "$UPSTREAM_REMOTE"
110+
111+
# Fetch from kkit remote
112+
log_info "Fetching from kkit remote..."
113+
git -C "$LINUX_DIR" fetch "$KKIT_REMOTE"
114+
115+
# Pull changes from kkit remote
116+
log_info "Pulling latest changes from $KKIT_REMOTE..."
117+
git -C "$LINUX_DIR" pull "$KKIT_REMOTE" "$LINUX_BRANCH"
118+
}
119+
120+
# Rebase on new kernel
121+
rebase_kernel() {
122+
log_info "Rebasing on new kernel release..."
123+
124+
# Find the latest v6.12.x tag from upstream
125+
LATEST_TAG=$(git -C "$LINUX_DIR" tag -l "v${KERNEL_VERSION_PATTERN}.*" | sort -V | tail -n1)
126+
127+
if [ -z "$LATEST_TAG" ]; then
128+
log_error "No tags found matching v${KERNEL_VERSION_PATTERN}.*"
129+
exit 1
130+
fi
131+
132+
log_info "Latest kernel tag: $LATEST_TAG"
133+
log_info "Rebasing $LINUX_BRANCH on $LATEST_TAG..."
134+
135+
if git -C "$LINUX_DIR" rebase "$LATEST_TAG"; then
136+
log_info "Rebase successful"
137+
else
138+
log_error "Rebase failed. Manual intervention required."
139+
log_info "Run 'git rebase --abort' to cancel or resolve conflicts manually"
140+
exit 1
141+
fi
142+
143+
# Push rebased branch to kkit remote
144+
log_info "Pushing rebased branch to $KKIT_REMOTE..."
145+
if git -C "$LINUX_DIR" push "$KKIT_REMOTE" "$LINUX_BRANCH" --force-with-lease; then
146+
log_info "Successfully pushed to $KKIT_REMOTE"
147+
else
148+
log_error "Push failed"
149+
exit 1
150+
fi
151+
}
152+
153+
# Update infix and run kernel refresh
154+
update_infix() {
155+
log_info "Processing infix tree..."
156+
157+
# Fetch latest changes
158+
log_info "Fetching latest changes..."
159+
git fetch origin
160+
161+
# Update main branch
162+
log_info "Updating main branch..."
163+
git checkout main
164+
git pull origin main
165+
166+
# Check if branch exists and remove it
167+
if git show-ref --verify --quiet "refs/heads/$INFIX_BRANCH"; then
168+
log_info "Branch $INFIX_BRANCH exists, removing it..."
169+
git branch -D "$INFIX_BRANCH"
170+
fi
171+
172+
# Create fresh branch from main
173+
log_info "Creating fresh $INFIX_BRANCH from main..."
174+
git checkout -b "$INFIX_BRANCH"
175+
176+
# Get old kernel version from defconfig
177+
OLD_VERSION=$(grep 'BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE=' configs/aarch64_defconfig | cut -d'"' -f2)
178+
179+
if [ -z "$OLD_VERSION" ]; then
180+
log_error "Could not determine old kernel version from configs/aarch64_defconfig"
181+
exit 1
182+
fi
183+
184+
log_info "Old kernel version: $OLD_VERSION"
185+
186+
# Get new kernel version from linux tree
187+
NEW_VERSION=$(cd "$LINUX_DIR" && git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//')
188+
189+
if [ -z "$NEW_VERSION" ]; then
190+
log_error "Could not determine new kernel version"
191+
exit 1
192+
fi
193+
194+
log_info "New kernel version: $NEW_VERSION"
195+
196+
# Check if versions are the same
197+
if [ "$OLD_VERSION" = "$NEW_VERSION" ]; then
198+
log_info "Kernel version unchanged ($OLD_VERSION), skipping refresh"
199+
return 0
200+
fi
201+
202+
# Run kernel refresh script
203+
KERNEL_PATH="$(cd "$LINUX_DIR" && pwd)"
204+
PATCH_DIR="$INFIX_DIR/patches/linux/$NEW_VERSION"
205+
DEFCONFIG_DIR="$INFIX_DIR/configs"
206+
207+
log_info "bash utils/kernel-refresh.sh -k \"$KERNEL_PATH\" -o \"$OLD_VERSION\" -t \"v$NEW_VERSION\" -p \"$PATCH_DIR\" -d \"$DEFCONFIG_DIR\""
208+
log_info "Running kernel refresh script..."
209+
if bash utils/kernel-refresh.sh -k "$KERNEL_PATH" -o "$OLD_VERSION" -t "v$NEW_VERSION" -p "$PATCH_DIR" -d "$DEFCONFIG_DIR"; then
210+
log_info "Kernel refresh completed successfully"
211+
else
212+
log_error "Kernel refresh failed"
213+
exit 1
214+
fi
215+
216+
# Update ChangeLog.md with new kernel version
217+
log_info "Updating ChangeLog.md..."
218+
if [ -f "doc/ChangeLog.md" ]; then
219+
# Check if there's already a kernel upgrade entry in the latest release
220+
if grep -q "^- Upgrade Linux kernel to" doc/ChangeLog.md | head -20; then
221+
# Find and update the existing kernel upgrade line
222+
sed -i "0,/^- Upgrade Linux kernel to.*/{s/^- Upgrade Linux kernel to.*/- Upgrade Linux kernel to $NEW_VERSION (LTS)/}" doc/ChangeLog.md
223+
log_info "Updated existing kernel version entry to $NEW_VERSION"
224+
else
225+
# Add new kernel upgrade entry after the first "### Changes" section
226+
sed -i "0,/^### Changes/a\\
227+
\\
228+
- Upgrade Linux kernel to $NEW_VERSION (LTS)" doc/ChangeLog.md
229+
log_info "Added new kernel version entry: $NEW_VERSION"
230+
fi
231+
else
232+
log_warn "doc/ChangeLog.md not found, skipping changelog update"
233+
fi
234+
}
235+
236+
# Check for uncommitted changes
237+
check_clean_working_tree() {
238+
log_info "Checking for uncommitted changes..."
239+
240+
# Check infix directory
241+
if ! git -C "$INFIX_DIR" diff-index --quiet HEAD --; then
242+
log_error "Infix directory has uncommitted changes. Please commit or stash them first."
243+
exit 1
244+
fi
245+
246+
# Check linux directory if it exists
247+
if [ -d "$LINUX_DIR" ]; then
248+
if ! git -C "$LINUX_DIR" diff-index --quiet HEAD --; then
249+
log_error "Linux directory has uncommitted changes. Please commit or stash them first."
250+
exit 1
251+
fi
252+
fi
253+
254+
log_info "Working tree is clean"
255+
}
256+
257+
# Main execution
258+
main() {
259+
log_info "Starting automated kernel upgrade test..."
260+
log_info "Working directory: $(pwd)"
261+
262+
check_clean_working_tree
263+
check_directories
264+
setup_linux_remotes
265+
update_linux_kernel
266+
rebase_kernel
267+
update_infix
268+
269+
log_info "Kernel upgrade completed successfully!"
270+
}
271+
272+
# Run main function
273+
main

0 commit comments

Comments
 (0)