Skip to content

Commit 0afdb2a

Browse files
committed
[LTR] Update kernel.spec during rebases
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.
1 parent 96d6e4c commit 0afdb2a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lt_rebase.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,68 @@ if [ ! -z "$REPO_STATUS" ]; then
148148
git commit -m "[CIQ] $(git describe --tags --abbrev=0) - rebased configs"
149149
fi
150150

151+
SPEC_FILE="./SPECS/kernel.spec"
152+
if [ -f "$SPEC_FILE" ] ; then
153+
UPSTREAM_TAG=$(git describe --tags --abbrev=0)
154+
if [ -z "$UPSTREAM_TAG" ]; then
155+
echo "ERROR: Could not determine upstream tag via git describe. Cannot update spec."
156+
exit 1
157+
fi
158+
FULL_KERNEL_VERSION=${UPSTREAM_TAG#v}
159+
TAG_VERSION="${FULL_KERNEL_VERSION}-1"
160+
NEW_TAG="ciq_kernel-${TAG_VERSION}"
161+
DISTLOCALVERSION=${DISTLOCALVERSION:-".1.0.0"}
162+
DIST=${DIST:-".el9_clk"}
163+
SPECTARFILE_RELEASE=${TAG_VERSION}$DISTLOCALVERSION$DIST
164+
165+
echo "Updating kernel.spec version variables and changelog..."
166+
167+
# Update version variables
168+
sed -i -e "s/^%define specrpmversion .*/%define specrpmversion $FULL_KERNEL_VERSION/" \
169+
-e "s/^%define specversion .*/%define specversion $FULL_KERNEL_VERSION/" \
170+
-e "s/^%define tarfile_release .*/%define tarfile_release $SPECTARFILE_RELEASE/" \
171+
"$SPEC_FILE"
172+
173+
# Generate changelog
174+
# Extract major version (e.g., 6 from 6.12.74)
175+
MAJOR_VERSION=${FULL_KERNEL_VERSION%%.*}
176+
CHANGELOG_DATE=$(date '+%a %b %d %Y')
177+
CHANGELOG_HEADER="* $CHANGELOG_DATE $(git config user.name) <$(git config user.email)> - ${TAG_VERSION}${DISTLOCALVERSION}${DIST}"
178+
TEMP_CHANGELOG=$(mktemp)
179+
TEMP_COMMENTS=$(mktemp)
180+
181+
# Full changelog for new kernel version or initial spec update
182+
echo "$CHANGELOG_HEADER" > "$TEMP_CHANGELOG"
183+
echo "-- Rebased changes for Linux $FULL_KERNEL_VERSION (https://github.com/ctrliq/kernel-src-tree/releases/tag/$NEW_TAG)" >> "$TEMP_CHANGELOG"
184+
git log --no-merges --pretty=format:"-- %s (%an)" ${UPSTREAM_TAG}..HEAD >> "$TEMP_CHANGELOG"
185+
echo "" >> "$TEMP_CHANGELOG"
186+
echo "-- Linux $FULL_KERNEL_VERSION (https://cdn.kernel.org/pub/linux/kernel/v$MAJOR_VERSION.x/ChangeLog-$FULL_KERNEL_VERSION)" >> "$TEMP_CHANGELOG"
187+
echo "" >> "$TEMP_CHANGELOG"
188+
echo "" >> "$TEMP_CHANGELOG"
189+
190+
# Extract trailing comments (lines starting with # after %changelog)
191+
awk '/^%changelog$/,0 {if (/^#/ || /^###/) print}' "$SPEC_FILE" > "$TEMP_COMMENTS"
192+
193+
# Rebuild changelog section
194+
if ! grep -q '^%changelog$' "$SPEC_FILE"; then
195+
echo "ERROR: %changelog section not found in $SPEC_FILE. Cannot update spec."
196+
exit 1
197+
fi
198+
# Remove everything from %changelog onwards
199+
sed -i '/^%changelog$/q' "$SPEC_FILE"
200+
201+
# Add new changelog entry
202+
cat "$TEMP_CHANGELOG" >> "$SPEC_FILE"
203+
204+
# Add trailing comments if any
205+
if [ -s "$TEMP_COMMENTS" ]; then
206+
cat "$TEMP_COMMENTS" >> "$SPEC_FILE"
207+
fi
208+
209+
rm -f "$TEMP_CHANGELOG" "$TEMP_COMMENTS"
151210

211+
git add "$SPEC_FILE"
212+
git commit -m "[CIQ] $(git describe --tags --abbrev=0) - updated spec"
213+
214+
echo "Spec file updated successfully"
215+
fi

0 commit comments

Comments
 (0)