Skip to content

[LTR] Update kernel.spec during rebases#60

Open
bmastbergen wants to merge 2 commits intomainlinefrom
clk-spec-update
Open

[LTR] Update kernel.spec during rebases#60
bmastbergen wants to merge 2 commits intomainlinefrom
clk-spec-update

Conversation

@bmastbergen
Copy link
Collaborator

@bmastbergen bmastbergen commented Mar 11, 2026

When rebasing a CLK kernel onto a new LT kernel, update kernel.spec to match (if it exists).

Update the kernel version strings and replace the changelog with references to the upstream LT we are rebasing on and the commits we apply on top of it.

This goes long with this kernel-src-tree PR to embed CLK dist-git in the source:
ctrliq/kernel-src-tree#959

An example of what a rebased branch looks like with this change is here:
https://github.com/ctrliq/kernel-src-tree/tree/%7Bbmastbergen%7D_ciq-6.12.y-next

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automation to update an embedded dist-git SPECS/kernel.spec during LT rebases so the spec’s version fields and %changelog reflect the new upstream base and the CIQ-on-top commits.

Changes:

  • Detect and update SPECS/kernel.spec version macros based on the current upstream tag.
  • Regenerate the spec %changelog with links to the rebased LT release and the applied-on-top commit list.
  • Commit the spec update as part of the rebase script run when the spec file exists.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 12, 2026 20:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

lt_rebase.sh Outdated
Comment on lines +211 to +214
git add "$SPEC_FILE"
git commit -m "[CIQ] $(git describe --tags --abbrev=0) - updated spec"

echo "Spec file updated successfully"
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git commit -m "... - updated spec" is unconditional once the spec block runs. If rerun and the spec content ends up unchanged, git commit will fail with “nothing to commit” and abort the script. Consider checking git diff --quiet -- "$SPEC_FILE" (or git status --porcelain) before committing, similar to how config commits are gated earlier in the script.

Suggested change
git add "$SPEC_FILE"
git commit -m "[CIQ] $(git describe --tags --abbrev=0) - updated spec"
echo "Spec file updated successfully"
# Only commit if the spec file has actually changed
if git diff --quiet -- "$SPEC_FILE"; then
echo "No changes detected in $SPEC_FILE; skipping spec commit"
else
git add "$SPEC_FILE"
git commit -m "[CIQ] $(git describe --tags --abbrev=0) - updated spec"
echo "Spec file updated successfully"
fi

Copilot uses AI. Check for mistakes.
lt_rebase.sh Outdated
Comment on lines +153 to +160
UPSTREAM_TAG=$(git describe --tags --abbrev=0)
if [ -z "$UPSTREAM_TAG" ]; then
echo "ERROR: Could not determine upstream tag via git describe. Cannot update spec."
exit 1
fi
FULL_KERNEL_VERSION=${UPSTREAM_TAG#v}
TAG_VERSION="${FULL_KERNEL_VERSION}-1"
NEW_TAG="ciq_kernel-${TAG_VERSION}"
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPSTREAM_TAG=$(git describe --tags --abbrev=0) can resolve to a non-upstream tag (e.g., a ciq_kernel-* tag) and then FULL_KERNEL_VERSION=${UPSTREAM_TAG#v} will produce an invalid version string/URLs. Consider constraining git describe with --match 'v[0-9]*' (or similar) and validating the result against an expected vX.Y.Z regex before using it to rewrite kernel.spec.

Copilot uses AI. Check for mistakes.
lt_rebase.sh Outdated
# Extract major version (e.g., 6 from 6.12.74)
MAJOR_VERSION=${FULL_KERNEL_VERSION%%.*}
CHANGELOG_DATE=$(date '+%a %b %d %Y')
CHANGELOG_HEADER="* $CHANGELOG_DATE $(git config user.name) <$(git config user.email)> - ${TAG_VERSION}${DISTLOCALVERSION}${DIST}"
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGELOG_HEADER depends on git config user.name / user.email, which are often unset in CI/automation environments; that would generate an invalid RPM changelog header. Consider failing with a helpful message if either is empty, or providing a deterministic fallback identity for automated rebases.

Suggested change
CHANGELOG_HEADER="* $CHANGELOG_DATE $(git config user.name) <$(git config user.email)> - ${TAG_VERSION}${DISTLOCALVERSION}${DIST}"
GIT_USER_NAME=$(git config user.name || true)
GIT_USER_EMAIL=$(git config user.email || true)
if [ -z "$GIT_USER_NAME" ] || [ -z "$GIT_USER_EMAIL" ]; then
echo "WARNING: git user.name or user.email not set; using fallback identity for changelog entry."
GIT_USER_NAME=${GIT_USER_NAME:-"Automated Rebase"}
GIT_USER_EMAIL=${GIT_USER_EMAIL:-"autorebase@example.com"}
fi
CHANGELOG_HEADER="* $CHANGELOG_DATE $GIT_USER_NAME <$GIT_USER_EMAIL> - ${TAG_VERSION}${DISTLOCALVERSION}${DIST}"

Copilot uses AI. Check for mistakes.
lt_rebase.sh Outdated
Comment on lines +178 to +197
TEMP_CHANGELOG=$(mktemp)
TEMP_COMMENTS=$(mktemp)

# Full changelog for new kernel version or initial spec update
echo "$CHANGELOG_HEADER" > "$TEMP_CHANGELOG"
echo "-- Rebased changes for Linux $FULL_KERNEL_VERSION (https://github.com/ctrliq/kernel-src-tree/releases/tag/$NEW_TAG)" >> "$TEMP_CHANGELOG"
git log --no-merges --pretty=format:"-- %s (%an)" ${UPSTREAM_TAG}..HEAD >> "$TEMP_CHANGELOG"
echo "" >> "$TEMP_CHANGELOG"
echo "-- Linux $FULL_KERNEL_VERSION (https://cdn.kernel.org/pub/linux/kernel/v$MAJOR_VERSION.x/ChangeLog-$FULL_KERNEL_VERSION)" >> "$TEMP_CHANGELOG"
echo "" >> "$TEMP_CHANGELOG"
echo "" >> "$TEMP_CHANGELOG"

# Extract trailing comments (lines starting with # after %changelog)
awk '/^%changelog$/,0 {if (/^#/ || /^###/) print}' "$SPEC_FILE" > "$TEMP_COMMENTS"

# Rebuild changelog section
if ! grep -q '^%changelog$' "$SPEC_FILE"; then
echo "ERROR: %changelog section not found in $SPEC_FILE. Cannot update spec."
exit 1
fi
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEMP_CHANGELOG/TEMP_COMMENTS are only cleaned up on the success path. If the script exits early (e.g., %changelog missing, git/log failure), these temp files will be left behind. Consider adding a trap that removes the temp files on EXIT once they’re created.

Copilot uses AI. Check for mistakes.
@jdieter
Copy link

jdieter commented Mar 13, 2026

Don't we already have a script that does a good chunk of this in mkdistgitdiff.py? Wouldn't it make sense to use that script (maybe adapting it)?

@bmastbergen
Copy link
Collaborator Author

Don't we already have a script that does a good chunk of this in mkdistgitdiff.py? Wouldn't it make sense to use that script (maybe adapting it)?

In my head this deviates from what that does a good bit, but you are right to ask. I'll give it a look to see if we could make mkdistgitdiff.py work

@PlaidCat
Copy link
Collaborator

Don't we already have a script that does a good chunk of this in mkdistgitdiff.py? Wouldn't it make sense to use that script (maybe adapting it)?

In my head this deviates from what that does a good bit, but you are right to ask. I'll give it a look to see if we could make mkdistgitdiff.py work

Maybe we can pull out some common functions or functionality.

When rebasing a CLK kernel onto a new LT kernel, update
kernel.spec to match (if it exists).

Update the kernel version strings and replace the changelog
with references to the upstream LT we are rebasing on and
the commits we apply on top of it.
@bmastbergen
Copy link
Collaborator Author

Still looking at mkdistgitdiff. For the moment, updated to adjust to kernel.spec being in ciq/SPECS now.

Copilot AI review requested due to automatic review settings March 16, 2026 20:19
@bmastbergen
Copy link
Collaborator Author

Trying to use mkdistgitdiff really felt like shoehorning in something different. However, I do think having a python script to do the updating is a good idea. We will need to tweak this in the future to handle the non-rebase update case and I think update_lt_spec.py will be better for that. Initially I did have this in kernel-tools (with mkdistgitdiff.py) but they don't really share much other than ciq_helpers, so it seemed simpler to put it in this repo.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +226 to +229
srcgit.git.add(spec_path)

# Check if there are changes to commit
if srcgit.is_dirty(path=spec_path):

import argparse
import os
import re
# Validate tag format (should be like 'v6.12.74' or '6.12.74')
tag_without_v = upstream_tag.lstrip('v')
tag_parts = tag_without_v.split('.')
if len(tag_parts) < 2:
Comment on lines +170 to +176
# Call update_lt_spec.py to update the spec file
python "$UPDATE_LT_SPEC" \
--srcgit . \
--spec-file "$SPEC_FILE" \
--distlocalversion "$DISTLOCALVERSION" \
--dist "$DIST" \
--commit
Comment on lines +15 to +23
from ciq_helpers import last_git_tag

try:
import git
except ImportError:
print('ERROR: GitPython is not installed. Install it with: pip install GitPython')
sys.exit(1)


Python will be easier to extend in the future when
we need to update the spec for more than just rebases.
Copilot AI review requested due to automatic review settings March 16, 2026 21:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +79 to +89
try:
config = srcgit.config_reader()
name = config.get_value("user", "name")
email = config.get_value("user", "email")
except Exception as e:
print("ERROR: Failed to read git config. Please ensure user.name and user.email are configured.")
print(' Run: git config --global user.name "Your Name"')
print(' Run: git config --global user.email "your.email@example.com"')
print(f" Error details: {e}")
sys.exit(1)

Comment on lines +193 to +207
tag_without_v = upstream_tag.lstrip("v")
tag_parts = tag_without_v.split(".")
if len(tag_parts) < 3:
print(f"ERROR: Invalid tag format: {upstream_tag}")
print(" Expected format: vX.Y.Z or X.Y.Z (e.g., v6.12.74)")
sys.exit(1)

# Validate that parts are numeric
try:
for part in tag_parts:
int(part)
except ValueError:
print(f"ERROR: Invalid tag format: {upstream_tag}")
print(" Tag version parts must be numeric")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants