.github: record the build environment in the emerge elog comment
The stage3 tag, the Gentoo tree and the binhost move on every day, and a run's logs and artifacts expire, so a failed pull request run could not be reproduced later. The comment now keeps the image, the tree commit, the packages the job merged and emerge --info, and the dated stage3 tag keeps the image itself for a week. Co-authored-by: Yongxiang Liang <tanekliang@gmail.com> Signed-off-by: Zakk <zakk@gentoozh.org>
This commit is contained in:
1 parent
daa712acd6
commit
36e9c08555
4 files changed
+87
-8
No files matched your search
@@ -1,11 +1,15 @@
|
||||
ARG PROFILE
|
||||
FROM gentoo/stage3:${PROFILE} AS update
|
||||
ARG PROFILE IMAGE BASE RUN
|
||||
|
||||
# stage3 has no world file: @world covers only @system, and depclean would drop the rest
|
||||
RUN emerge-webrsync --no-pgp-verify \
|
||||
&& getuto \
|
||||
&& FEATURES="getbinpkg" emerge --quiet --update --deep --newuse --with-bdeps=y @installed \
|
||||
&& FEATURES="getbinpkg" emerge --quiet @preserved-rebuild \
|
||||
&& printf 'image: %s\nbase: gentoo/stage3:%s@%s\nimage gentoo: %s\nimage run: %s\n' \
|
||||
"$IMAGE" "$PROFILE" "$BASE" "$(cat /var/db/repos/gentoo/metadata/timestamp.commit)" "$RUN" \
|
||||
> /etc/gentoo-zh-ci-image \
|
||||
&& rm -rf /var/db/repos/gentoo /var/cache/distfiles/* /var/cache/binpkgs/*
|
||||
|
||||
# one layer, as gentoo/stage3 itself is built: the update layer would duplicate every replaced file
|
||||
|
||||
@@ -37,7 +37,16 @@ jobs:
|
||||
id: image
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
run: echo "ref=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/stage3:$PROFILE" >> "$GITHUB_OUTPUT"
|
||||
# a dated tag keeps the image a pull request ran on after the profile tag moves
|
||||
run: |
|
||||
ref=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/stage3:$PROFILE
|
||||
dated=$ref-$(date -u +%Y%m%d)
|
||||
base=$(docker buildx imagetools inspect "gentoo/stage3:$PROFILE" --format '{{.Manifest.Digest}}') || base=unknown
|
||||
{
|
||||
echo "tags=$ref,$dated"
|
||||
echo "dated=$dated"
|
||||
echo "base=$base"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: log in to ghcr
|
||||
uses: docker/login-action@v4
|
||||
@@ -50,12 +59,16 @@ jobs:
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .github/stage3
|
||||
build-args: PROFILE=${{ matrix.profile }}
|
||||
build-args: |
|
||||
PROFILE=${{ matrix.profile }}
|
||||
IMAGE=${{ steps.image.outputs.dated }}
|
||||
BASE=${{ steps.image.outputs.base }}
|
||||
RUN=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
push: true
|
||||
no-cache: true
|
||||
# attestation manifests are untagged and the cleanup would delete them
|
||||
provenance: false
|
||||
tags: ${{ steps.image.outputs.ref }}
|
||||
tags: ${{ steps.image.outputs.tags }}
|
||||
|
||||
cleanup:
|
||||
needs: build
|
||||
@@ -70,3 +83,14 @@ jobs:
|
||||
package-type: container
|
||||
delete-only-untagged-versions: true
|
||||
min-versions-to-keep: 0
|
||||
|
||||
# a week of dated images, one per profile a day; only after every profile built, so
|
||||
# the newest image of each profile is among those kept
|
||||
- name: drop superseded images
|
||||
if: needs.build.result == 'success'
|
||||
uses: actions/delete-package-versions@v5
|
||||
with:
|
||||
owner: ${{ github.repository_owner }}
|
||||
package-name: stage3
|
||||
package-type: container
|
||||
min-versions-to-keep: 21
|
||||
@@ -4,6 +4,7 @@
|
||||
set -euo pipefail
|
||||
MARKER='<!-- pkgcheck-report -->'
|
||||
MAX_LINES=40
|
||||
MAX_ENVIRONMENT_LINES=300
|
||||
MAX_BYTES=40000
|
||||
MAX_TABLE=20000
|
||||
artifacts_dir=${1:?artifacts-directory}
|
||||
@@ -74,7 +75,7 @@ summary() {
|
||||
# add_detail <atom> <profile> <title> <file> [<build-log-url>]: a collapsed block, shared
|
||||
# by the profiles that printed the same text. The block's key is left in detail_key.
|
||||
keys=()
|
||||
declare -A detail_atom detail_title detail_text detail_profiles detail_links detail_unlinked detail_all detail_action detail_footer atom_profiles
|
||||
declare -A detail_atom detail_title detail_text detail_profiles detail_links detail_unlinked detail_all detail_action detail_footer detail_lines atom_profiles
|
||||
add_detail() {
|
||||
local text key
|
||||
text=$(sed 's/\x1b\[[0-9;]*m//g' "$4")
|
||||
@@ -355,6 +356,13 @@ fix_summary() {
|
||||
done
|
||||
fi
|
||||
} > "$body_file"
|
||||
# the environment of every target follows its elog, so the size limit drops it first
|
||||
for dir in "${targets[@]}"; do
|
||||
[ -s "$dir/environment" ] || continue
|
||||
atom=$(field "$dir" atom)
|
||||
add_detail "${atom#=}" "$(field "$dir" profile)" environment "$dir/environment"
|
||||
detail_lines[$detail_key]=$MAX_ENVIRONMENT_LINES
|
||||
done
|
||||
# a package's LDFLAGS block follows its other blocks, which later profiles can add
|
||||
ordered=()
|
||||
pending=
|
||||
@@ -385,6 +393,7 @@ for key in "${ordered[@]}"; do
|
||||
[ -z "$links" ] || title+=", build.log: ${links}"
|
||||
[ -z "${detail_action[$key]:-}" ] || title=":warning: ${title}"
|
||||
lines=$(wc -l <<< "$text")
|
||||
max=${detail_lines[$key]:-$MAX_LINES}
|
||||
detail=$(
|
||||
echo
|
||||
echo "<details><summary>${title}</summary>"
|
||||
@@ -394,11 +403,11 @@ for key in "${ordered[@]}"; do
|
||||
echo
|
||||
fi
|
||||
echo '``````'
|
||||
head -n "$MAX_LINES" <<< "$text"
|
||||
head -n "$max" <<< "$text"
|
||||
echo '``````'
|
||||
if [ "$lines" -gt "$MAX_LINES" ]; then
|
||||
if [ "$lines" -gt "$max" ]; then
|
||||
echo
|
||||
echo "$(( lines - MAX_LINES )) more lines in the [run](${RUN_URL})."
|
||||
echo "$(( lines - max )) more lines in the [run](${RUN_URL})."
|
||||
fi
|
||||
if [ -n "${detail_footer[$key]:-}" ]; then
|
||||
echo
|
||||
|
||||
@@ -66,10 +66,50 @@ elog() {
|
||||
'
|
||||
}
|
||||
|
||||
# snapshot: the package.* configuration before the first emerge, for autounmask
|
||||
# installed: the category/pf of every installed package
|
||||
installed() (
|
||||
cd /var/db/pkg
|
||||
printf '%s\n' */* | sort
|
||||
)
|
||||
|
||||
# snapshot: the package.* configuration and the installed packages before the first
|
||||
# emerge, for autounmask and the environment
|
||||
snapshot() {
|
||||
mkdir -p "$BEFORE"
|
||||
cp -a /etc/portage/package.* "$BEFORE/"
|
||||
installed > "$BEFORE/installed"
|
||||
date +%s > "$BEFORE/start"
|
||||
}
|
||||
|
||||
# environment <atom>: what a rerun needs once the image tag, the Gentoo tree and the
|
||||
# binhost have moved on: the image, the tree commit, the packages this job merged and
|
||||
# emerge --info. The pull request comment keeps it after the run expires.
|
||||
environment() {
|
||||
local cpv dir start flag iuse use flags how
|
||||
cat /etc/gentoo-zh-ci-image 2>/dev/null || echo 'image: built before /etc/gentoo-zh-ci-image was recorded'
|
||||
echo "gentoo: $(cat "$(portageq get_repo_path / gentoo)/metadata/timestamp.commit")"
|
||||
echo
|
||||
echo 'target:'
|
||||
emerge --pretend --verbose --nodeps --oneshot "$1" 2>&1 | grep -E '^\[(ebuild|binary)'
|
||||
echo
|
||||
# a package built before the job started came from a binhost
|
||||
echo 'merged by this job:'
|
||||
start=$(cat "$BEFORE/start")
|
||||
comm -13 "$BEFORE/installed" <(installed) | while read -r cpv; do
|
||||
dir=/var/db/pkg/$cpv
|
||||
how=binary
|
||||
[ "$(cat "$dir/BUILD_TIME")" -lt "$start" ] || how=source
|
||||
read -ra iuse < "$dir/IUSE" || true
|
||||
use=" $(cat "$dir/USE") "
|
||||
flags=()
|
||||
for flag in "${iuse[@]}"; do
|
||||
flag=${flag#[+-]}
|
||||
[[ $use != *" $flag "* ]] || flags+=("$flag")
|
||||
done
|
||||
echo "$cpv $how USE=\"${flags[*]}\""
|
||||
done
|
||||
echo
|
||||
emerge --info
|
||||
}
|
||||
|
||||
# save <atom>: the step outcomes from SETUP, DEPS, OUTCOME and UNMERGE, the output
|
||||
@@ -85,6 +125,8 @@ save() {
|
||||
echo "$DEPS" > "$REPORT/deps"
|
||||
echo "$OUTCOME" > "$REPORT/outcome"
|
||||
echo "$UNMERGE" > "$REPORT/unmerge"
|
||||
# a missing record leaves a gap in the text and never fails the job
|
||||
environment "$atom" > "$REPORT/environment" 2>&1 || true
|
||||
log=
|
||||
[ "$DEPS" != failure ] || log=/var/tmp/deps.log
|
||||
[ "$OUTCOME" != failure ] || log=/var/tmp/emerge.log
|
||||
|
||||
Reference in new issue
Block a user