Files
gentoo-zh/scripts/emerge-targets.sh
Zakk ab536be951 .github: keep tokens out of builds and sanitize bot comments
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>
2026-11-18 01:11:14 +11:00

88 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# usage: emerge-targets.sh PR
set -euo pipefail
pr=${1:?PR number}
files=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$pr/files" \
--jq '.[] | [.filename, .additions, .deletions] | @tsv')
ignore_list=(
.agents .gitignore AGENTS.md AUTHORS COPYING MIGRATION.md
README.md README.en.md README.zh-TW.md README.yue.md
repo.xml skel.ChangeLog skel.metadata.xml .github
eclass licenses metadata profiles scripts
)
packages=()
while IFS=$'\t' read -r file additions deletions; do
[ -n "$file" ] || continue
ignored=false
for prefix in "${ignore_list[@]}"; do
if [[ "$file" == "$prefix"* ]]; then
ignored=true
break
fi
done
"$ignored" && continue
IFS=/ read -r category package filename <<< "$file"
[ -n "$filename" ] || continue
package="$category/$package"
if (( additions == 0 && deletions > 0 )); then
[ -d "$package" ] || continue
if [[ "$file" == *.ebuild && ! -f "$file" ]]; then
continue
fi
fi
if [[ "$file" == *.ebuild ]]; then
packages+=("=$category/${filename%.ebuild}")
else
packages+=("$package")
fi
done <<< "$files"
atoms=$(
for atom in "${packages[@]}"; do
if [[ "$atom" != =* ]]; then
versioned=false
for candidate in "${packages[@]}"; do
if [[ "$candidate" == "=$atom-"[0-9]* ]]; then
versioned=true
break
fi
done
"$versioned" && continue
fi
printf '%s\n' "$atom"
done | sort -u
)
{
arm64_packages=()
while IFS= read -r atom; do
[ -n "$atom" ] || continue
printf '%s\t%s\t%s\n' "$atom" amd64-desktop-openrc ubuntu-latest
printf '%s\t%s\t%s\n' "$atom" amd64-desktop-systemd ubuntu-latest
if [[ "$atom" == =* ]]; then
category=${atom#=}
category=${category%%/*}
filename=${atom##*/}
ebuilds=("$category"/*/"$filename.ebuild")
else
ebuilds=("$atom"/*.ebuild)
fi
for ebuild in "${ebuilds[@]}"; do
[ -f "$ebuild" ] || continue
keywords=$(sed -n 's/^KEYWORDS="\(.*\)"/\1/p' "$ebuild")
for keyword in $keywords; do
if [[ "$keyword" == arm64 || "$keyword" == "~arm64" ]]; then
arm64_packages+=("$atom")
break 2
fi
done
done
done <<< "$atoms"
for atom in "${arm64_packages[@]}"; do
printf '%s\t%s\t%s\n' "$atom" arm64-desktop-systemd ubuntu-24.04-arm
done
} | jq -R 'split("\t") | {package: .[0], profile: .[1], runner: .[2]}' | jq -sc .