Skip to content

Commit 0fde346

Browse files
committed
CI: Improve check for new kernel
Improve the script to be able to run in workflow and fix the worflow and run each night. Signed-off-by: Mattias Walström <[email protected]>
1 parent 966fb48 commit 0fde346

File tree

2 files changed

+121
-54
lines changed

2 files changed

+121
-54
lines changed

.github/workflows/check-kernel-release.yml

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: Check Kernel 6.12 Release
22

33
on:
4-
workflow_dispatch: # Allow manual triggering
4+
schedule:
5+
- cron: '0 3 * * *'
6+
workflow_dispatch:
57

68
jobs:
79
check-kernel:
@@ -14,14 +16,6 @@ jobs:
1416
fetch-depth: 0
1517
token: ${{ secrets.KERNEL_UPDATE_TOKEN }}
1618

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-
2519
- name: Fetch kernel.org and check for 6.12 release
2620
id: check
2721
run: |
@@ -37,29 +31,61 @@ jobs:
3731
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
3832
echo "Current 6.12 kernel version: $CURRENT_VERSION"
3933
40-
# Get the latest tag from our linux tree
41-
cd linux
42-
git fetch origin
43-
LATEST_TAG=$(git tag -l "v6.12.*" | sort -V | tail -n1 | sed 's/^v//')
44-
cd ..
34+
# Get the version from infix defconfig
35+
INFIX_VERSION=$(grep 'BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE=' configs/aarch64_defconfig | cut -d'"' -f2)
36+
37+
echo "infix_version=$INFIX_VERSION" >> $GITHUB_OUTPUT
38+
echo "Infix kernel version: $INFIX_VERSION"
4539
46-
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
47-
echo "Latest tag in our tree: $LATEST_TAG"
40+
if [ "$CURRENT_VERSION" != "$INFIX_VERSION" ]; then
41+
# Check if there's already an open PR for this version
42+
PR_EXISTS=$(gh pr list --state open --search "Upgrade to kernel $CURRENT_VERSION in:title" --json number --jq 'length')
4843
49-
if [ "$CURRENT_VERSION" != "$LATEST_TAG" ]; then
50-
echo "new_release=true" >> $GITHUB_OUTPUT
51-
echo "🎉 New 6.12 kernel released: $CURRENT_VERSION (our version: $LATEST_TAG)"
44+
if [ "$PR_EXISTS" -gt 0 ]; then
45+
echo "new_release=false" >> $GITHUB_OUTPUT
46+
echo "PR already exists for kernel $CURRENT_VERSION, skipping"
47+
else
48+
echo "new_release=true" >> $GITHUB_OUTPUT
49+
echo "🎉 New 6.12 kernel released: $CURRENT_VERSION (infix version: $INFIX_VERSION)"
50+
fi
5251
else
5352
echo "new_release=false" >> $GITHUB_OUTPUT
5453
echo "No change - still at $CURRENT_VERSION"
5554
fi
55+
env:
56+
GH_TOKEN: ${{ secrets.KERNEL_UPDATE_TOKEN }}
57+
58+
- name: Generate branch name
59+
if: steps.check.outputs.new_release == 'true'
60+
id: branch
61+
run: |
62+
BRANCH_NAME="kernel-upgrade-$(uuidgen | tr '[:upper:]' '[:lower:]')"
63+
echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT
64+
echo "Branch name: $BRANCH_NAME"
65+
66+
- name: Import GPG key
67+
if: steps.check.outputs.new_release == 'true'
68+
run: |
69+
# Import the GPG key
70+
echo "${{ secrets.AEL_BOT_GPG_PRIVATE_KEY }}" | gpg --batch --import
71+
72+
# Get the key ID
73+
GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format=long | grep '^sec' | head -1 | awk '{print $2}' | cut -d'/' -f2)
74+
echo "GPG_KEY_ID=$GPG_KEY_ID" >> $GITHUB_ENV
75+
76+
# Configure GPG agent for non-interactive use
77+
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
78+
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
79+
gpg-connect-agent reloadagent /bye || true
5680
5781
- name: Set up git credentials
5882
if: steps.check.outputs.new_release == 'true'
5983
run: |
6084
set -e -o pipefail
6185
git config --global user.email "[email protected]"
6286
git config --global user.name "ael-bot"
87+
git config --global commit.gpgsign true
88+
git config --global user.signingkey ${{ env.GPG_KEY_ID }}
6389
6490
# Configure git to use the token for HTTPS operations
6591
git config --global url."https://ael-bot:${{ secrets.KERNEL_UPDATE_TOKEN }}@github.com/".insteadOf "[email protected]:"
@@ -69,17 +95,17 @@ jobs:
6995
if: steps.check.outputs.new_release == 'true'
7096
env:
7197
GIT_TERMINAL_PROMPT: 0
98+
BRANCH_NAME: ${{ steps.branch.outputs.name }}
7299
run: |
73100
set -e -o pipefail
74-
./utils/kernel-upgrade.sh linux
101+
./utils/kernel-upgrade.sh linux "$BRANCH_NAME"
75102
76103
- name: Create pull request
77104
if: steps.check.outputs.new_release == 'true'
78105
uses: actions/github-script@v7
79106
with:
80107
github-token: ${{ secrets.KERNEL_UPDATE_TOKEN }}
81108
script: |
82-
// Check if PR already exists
83109
const { data: pulls } = await github.rest.pulls.list({
84110
owner: context.repo.owner,
85111
repo: context.repo.repo,
@@ -92,20 +118,18 @@ jobs:
92118
owner: context.repo.owner,
93119
repo: context.repo.repo,
94120
title: `Upgrade to kernel ${{ steps.check.outputs.current_version }}`,
95-
head: 'kernel-upgrade',
121+
head: '${{ steps.branch.outputs.name }}',
96122
base: 'main',
97-
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.`
123+
body: `Automated kernel upgrade to version ${{ steps.check.outputs.current_version }}.\n\n**Previous version:** ${{ steps.check.outputs.infix_version }}\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.`
98124
});
99125
100-
// Add label
101126
await github.rest.issues.addLabels({
102127
owner: context.repo.owner,
103128
repo: context.repo.repo,
104129
issue_number: pr.number,
105130
labels: ['ci:main']
106131
});
107132
108-
// Request reviews
109133
await github.rest.pulls.requestReviewers({
110134
owner: context.repo.owner,
111135
repo: context.repo.repo,

utils/kernel-upgrade.sh

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@
99
set -e -o pipefail
1010

1111
# Parse arguments
12-
if [ $# -ne 1 ]; then
13-
echo "Usage: $0 <path-to-linux-dir>"
12+
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
13+
echo "Usage: $0 <path-to-linux-dir> [branch-name]"
1414
exit 1
1515
fi
1616

1717
LINUX_DIR="$1"
18+
INFIX_BRANCH="${2:-kernel-upgrade}"
1819

1920
# Configuration
2021
INFIX_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
21-
INFIX_BRANCH="kernel-upgrade"
2222
LINUX_BRANCH="kkit-linux-6.12.y"
2323
UPSTREAM_REMOTE="upstream"
2424
UPSTREAM_URL="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
2525
KKIT_REMOTE="origin"
26-
KKIT_URL="[email protected]:kernelkit/linux.git"
26+
27+
# Detect if running in CI (GitHub Actions sets CI=true)
28+
if [ "${CI:-false}" = "true" ]; then
29+
KKIT_URL="https://github.com/kernelkit/linux.git"
30+
else
31+
KKIT_URL="[email protected]:kernelkit/linux.git"
32+
fi
33+
2734
KERNEL_VERSION_PATTERN="6.12"
2835

2936
# Colors for output
@@ -50,8 +57,18 @@ check_directories() {
5057

5158
if [ ! -d "$LINUX_DIR" ]; then
5259
log_info "Linux directory '$LINUX_DIR' not found, cloning..."
53-
if git clone "$KKIT_URL" "$LINUX_DIR"; then
60+
# Clone to parent directory if LINUX_DIR is a relative path without slashes
61+
if [[ "$LINUX_DIR" != */* ]]; then
62+
CLONE_TARGET="../$LINUX_DIR"
63+
log_info "Cloning to $CLONE_TARGET (parent directory)"
64+
else
65+
CLONE_TARGET="$LINUX_DIR"
66+
fi
67+
68+
if git clone "$KKIT_URL" "$CLONE_TARGET"; then
5469
log_info "Successfully cloned linux repository"
70+
# Update LINUX_DIR to the actual path
71+
LINUX_DIR="$CLONE_TARGET"
5572
else
5673
log_error "Failed to clone linux repository"
5774
exit 1
@@ -204,24 +221,8 @@ update_infix() {
204221
exit 1
205222
fi
206223

207-
# Update ChangeLog.md with new kernel version
208-
log_info "Updating ChangeLog.md..."
209-
if [ -f "doc/ChangeLog.md" ]; then
210-
# Check if there's already a kernel upgrade entry in the latest release
211-
if grep -q "^- Upgrade Linux kernel to" doc/ChangeLog.md | head -20; then
212-
# Find and update the existing kernel upgrade line
213-
sed -i "0,/^- Upgrade Linux kernel to.*/{s/^- Upgrade Linux kernel to.*/- Upgrade Linux kernel to $NEW_VERSION (LTS)/}" doc/ChangeLog.md
214-
log_info "Updated existing kernel version entry to $NEW_VERSION"
215-
else
216-
# Add new kernel upgrade entry after the first "### Changes" section
217-
sed -i "0,/^### Changes/a\\
218-
\\
219-
- Upgrade Linux kernel to $NEW_VERSION (LTS)" doc/ChangeLog.md
220-
log_info "Added new kernel version entry: $NEW_VERSION"
221-
fi
222-
else
223-
log_warn "doc/ChangeLog.md not found, skipping changelog update"
224-
fi
224+
# Update changelog
225+
update_changelog "$NEW_VERSION"
225226

226227
# Commit all changes
227228
log_info "Committing changes to infix..."
@@ -234,6 +235,50 @@ update_infix() {
234235
fi
235236
}
236237

238+
# Update ChangeLog.md with new kernel version
239+
update_changelog() {
240+
local NEW_VERSION="$1"
241+
242+
log_info "Updating ChangeLog.md..."
243+
if [ ! -f "doc/ChangeLog.md" ]; then
244+
log_warn "doc/ChangeLog.md not found, skipping changelog update"
245+
return 0
246+
fi
247+
248+
# Check if the latest release is UNRELEASED (first release header in file)
249+
FIRST_RELEASE=$(grep -m1 "^\[v" doc/ChangeLog.md)
250+
if ! echo "$FIRST_RELEASE" | grep -q "\[UNRELEASED\]"; then
251+
log_error "First release section in ChangeLog.md is not UNRELEASED"
252+
log_error "Please create an UNRELEASED section first before running this script"
253+
exit 1
254+
fi
255+
256+
# Extract just the UNRELEASED section (from start until next version header)
257+
UNRELEASED_SECTION=$(sed -n '1,/^\[v[0-9]/p' doc/ChangeLog.md | head -n -1)
258+
259+
# Check if there's already a kernel upgrade entry in the UNRELEASED section
260+
if echo "$UNRELEASED_SECTION" | grep -q "^- Upgrade Linux kernel to"; then
261+
# Update existing kernel upgrade line (only first occurrence)
262+
sed -i "0,/^- Upgrade Linux kernel to.*/{s|^- Upgrade Linux kernel to.*|- Upgrade Linux kernel to $NEW_VERSION (LTS)|}" doc/ChangeLog.md
263+
log_info "Updated existing kernel version entry to $NEW_VERSION"
264+
else
265+
# Add new kernel upgrade entry after first "### Changes"
266+
# Use awk to insert at the right place
267+
awk -v new_line="- Upgrade Linux kernel to $NEW_VERSION (LTS)" '
268+
/^### Changes/ && !done {
269+
print
270+
getline
271+
if (NF == 0) print
272+
print new_line
273+
done=1
274+
next
275+
}
276+
{print}
277+
' doc/ChangeLog.md > doc/ChangeLog.md.tmp && mv doc/ChangeLog.md.tmp doc/ChangeLog.md
278+
log_info "Added new kernel version entry: $NEW_VERSION"
279+
fi
280+
}
281+
237282
# Check for uncommitted changes
238283
check_clean_working_tree() {
239284
log_info "Checking for uncommitted changes..."
@@ -255,20 +300,18 @@ check_clean_working_tree() {
255300
log_info "Working tree is clean"
256301
}
257302

258-
# Push changes to remotes
303+
# Push changes to both repositories
259304
push_changes() {
260-
log_info "Pushing changes to remotes..."
261-
262-
# Push rebased linux branch to kkit remote
263-
log_info "Pushing rebased linux branch to $KKIT_REMOTE..."
305+
# Push rebased linux branch
306+
log_info "Pushing linux branch to $KKIT_REMOTE..."
264307
if git -C "$LINUX_DIR" push "$KKIT_REMOTE" "$LINUX_BRANCH" --force-with-lease; then
265308
log_info "Successfully pushed linux branch to $KKIT_REMOTE"
266309
else
267310
log_error "Push to linux remote failed"
268311
exit 1
269312
fi
270313

271-
# Push infix branch to origin
314+
# Push infix changes
272315
log_info "Pushing infix branch to origin..."
273316
if git -C "$INFIX_DIR" push origin "$INFIX_BRANCH"; then
274317
log_info "Successfully pushed infix branch to origin"

0 commit comments

Comments
 (0)