Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion .github/workflows/publish-apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,8 @@ jobs:
env:
TOKEN: ${{ steps.token.outputs.token }}
run: |
# The checkout path is passed explicitly: the script cannot infer it
# from its own location, which resolves to this source repository.
./scripts/publish-log-release.sh \
"$LOG_REPO" "${{ steps.stage.outputs.run_dir }}" "$TOKEN"
"$LOG_REPO" "${{ steps.stage.outputs.run_dir }}" \
"$RUNNER_TEMP/logrepo" "$TOKEN"
35 changes: 32 additions & 3 deletions .github/workflows/script-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,39 @@ jobs:
! APP_KEY=x ./scripts/github-app-token.sh 6008281 not-a-number 2>/dev/null

- name: Test the release script guards
# The checkout is an explicit argument. Inferring it from the script's own
# location resolved to the ZGS source repository in CI, so the run
# directory was never found and no release was ever published.
run: |
! ./scripts/publish-log-release.sh 'bad/slug/here' 2026-12-01-1 tok 2>/dev/null
! ./scripts/publish-log-release.sh owner/repo not-a-run-dir tok 2>/dev/null
! ./scripts/publish-log-release.sh owner/repo 2026-12-01-1 '' 2>/dev/null
! ./scripts/publish-log-release.sh 'bad/slug/here' 2026-12-01-1 /tmp tok 2>/dev/null
! ./scripts/publish-log-release.sh owner/repo not-a-run-dir /tmp tok 2>/dev/null
! ./scripts/publish-log-release.sh owner/repo 2026-12-01-1 /tmp '' 2>/dev/null
! ./scripts/publish-log-release.sh owner/repo 2026-12-01-1 /nonexistent-checkout tok 2>/dev/null

- name: Test the /log/ index does not clobber per-run indexes
# stage-log-index.sh used to generate an "empty directory" index inside
# every run directory and sync it over the real one, so published runs
# listed as "This directory is empty" while their files were present.
run: |
tmp="$(mktemp -d)"

# Build a tree the way publish-repo.sh does, with a real per-run index.
mkdir -p "$tmp/repo/log/2026-12-01-46655100700"
printf 'log line\n' > "$tmp/repo/log/2026-12-01-46655100700/pkg.log"
./scripts/generate-index.sh "$tmp/repo" test
grep -q 'pkg.log' "$tmp/repo/log/2026-12-01-46655100700/index.html"

# Rebuilding the /log/ index must emit only the top-level index.html.
./scripts/stage-log-index.sh "$tmp/logindex" 2026-12-01-46655100700
test -f "$tmp/logindex/index.html"
test ! -e "$tmp/logindex/2026-12-01-46655100700/index.html"
! grep -q 'This directory is empty' "$tmp/logindex/index.html"

# After applying it, the per-run index must still list its files.
cp -r "$tmp/logindex/." "$tmp/repo/log/"
grep -q 'pkg.log' "$tmp/repo/log/2026-12-01-46655100700/index.html"
! grep -q 'This directory is empty' \
"$tmp/repo/log/2026-12-01-46655100700/index.html"

- name: Test build-deb.sh exit statuses
# A cleanup trap that ends on a failing test used to turn successful
Expand Down
2 changes: 2 additions & 0 deletions README-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/zitzhen-patchsplit.log
`dists/`、`pool/` 一起出现在 <https://apt-general.zitzhen.cn> 的根目录列表里。
- `/log/` 的列表页按 bucket 中实际存在的运行目录重建,因此历史运行同样可以浏览。
重建使用带 delimiter 的 `list-objects-v2`,即使运行次数很多,开销依然很小。
重建只产出这一个 `index.html`:各运行目录的索引由 `publish-repo.sh` 生成,
重建列表时绝不能覆盖它们。
- 同步**不使用** `--delete`,所以归档新日志不会删除旧日志;清理需要手动决定。
- 日志是公开内容,并以 `Cache-Control: no-cache` 提供。切勿让构建把密钥、令牌等
敏感信息打进日志——工作流只会发布构建自己写出的内容。
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/zitzhen-patchsplit.log
- The `/log/` listing is rebuilt from the run directories that actually exist in
the bucket, so older runs stay browsable. It is done with a delimiter-based
`list-objects-v2`, which keeps the listing cheap however many runs accumulate.
Only that one `index.html` is regenerated: the per-run indexes come from
`publish-repo.sh`, and rebuilding the listing must never overwrite them.
- Nothing is deleted from `/log/`: the sync runs without `--delete`, so
archiving a new run never removes an old one. Pruning is a manual decision.
- Logs are public and served with `Cache-Control: no-cache`. Never let a build
Expand Down
20 changes: 14 additions & 6 deletions scripts/publish-log-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
# workflow does not error out.
set -euo pipefail

if [[ $# -ne 3 ]]; then
echo "Usage: publish-log-release.sh <log-repo> <run-dir> <token>" >&2
if [[ $# -ne 4 ]]; then
echo "Usage: publish-log-release.sh <log-repo> <run-dir> <checkout> <token>" >&2
echo " log-repo owner/name of the log repository" >&2
echo " run-dir the archived run directory, e.g. 2026-12-01-46640252167" >&2
echo " checkout path to the checked-out log repository holding run-dir" >&2
echo " token GitHub App installation token" >&2
exit 1
fi

repo="$1"
run_dir="$2"
token="$3"
checkout="$3"
token="$4"

if [[ ! "$repo" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]]; then
echo "Error: invalid repository slug: $repo" >&2
Expand All @@ -32,9 +34,15 @@ if [[ -z "$token" ]]; then
exit 1
fi

script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
repo_dir="$(git -C "$script_dir" rev-parse --show-toplevel)"
run_path="$repo_dir/$run_dir"
# The checkout is passed in explicitly. Deriving it from this script's own
# location used to resolve to the ZGS source repository in CI, not to the log
# repository clone, so the run directory was never found and no release was made.
if [[ ! -d "$checkout" ]]; then
echo "Error: log repository checkout not found: $checkout" >&2
exit 1
fi

run_path="$checkout/$run_dir"

if [[ ! -d "$run_path" ]]; then
echo "Error: run directory not found: $run_path" >&2
Expand Down
46 changes: 30 additions & 16 deletions scripts/stage-log-index.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/usr/bin/env bash
# Build an index.html for /log/ that lists every run directory, including runs
# from previous publishes.
# Build the index.html for /log/ itself, listing every run directory, including
# runs from previous publishes.
#
# publish-repo.sh generates its indexes from the staged tree, which only holds the
# current run. Now that each run is archived under its own directory, that index
# would hide every older run even though their files are still in the bucket, so
# the /log/ listing is rebuilt from the directory names that actually exist.
#
# Only the top-level index.html is emitted. generate-index.sh walks a tree
# recursively, so running it directly over a tree of empty <run-dir> directories
# also produced an "empty directory" index inside each one; syncing that tree
# overwrote the real per-run index.html that publish-repo.sh had generated, and
# every run directory listed as "This directory is empty" even though its log
# files were present.
set -euo pipefail

if [[ $# -lt 1 ]]; then
Expand All @@ -22,28 +29,35 @@ script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
rm -rf "$output_dir"
mkdir -p "$output_dir"

if (( $# == 0 )); then
echo "Warning: no run directories supplied; writing an empty /log/ index" >&2
"$script_dir/generate-index.sh" "$output_dir" \
"ZGS · Build logs · Generated $(date -u '+%Y-%m-%d %H:%M UTC')"
exit 0
fi
# Build the listing in a scratch tree of empty directories, then keep only the
# index generated for its root.
scratch_dir="$(mktemp -d)"
trap 'rm -rf "$scratch_dir"' EXIT

valid_count=0
for run_dir in "$@"; do
if [[ ! "$run_dir" =~ ^[A-Za-z0-9._-]+$ || "$run_dir" == "." || "$run_dir" == ".." ]]; then
[[ -z "$run_dir" ]] && continue
if [[ ! "$run_dir" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]+$ ]]; then
echo "Warning: skipping unusable run directory name: $run_dir" >&2
continue
fi
mkdir -p "$output_dir/$run_dir"
# Name starts with the run date; use it for the listing timestamp so an old run
# does not appear to have been published just now.
mkdir -p "$scratch_dir/$run_dir"
# The name starts with the run date; use it for the listing timestamp so an old
# run does not appear to have been published just now.
if [[ "$run_dir" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})- ]]; then
touch -d "${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]} 00:00:00 UTC" \
"$output_dir/$run_dir" 2>/dev/null || true
"$scratch_dir/$run_dir" 2>/dev/null || true
fi
valid_count=$((valid_count + 1))
done

"$script_dir/generate-index.sh" "$output_dir" \
"ZGS · Build logs · Generated $(date -u '+%Y-%m-%d %H:%M UTC')"
if (( valid_count == 0 )); then
echo "Warning: no usable run directories supplied; writing an empty /log/ index" >&2
fi

"$script_dir/generate-index.sh" "$scratch_dir" \
"ZGS · Build logs · Generated $(date -u '+%Y-%m-%d %H:%M UTC')" >/dev/null

cp "$scratch_dir/index.html" "$output_dir/index.html"

echo "Generated a /log/ index covering $(($#)) run director(y|ies)" >&2
echo "Generated the /log/ index covering $valid_count run director(ies)" >&2
Loading