Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .github/workflows/decision-model-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,33 @@ jobs:
printf 'The linter did not finish (exit %s), and the `%s` label passes the check anyway; see the job log.\n' "$status" "$LABEL" >> "$report"
fi

cat "$report" >> "$GITHUB_STEP_SUMMARY"

marker='<!-- decision-model-linter -->'
comment=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id" | head -n 1)
body=
# gh reads the body from a file, because Linux limits one argument to 128 KiB.
body="$RUNNER_TEMP/decision-model-lint-comment.md"
if [ -s "$report" ] && { [ "$status" -le 1 ] || [ "$OVERRIDDEN" = true ]; }; then
body=$(printf '%s\n%s' "$marker" "$(cat "$report")")
printf '%s\n' "$marker" > "$body"
# GitHub rejects comments over 65536 characters, and bytes never undercount characters.
if [ "$(wc -c < "$report")" -gt 60000 ]; then
# Drop the line that the cut can split. Keep the last line: the note above, or the usage.
head -c 60000 "$report" | sed '$d' >> "$body"
printf '\nThe report is too long for a comment. The [job summary](%s) has the full report.\n\n' \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> "$body"
tail -n 1 "$report" >> "$body"
else
cat "$report" >> "$body"
fi
elif [ "$status" -eq 0 ] && [ -n "$comment" ]; then
body=$(printf '%s\nNo findings on the latest commit.' "$marker")
printf '%s\nNo findings on the latest commit.\n' "$marker" > "$body"
fi
if [ -n "$body" ] && [ -n "$comment" ]; then
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment" -f body="$body" > /dev/null
elif [ -n "$body" ]; then
gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -f body="$body" > /dev/null
if [ -s "$body" ] && [ -n "$comment" ]; then
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment" -F body=@"$body" > /dev/null
elif [ -s "$body" ]; then
gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$body" > /dev/null
fi
cat "$report" >> "$GITHUB_STEP_SUMMARY"

if [ "$status" -ne 0 ] && [ "$OVERRIDDEN" = true ]; then exit 0; fi
exit "$status"
Loading