Skip to content

Commit ab86632

Browse files
committed
getting there
1 parent 1792e9c commit ab86632

File tree

1 file changed

+28
-48
lines changed

1 file changed

+28
-48
lines changed

.github/workflows/upstream-fix-check.yml

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
1616
- name: Clone Linux Kernel (Bare) # Step 0: Perform a bare clone of the Linux kernel repository
1717
run: |
18-
echo "Cloning Linux kernel repository (bare clone, single branch, no blobs)..."
19-
git clone --bare --filter=blob:none --single-branch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux.git
18+
echo "Cloning Linux kernel repository (bare clone, single branch, no blobs) into 'linux' directory..."
19+
git clone --bare --filter=blob:none --single-branch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux
2020
echo "Cloning complete."
2121
2222
- name: Get PR commit SHAs via GitHub API # Step 1: Get the list of all commit SHAs in the current Pull Request using GitHub API
@@ -54,25 +54,23 @@ jobs:
5454
# Use printf -v for robust multi-line string accumulation for the PR comment
5555
PR_COMMENT_BODY_ACCUMULATOR=""
5656
57-
# Get the HEAD commit SHA and its date for the Linux kernel master branch
57+
# Get the current HEAD commit SHA for the Linux kernel master branch from the local clone
5858
printf -v PR_COMMENT_BODY_ACCUMULATOR "%sGetting current HEAD of '%s/%s' master branch from local bare clone...\n" \
5959
"$PR_COMMENT_BODY_ACCUMULATOR" "$LINUX_KERNEL_REPO_OWNER" "$LINUX_KERNEL_REPO_NAME"
6060
61-
HEAD_COMMIT_SHA=$(git -C linux.git rev-parse master)
62-
# Get committer date in ISO 8601 format for `git log --until`
63-
HEAD_COMMIT_DATE=$(git -C linux.git show -s --format=%cI master)
61+
HEAD_COMMIT_SHA=$(git -C linux rev-parse master)
6462
65-
if [ -z "$HEAD_COMMIT_SHA" ] || [ -z "$HEAD_COMMIT_DATE" ]; then
66-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s ERROR: Could not retrieve HEAD commit or date for Linux kernel master from local clone.\n" \
63+
if [ -z "$HEAD_COMMIT_SHA" ]; then
64+
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s ERROR: Could not retrieve HEAD commit for Linux kernel master from local clone.\n" \
6765
"$PR_COMMENT_BODY_ACCUMULATOR"
6866
echo "PR_COMMENT_BODY<<EOF" >> "$GITHUB_OUTPUT"
6967
echo "$PR_COMMENT_BODY_ACCUMULATOR" >> "$GITHUB_OUTPUT"
7068
echo "EOF" >> "$GITHUB_OUTPUT"
7169
exit 1
7270
fi
7371
74-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Linux kernel master HEAD: \`%s\` (as of %s)\n\n" \
75-
"$PR_COMMENT_BODY_ACCUMULATOR" "$HEAD_COMMIT_SHA" "$HEAD_COMMIT_DATE"
72+
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Linux kernel master HEAD: \`%s\`\n\n" \
73+
"$PR_COMMENT_BODY_ACCUMULATOR" "$HEAD_COMMIT_SHA"
7674
7775
7876
# Loop through each commit SHA identified in the current PR
@@ -112,55 +110,35 @@ jobs:
112110
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Found upstream Linux hash to check for fixes: \`%s\`\n" \
113111
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
114112
115-
# --- Get commit date of the UPSTREAM_LINUX_HASH from the cloned Linux kernel repo ---
116-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Getting commit date for upstream Linux commit \`%s\` from local bare clone...\n" \
117-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
118-
119-
# Check if the upstream hash exists in the local clone first
120-
if ! git -C linux.git cat-file -e "$UPSTREAM_LINUX_HASH"; then
121-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s ERROR: Upstream commit \`%s\` not found in the local Linux kernel bare clone. This might indicate an invalid or very old hash.\n" \
122-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
123-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s\n" "$PR_COMMENT_BODY_ACCUMULATOR"
124-
continue # Continue to the next PR commit
125-
fi
126-
127-
# Get committer date in ISO 8601 format for `git log --since`
128-
UPSTREAM_COMMIT_DATE=$(git -C linux.git show -s --format=%cI "$UPSTREAM_LINUX_HASH")
129-
130-
if [ -z "$UPSTREAM_COMMIT_DATE" ]; then
131-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s ERROR: Upstream commit \`%s\` found, but its date could not be extracted from local clone.\n" \
132-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
133-
echo "PR_COMMENT_BODY<<EOF" >> "$GITHUB_OUTPUT"
134-
echo "$PR_COMMENT_BODY_ACCUMULATOR" >> "$GITHUB_OUTPUT"
135-
echo "EOF" >> "$GITHUB_OUTPUT"
136-
exit 1
137-
fi
138-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Upstream commit \`%s\` date: %s\n" \
139-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH" "$UPSTREAM_COMMIT_DATE"
140-
141-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Searching for upstream commits on 'master' branch between \`%s\` and \`%s\` that fix \`%s\` using \`git log\`...\n" \
142-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_COMMIT_DATE" "$HEAD_COMMIT_DATE" "$UPSTREAM_LINUX_HASH"
113+
# --- Search for "Fixes:" tag in upstream Linux kernel using git log ---
114+
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Searching for upstream commits on 'master' branch in range \`%s..%s\` that fix \`%s\` using \`git log\`...\n" \
115+
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH" "$HEAD_COMMIT_SHA" "$UPSTREAM_LINUX_HASH"
143116
144117
FOUND_FIXING_COMMITS=()
145-
# Construct the grep pattern using the first 12 characters of the SHA, commonly used in Fixes: tags in Linux kernel.
146-
UPSTREAM_LINUX_HASH_SHORT=$(echo "$UPSTREAM_LINUX_HASH" | cut -c 1-12)
147-
GREP_PATTERN="Fixes: ${UPSTREAM_LINUX_HASH_SHORT}"
118+
# Construct the grep pattern using the full SHA as it's the most precise match.
119+
# `git log` grep is powerful enough for full SHA.
120+
GREP_PATTERN="Fixes: ${UPSTREAM_LINUX_HASH}"
148121
149-
# Use git log to find commits that mention the short SHA in their message, after the original commit's date.
122+
# Use git log to find commits that mention the full SHA in their "Fixes:" line,
123+
# in the range from the specific commit up to HEAD.
150124
# --pretty=format:"%H%n%B" ensures SHA on one line, followed by the full message.
151-
GIT_LOG_OUTPUT=$(git -C linux.git log master \
152-
--since="${UPSTREAM_COMMIT_DATE}" \
153-
--until="${HEAD_COMMIT_DATE}" \
125+
# --invert-grep ensures we exclude the UPSTREAM_LINUX_HASH if it somehow
126+
# matches its own Fixes: tag (shouldn't happen, but defensive).
127+
# --regexp-ignore-case for case-insensitive grep (Fixes: vs fixes:).
128+
# We explicitly include --invert-grep "${UPSTREAM_LINUX_HASH}" to ensure
129+
# the original commit itself is not included in the results for "Fixes:"
130+
# that points to itself, as we are looking for *subsequent* fixes.
131+
GIT_LOG_OUTPUT=$(git -C linux log master \
132+
"${UPSTREAM_LINUX_HASH}..${HEAD_COMMIT_SHA}" \
154133
--grep="${GREP_PATTERN}" \
155134
--pretty=format:"%H%n%B" \
156-
--regexp-ignore-case) # Use --regexp-ignore-case for case-insensitive grep
135+
--regexp-ignore-case)
157136
158137
if [ -z "$GIT_LOG_OUTPUT" ]; then
159138
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s No upstream fixes found for \`%s\` in the specified range.\n" \
160139
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
161140
else
162141
# Process the git log output line by line to parse SHAs and full messages.
163-
# Then, perform a more precise check for the full SHA in the "Fixes:" line.
164142
current_commit_sha=""
165143
commit_message_lines=()
166144
# Read the git log output, handling multi-line messages
@@ -170,6 +148,8 @@ jobs:
170148
# Process the previous commit's message (if any) before starting a new one.
171149
if [ -n "$current_commit_sha" ]; then
172150
FULL_MESSAGE=$(printf "%s\n" "${commit_message_lines[@]}")
151+
# Final check on the full message (though grep already filtered)
152+
# to extract the specific Fixes: line for display.
173153
if echo "$FULL_MESSAGE" | grep -Eq "^Fixes: [0-9a-fA-F]*${UPSTREAM_LINUX_HASH}.*"; then
174154
FIX_MESSAGE_SNIPPET=$(echo "$FULL_MESSAGE" | grep -Ei "^Fixes:.*${UPSTREAM_LINUX_HASH}.*")
175155
FOUND_FIXING_COMMITS+=("${current_commit_sha}:${FIX_MESSAGE_SNIPPET}")
@@ -183,7 +163,7 @@ jobs:
183163
fi
184164
done <<< "$GIT_LOG_OUTPUT"
185165
186-
# Process the last commit in the output
166+
# Process the last commit in the output (after the loop finishes)
187167
if [ -n "$current_commit_sha" ]; then
188168
FULL_MESSAGE=$(printf "%s\n" "${commit_message_lines[@]}")
189169
if echo "$FULL_MESSAGE" | grep -Eq "^Fixes: [0-9a-fA-F]*${UPSTREAM_LINUX_HASH}.*"; then

0 commit comments

Comments
 (0)