The autobump engine opens pull requests with gh and git push, so its
environment must keep GH_TOKEN. Portage passes that environment into
every ebuild phase, which builds unreviewed upstream releases, so both
autobump workflows add the token variables to ENV_UNSET in make.conf.
ENV_UNSET is incremental and needs EAPI 7, which every overlay ebuild
already uses.
The nvchecker job exports a personal access token right after its pip
install, so an unpinned release of any dependency could read it. The
job now installs exact versions with hashes for the runner's Python
3.12. Regenerate .github/nvchecker-requirements.txt with:
printf '%s\n' nvchecker==2.22 jq==1.13.0 portage==3.0.83 |
uv pip compile - --generate-hashes --python-version 3.12 \
--no-header --no-annotate
A pull request's own run writes findings.json and the elog artifacts,
so a line starting with a backtick run could close the code fence and
post markdown under github-actions[bot]. Backticks in that text now
become quotes. The commit subject in the pull request rules comment is
not fenced at all, so it now goes into a code span with its backticks
and control characters replaced.
emerge-targets.sh turned a new top-level file such as SECURITY.md into
the atom SECURITY.md/, which failed emerge-on-pr, so paths without
category/package/file are skipped.
Signed-off-by: Zakk <zakk@gentoozh.org>
119 lines
3.9 KiB
Bash
Executable File
119 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# usage: pkgcheck-comment.sh <report-directory>
|
|
set -euo pipefail
|
|
MARKER='<!-- pkgcheck-report -->'
|
|
MAX_LINES=30
|
|
report_dir=${1:?report-directory}
|
|
findings=$report_dir/findings.json
|
|
body_file=$(mktemp)
|
|
trap 'rm -f "$body_file"' EXIT
|
|
|
|
pr=$(scripts/pr-at-commit.sh "$GITHUB_REPOSITORY" "$HEAD_SHA")
|
|
if [ -z "$pr" ]; then
|
|
echo 'no open pull request at this commit'
|
|
exit 0
|
|
fi
|
|
echo "pull request #${pr}"
|
|
|
|
if [ ! -f "$findings" ]; then
|
|
echo 'the report predates findings.json'
|
|
exit 0
|
|
fi
|
|
|
|
# atom: stdin cut to 200 atom characters. The pull request's run wrote the report, so
|
|
# the commit and package names go through it.
|
|
atom() {
|
|
head -c 200 | tr -cd '[:alnum:]/._+=~@:-'
|
|
}
|
|
|
|
# list <new> <level>...: one line per finding, existing ones prefixed with their level
|
|
# and control characters turned into spaces and backticks into quotes, so a finding
|
|
# cannot leave its code block
|
|
list() {
|
|
jq -r --argjson new "$1" '
|
|
.[] | select(.new == $new and (.level | IN($ARGS.positional[])))
|
|
| (if $new then "" else "\(.level): " end) + "\(.target): \(.keyword): \(.desc)"
|
|
| gsub("[[:cntrl:]]"; " ") | gsub("`"; "\u0027") | .[:300]
|
|
' "$findings" --args "${@:2}"
|
|
}
|
|
|
|
# block <title> <collapsed> <lines>
|
|
block() {
|
|
local title=$1 collapsed=$2 lines=$3 n
|
|
n=$(grep -c . <<< "$lines" || true)
|
|
[ "$n" -gt 0 ] || return 0
|
|
echo
|
|
if [ "$collapsed" = yes ]; then
|
|
echo "<details><summary>${title} (${n})</summary>"
|
|
else
|
|
echo "### ${title} (${n})"
|
|
fi
|
|
echo
|
|
echo '``````'
|
|
head -n "$MAX_LINES" <<< "$lines"
|
|
echo '``````'
|
|
if [ "$n" -gt "$MAX_LINES" ]; then
|
|
echo
|
|
echo "$(( n - MAX_LINES )) more in the [run log](${RUN_URL})."
|
|
fi
|
|
if [ "$collapsed" = yes ]; then
|
|
echo
|
|
echo '</details>'
|
|
fi
|
|
}
|
|
|
|
count=$(wc -l < "$report_dir"/packages)
|
|
if [ "$count" -eq 0 ]; then
|
|
{
|
|
echo '## Pull request pkgcheck report'
|
|
echo
|
|
echo "*Newest commit scanned*: \`$(atom < "$report_dir"/commit)\`"
|
|
echo '*Status*: :white_check_mark: no packages touched'
|
|
} > "$body_file"
|
|
scripts/upsert-comment-section.sh "$GITHUB_REPOSITORY" "$pr" "$MARKER" pkgcheck "$body_file"
|
|
# emerge-on-pr skips a pull request that only touches .github, so drop its report here
|
|
: > "$body_file"
|
|
scripts/upsert-comment-section.sh "$GITHUB_REPOSITORY" "$pr" "$MARKER" elog "$body_file"
|
|
echo 'no packages touched'
|
|
exit 0
|
|
fi
|
|
errors=$(list true error)
|
|
warnings=$(list true warning)
|
|
minor=$(list true style info)
|
|
|
|
{
|
|
echo '## Pull request pkgcheck report'
|
|
echo
|
|
echo "*Newest commit scanned*: \`$(atom < "$report_dir"/commit)\`"
|
|
if [ "${count}" -le 10 ]; then
|
|
packages=()
|
|
while IFS= read -r package; do
|
|
packages+=("\`$(atom <<< "$package")\`")
|
|
done < "$report_dir/packages"
|
|
echo "*Packages scanned*: ${packages[*]}"
|
|
else
|
|
echo "*Packages scanned*: ${count}"
|
|
fi
|
|
if [ -f "$report_dir"/incomplete ]; then
|
|
echo "*Status*: :x: the scan did not finish, see the [run](${RUN_URL})"
|
|
elif [ -z "$errors$warnings$minor" ]; then
|
|
echo '*Status*: :white_check_mark: no new findings'
|
|
block 'Existing findings in these packages' yes "$(list false error warning style info)"
|
|
else
|
|
if [ -n "$errors" ]; then
|
|
echo '*Status*: :x: **new errors**'
|
|
else
|
|
echo '*Status*: :warning: **new issues**'
|
|
fi
|
|
echo
|
|
echo "This pull request adds these findings. Errors fail the \`report\` check."
|
|
block 'New errors' no "$errors"
|
|
block 'New warnings' no "$warnings"
|
|
block 'New style and info findings' yes "$minor"
|
|
block 'Existing findings in these packages' yes "$(list false error warning style info)"
|
|
fi
|
|
} > "$body_file"
|
|
|
|
scripts/upsert-comment-section.sh "$GITHUB_REPOSITORY" "$pr" "$MARKER" pkgcheck "$body_file"
|
|
echo "commented on #${pr}"
|