Skip to content

Commit 68a3fb7

Browse files
committed
previous commit worked. now reducing output
1 parent 013a91f commit 68a3fb7

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

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

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,21 @@ jobs:
5555
PR_COMMENT_BODY_ACCUMULATOR=""
5656
5757
# Get the current HEAD commit SHA for the Linux kernel master branch from the local clone
58-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%sGetting current HEAD of '%s/%s' master branch from local bare clone...\n" \
59-
"$PR_COMMENT_BODY_ACCUMULATOR" "$LINUX_KERNEL_REPO_OWNER" "$LINUX_KERNEL_REPO_NAME"
58+
echo "Getting current HEAD of '${LINUX_KERNEL_REPO_OWNER}/${LINUX_KERNEL_REPO_NAME}' master branch from local bare clone..."
6059
6160
HEAD_COMMIT_SHA=$(git -C linux rev-parse master)
6261
6362
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" \
65-
"$PR_COMMENT_BODY_ACCUMULATOR"
66-
echo "PR_COMMENT_BODY<<EOF" >> "$GITHUB_OUTPUT"
67-
echo "$PR_COMMENT_BODY_ACCUMULATOR" >> "$GITHUB_OUTPUT"
68-
echo "EOF" >> "$GITHUB_OUTPUT"
63+
echo "ERROR: Could not retrieve HEAD commit for Linux kernel master from local clone."
6964
exit 1
7065
fi
7166
72-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Linux kernel master HEAD: \`%s\`\n\n" \
73-
"$PR_COMMENT_BODY_ACCUMULATOR" "$HEAD_COMMIT_SHA"
67+
echo "Linux kernel master HEAD: ${HEAD_COMMIT_SHA}"
7468
7569
7670
# Loop through each commit SHA identified in the current PR
7771
for PR_COMMIT_SHA in ${{ steps.pr_commits.outputs.PR_COMMITS }}; do
78-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s--- Checking PR commit: \`%s\` ---\n" \
79-
"$PR_COMMENT_BODY_ACCUMULATOR" "$PR_COMMIT_SHA"
72+
echo "--- Checking PR commit: ${PR_COMMIT_SHA} ---"
8073
8174
# --- Fetch the full commit message of the PR commit via GitHub API ---
8275
PR_COMMIT_DETAILS_JSON=$(curl -sS -H "Accept: application/vnd.github.v3+json" \
@@ -85,13 +78,8 @@ jobs:
8578
8679
ERROR_MESSAGE=$(echo "$PR_COMMIT_DETAILS_JSON" | jq -r 'if type == "object" and .message then .message else null end')
8780
if [ "$ERROR_MESSAGE" != "null" ] && [ -n "$ERROR_MESSAGE" ]; then
88-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s ERROR: Could not retrieve commit message for PR commit \`%s\` from GitHub API: %s\n" \
89-
"$PR_COMMENT_BODY_ACCUMULATOR" "$PR_COMMIT_SHA" "$ERROR_MESSAGE"
90-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s API Response snippet: %s\n" \
91-
"$PR_COMMENT_BODY_ACCUMULATOR" "$(echo "$PR_COMMIT_DETAILS_JSON" | head -n 5)"
92-
echo "PR_COMMENT_BODY<<EOF" >> "$GITHUB_OUTPUT"
93-
echo "$PR_COMMENT_BODY_ACCUMULATOR" >> "$GITHUB_OUTPUT"
94-
echo "EOF" >> "$GITHUB_OUTPUT"
81+
echo "ERROR: Could not retrieve commit message for PR commit ${PR_COMMIT_SHA} from GitHub API: ${ERROR_MESSAGE}"
82+
echo "API Response snippet: $(echo "$PR_COMMIT_DETAILS_JSON" | head -n 5)"
9583
exit 1
9684
fi
9785
@@ -101,21 +89,24 @@ jobs:
10189
UPSTREAM_LINUX_HASH=$(echo "$PR_COMMIT_MESSAGE" | grep -Eo "^commit [0-9a-f]{40}$" | awk '{print $2}')
10290
10391
if [ -z "$UPSTREAM_LINUX_HASH" ]; then
104-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s No \`commit <upstream_linux_commit_hash>\` line found in PR commit \`%s\`. Skipping upstream check for this commit.\n" \
105-
"$PR_COMMENT_BODY_ACCUMULATOR" "$PR_COMMIT_SHA"
106-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s\n" "$PR_COMMENT_BODY_ACCUMULATOR"
107-
continue
92+
echo "No 'commit <upstream_linux_commit_hash>' line found in PR commit ${PR_COMMIT_SHA}. Skipping upstream check for this commit."
93+
continue # Skip to next PR commit, no comment for this scenario
10894
fi
10995
110-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Found upstream Linux hash to check for fixes: \`%s\`\n" \
111-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
96+
echo "Found upstream Linux hash to check for fixes: ${UPSTREAM_LINUX_HASH}"
97+
98+
# --- Check if the upstream hash exists in the local cloned Linux kernel repo ---
99+
if ! git -C linux cat-file -e "$UPSTREAM_LINUX_HASH"; then
100+
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s- **PR commit \`%s\`**: References upstream commit \`%s\` which was **NOT found** in the Linux kernel repository. Please verify the hash.\n" \
101+
"$PR_COMMENT_BODY_ACCUMULATOR" "$PR_COMMIT_SHA" "$UPSTREAM_LINUX_HASH"
102+
continue # Skip to next PR commit, but added message to comment
103+
fi
112104
113105
# --- Search for "Fixes:" tag in upstream Linux kernel using git log ---
114106
# Extract the first 12 characters for the short SHA, commonly used in Fixes: tags in Linux kernel.
115107
UPSTREAM_LINUX_HASH_SHORT=$(echo "$UPSTREAM_LINUX_HASH" | cut -c 1-12)
116108
117-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Searching for upstream commits on 'master' branch in range \`%s..%s\` that fix \`%s\` using \`git log --grep=\"Fixes: %s\"\`...\n" \
118-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH" "$HEAD_COMMIT_SHA" "$UPSTREAM_LINUX_HASH" "$UPSTREAM_LINUX_HASH_SHORT"
109+
echo "Searching for upstream commits on 'master' branch in range ${UPSTREAM_LINUX_HASH}..${HEAD_COMMIT_SHA} that fix ${UPSTREAM_LINUX_HASH} using 'git log --grep=\"Fixes: ${UPSTREAM_LINUX_HASH_SHORT}\"'..."
119110
120111
# Construct the grep pattern using the SHORT SHA for search.
121112
GREP_PATTERN="Fixes: ${UPSTREAM_LINUX_HASH_SHORT}"
@@ -132,20 +123,21 @@ jobs:
132123
--pretty=format:"%h %s" \
133124
--regexp-ignore-case)
134125
135-
if [ -z "$GIT_LOG_FIXES_OUTPUT" ]; then
136-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s No upstream fixes found for \`%s\` in the specified range.\n" \
137-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
138-
else
139-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s SUCCESS: Found upstream Linux commit(s) that fix \`%s\`:\n" \
140-
"$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
126+
if [ -n "$GIT_LOG_FIXES_OUTPUT" ]; then
127+
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s- **PR commit \`%s\`**: References upstream commit \`%s\` which has the following fixes in the Linux kernel log:\n" \
128+
"$PR_COMMENT_BODY_ACCUMULATOR" "$PR_COMMIT_SHA" "$UPSTREAM_LINUX_HASH"
141129
# Add a markdown code block for the git log output
142130
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s\`\`\`\n%s\n\`\`\`\n" \
143131
"$PR_COMMENT_BODY_ACCUMULATOR" "$GIT_LOG_FIXES_OUTPUT"
132+
else
133+
echo "No upstream fixes found for ${UPSTREAM_LINUX_HASH} in the specified range."
134+
# No comment added to PR_COMMENT_BODY_ACCUMULATOR for this scenario
144135
fi
145-
printf -v PR_COMMENT_BODY_ACCUMULATOR "%s\n" "$PR_COMMENT_BODY_ACCUMULATOR"
136+
echo "" # Newline in action logs for separation
146137
done # End of for PR_COMMIT_SHA loop
147138
148139
# Set the output variable `PR_COMMENT_BODY` using EOF to preserve newlines for the PR comment.
140+
# If no relevant messages were accumulated, this will be an empty string (after trim in JS).
149141
echo "PR_COMMENT_BODY<<EOF" >> "$GITHUB_OUTPUT"
150142
echo "$PR_COMMENT_BODY_ACCUMULATOR" >> "$GITHUB_OUTPUT"
151143
echo "EOF" >> "$GITHUB_OUTPUT"
@@ -158,11 +150,18 @@ jobs:
158150
COMMENT_BODY: ${{ steps.check_results.outputs.PR_COMMENT_BODY }}
159151
with:
160152
script: |
161-
// Access the comment body directly from the environment variable
162-
const commentBody = process.env.COMMENT_BODY;
163-
await github.rest.issues.createComment({
164-
issue_number: context.issue.number,
165-
owner: context.repo.owner,
166-
repo: context.repo.repo,
167-
body: commentBody
168-
});
153+
// Access the comment body directly from the environment variable and trim any whitespace
154+
const commentBody = process.env.COMMENT_BODY.trim();
155+
156+
// Only post a comment if there is actual content
157+
if (commentBody) {
158+
await github.rest.issues.createComment({
159+
issue_number: context.issue.number,
160+
owner: context.repo.owner,
161+
repo: context.repo.repo,
162+
body: commentBody
163+
});
164+
console.log("Posted a PR comment with the results.");
165+
} else {
166+
console.log("No relevant upstream fixes information to post as a PR comment.");
167+
}

0 commit comments

Comments
 (0)