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
73 changes: 68 additions & 5 deletions .github/workflows/publish-apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,62 @@ jobs:
# Must run before publish-repo.sh, which generates every index.html at the
# end by walking the staged tree. Staging the logs afterwards (as a
# separate job did) leaves log/ absent from the root listing.
#
# Each run gets its own /log/<date>-<run-id>/ directory so previous runs
# are kept instead of being overwritten by the next publish.
id: stage
run: |
mkdir -p "$RUNNER_TEMP/repo"
./scripts/collect-logs.sh "$RUNNER_TEMP/logs" "$RUNNER_TEMP/repo"
# github.run_started_at is an ISO-8601 UTC timestamp for every trigger.
run_dir="$(./scripts/log-run-dir.sh "${{ github.run_started_at }}" "${{ github.run_id }}")"
echo "Build log directory: /log/$run_dir/"
./scripts/collect-logs.sh "$RUNNER_TEMP/logs" "$RUNNER_TEMP/repo" "$run_dir"
echo "run_dir=$run_dir" >> "$GITHUB_OUTPUT"

- name: Generate and sign repository metadata
env:
APT_GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
run: ./scripts/publish-repo.sh "$RUNNER_TEMP/packages" "$RUNNER_TEMP/repo" "$APT_GPG_KEY_ID"

- name: Collect the run directories already in the bucket
# Each run archives into /log/<date>-<run-id>/. The staged tree only knows
# about the current run, so the existing run directories are listed from
# R2 and passed on, otherwise /log/ would only ever list the newest run.
id: runs
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_REGION: auto
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
R2_BUCKET: ${{ secrets.R2_BUCKET }}
run: |
: "${AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID is required}"
: "${AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY is required}"
: "${R2_ACCOUNT_ID:?R2_ACCOUNT_ID is required}"
: "${R2_BUCKET:?R2_BUCKET is required}"
endpoint="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"

# Delimiter-based listing returns the run directories, not every log
# object, so the list stays small however many logs accumulate.
mapfile -t existing < <(
aws s3api list-objects-v2 \
--bucket "$R2_BUCKET" --prefix 'log/' --delimiter '/' \
--endpoint-url "$endpoint" --region auto \
--query 'CommonPrefixes[].Prefix' --output text 2>/dev/null \
| tr '\t' '\n' | sed -n 's|^log/\([^/]*\)/$|\1|p' | grep -v '^$' || true
)

run_dir="${{ steps.stage.outputs.run_dir }}"
printf '%s\n' "current=$run_dir" >&2
printf ' existing: %s\n' "${existing[*]:-none}" >&2

# Union of what is already published and this run, deduplicated.
printf '%s\n' "${existing[@]}" "$run_dir" \
| grep -v '^$' | sort -u > "$RUNNER_TEMP/run-dirs.txt"
echo "run_dirs<<EOF" >> "$GITHUB_OUTPUT"
cat "$RUNNER_TEMP/run-dirs.txt" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: Sync the repository to Cloudflare R2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
Expand All @@ -152,7 +199,7 @@ jobs:
# served as application/octet-stream and download instead of render.
aws s3 sync "$RUNNER_TEMP/repo" "s3://${R2_BUCKET}" \
--endpoint-url "$endpoint" --region auto --no-progress \
--exclude '*index.html' --exclude 'log/*.log'
--exclude '*index.html' --exclude 'log/**'

# Upload the generated directory indexes separately so they get an
# explicit MIME type; browsers then render them instead of downloading
Expand All @@ -164,10 +211,26 @@ jobs:
--cache-control 'no-cache, max-age=60'

# Build logs, plain text, uncached so a re-publish shows up immediately.
aws s3 sync "$RUNNER_TEMP/repo" "s3://${R2_BUCKET}" \
# The source root is log/ itself rather than a repo-wide include: a
# repo-wide 'log/**' include would also match log/<run>/index.html and
# overwrite the text/html type the pass above just set. No --delete, so
# the directories of previous runs are kept.
if [[ -d "$RUNNER_TEMP/repo/log" ]]; then
aws s3 sync "$RUNNER_TEMP/repo/log" "s3://${R2_BUCKET}/log" \
--endpoint-url "$endpoint" --region auto --no-progress \
--exclude '*index.html' \
--content-type 'text/plain; charset=utf-8' \
--cache-control 'no-cache, max-age=60'
fi

# Rebuild /log/index.html from every run directory in the bucket, so the
# listing points at archive directories instead of the current run's
# files and keeps every older run visible.
readarray -t run_dirs <<< "${{ steps.runs.outputs.run_dirs }}"
./scripts/stage-log-index.sh "$RUNNER_TEMP/logindex" "${run_dirs[@]}"
aws s3 sync "$RUNNER_TEMP/logindex" "s3://${R2_BUCKET}/log" \
--endpoint-url "$endpoint" --region auto --no-progress \
--exclude '*' --include 'log/*.log' \
--content-type 'text/plain; charset=utf-8' \
--content-type 'text/html; charset=utf-8' \
--cache-control 'no-cache, max-age=60'

echo "Repository published to $APT_REPO_URL"
35 changes: 35 additions & 0 deletions .github/workflows/script-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@ jobs:
! ./scripts/log-file-name.sh https://example.com/a/b 2>/dev/null
! ./scripts/log-file-name.sh https://github.com/onlyowner 2>/dev/null

- name: Test the run directory derivation
run: |
test "$(./scripts/log-run-dir.sh 2026-12-01T11:50:08Z 46640252167)" = \
"2026-12-01-46640252167"
test "$(./scripts/log-run-dir.sh 2026-12-01T11:50:08+08:00 42)" = \
"2026-12-01-42"
! ./scripts/log-run-dir.sh not-a-date 42 2>/dev/null
# The run id becomes a path component, so anything but digits is out.
! ./scripts/log-run-dir.sh 2026-12-01T11:50:08Z ../../etc 2>/dev/null

- name: Test the archived log layout
# Logs must land in log/<date>-<run-id>/, be listed from /log/ and stay
# reachable, and older run directories must remain in the /log/ index.
run: |
tmp="$(mktemp -d)"
mkdir -p "$tmp/logs" "$tmp/repo"
printf 'run a\n' > "$tmp/logs/zitzhen-patchsplit.log"

./scripts/collect-logs.sh "$tmp/logs" "$tmp/repo" 2026-12-01-46640252167
test -f "$tmp/repo/log/2026-12-01-46640252167/zitzhen-patchsplit.log"
# A malformed run directory must be rejected, not nested somewhere else.
! ./scripts/collect-logs.sh "$tmp/logs" "$tmp/repo" ../escape 2>/dev/null
! ./scripts/collect-logs.sh "$tmp/logs" "$tmp/repo" "" 2>/dev/null

./scripts/generate-index.sh "$tmp/repo" "test"
grep -q 'href="log/"' "$tmp/repo/index.html"
grep -q '2026-12-01-46640252167/' "$tmp/repo/log/index.html"
grep -q 'zitzhen-patchsplit.log' "$tmp/repo/log/2026-12-01-46640252167/index.html"

# The /log/ index rebuilt from the bucket must list past runs too.
./scripts/stage-log-index.sh "$tmp/logindex" \
2026-11-29-46000000000 2026-12-01-46640252167
grep -q '2026-11-29-46000000000/' "$tmp/logindex/index.html"
grep -q '2026-12-01-46640252167/' "$tmp/logindex/index.html"

- name: Test build-deb.sh exit statuses
# A cleanup trap that ends on a failing test used to turn successful
# builds into exit 1, which skipped publish on every run.
Expand Down
22 changes: 16 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,22 @@ argument, a log path, and mirrors the whole build into it:
./scripts/build-deb.sh https://github.com/zitzhen/patchsplit /tmp/debs /tmp/logs/patchsplit.log
```

The publish workflow collects those logs with `scripts/collect-logs.sh` into the
staged `/log/` directory, so they appear at
`https://apt-general.zitzhen.cn/log/<owner>-<repo>.log`. That step runs even when
a build fails, which is why the log is worth writing: it is the artifact that
explains a broken package after the Actions run has expired. Treat logs as
public content — never echo secrets, tokens, or credentials into a build.
The publish workflow collects those logs with `scripts/collect-logs.sh` into a
per-run directory, so they are published at
`https://apt-general.zitzhen.cn/log/<date>-<run-id>/<owner>-<repo>.log` (for
example `/log/2026-12-01-46640252167/zitzhen-patchsplit.log`). The directory name
comes from `scripts/log-run-dir.sh`, and each run keeps its own copy rather than
overwriting the previous one.

That step runs even when a build fails, which is why the log is worth writing: it
is the artifact that explains a broken package after the Actions run has expired.
Treat logs as public content — never echo secrets, tokens, or credentials into a
build.

`scripts/stage-log-index.sh` rebuilds the `/log/` listing from every run
directory present in the bucket, so older runs stay browsable after a new publish
adds another directory. The sync never passes `--delete`; pruning old runs is a
manual decision, so do not assume logs disappear on their own.

`scripts/publish-repo.sh` also calls `scripts/generate-index.sh`, which walks the
staged tree and writes one `index.html` per directory. It only needs Bash and the
Expand Down
29 changes: 20 additions & 9 deletions README-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ GitHub 仓库地址。手动触发的 GitHub Actions 工作流会:
(详见[构建日志](#构建日志));
7. 通过 `aws s3 sync` 把仓库同步到 Cloudflare R2 供 `apt` 拉取。其中 `index.html`
会单独上传并带上 `text/html` MIME 类型,日志带上 `text/plain`,两者都使用较短的
`max-age`,确保浏览器渲染而不是直接下载,同时目录内容保持较新。
`max-age`,确保浏览器渲染而不是直接下载,同时目录内容保持较新。构建日志按
`log/<日期>-<runID>/` 归档,不会被自动清理。

## 仓库布局

Expand All @@ -45,8 +46,10 @@ ZGS/
│ ├── diff-software-list.sh # 计算相对某个基线新增的仓库
│ ├── build-deb.sh # 从上游仓库构建 amd64 .deb
│ ├── publish-repo.sh # 组装、签名并导出 apt 元数据
│ ├── collect-logs.sh # 把构建日志收进待发布的 /log/ 目录
│ ├── collect-logs.sh # 把构建日志收进 /log/<运行目录>/
│ ├── log-file-name.sh # 由仓库 URL 推导发布用的日志文件名
│ ├── log-run-dir.sh # 推导单次运行的归档目录名
│ ├── stage-log-index.sh # 汇总所有运行目录重建 /log/ 索引
│ ├── generate-index.sh # 为仓库目录树生成可浏览的 index.html
│ └── test-workflow-build-step.sh # 在 bash 下执行 workflow 的 run 块
├── .github/workflows/ # 构建检查与发布 CI
Expand Down Expand Up @@ -100,23 +103,31 @@ sudo apt-get install -y git devscripts equivs dpkg-dev gnupg apt-utils

## 构建日志

每个包的构建过程都会完整写入日志,以纯文本形式发布在 `/log/` 下:
每次发布都会把各包的构建日志归档到独立目录,因此历史构建记录不会被覆盖:

```
https://apt-general.zitzhen.cn/log/
https://apt-general.zitzhen.cn/log/zitzhen-patchsplit.log
https://apt-general.zitzhen.cn/log/ # 所有运行
https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/ # 单次运行
https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/zitzhen-patchsplit.log
```

- 文件名规则为 `<owner>-<repo>.log`,由 `Software.list` 中的 URL 推导
- 运行目录名为 `<日期>-<runID>`(如 `2026-12-01-46640252167`),由工作流的开始日期
与数字运行 ID 通过 `scripts/log-run-dir.sh` 推导。每次运行都有独立目录,不会覆盖
上一次。
- 目录内的文件名规则为 `<owner>-<repo>.log`,由 `Software.list` 中的 URL 推导
(`https://github.com/zitzhen/patchsplit` → `zitzhen-patchsplit.log`)。
- 日志开头记录上游地址、开始时间、runner 与 commit,结尾记录结束时间与构建退出码,
因此构建失败时无需打开 Actions 页面即可定位原因。
因此构建失败时无需打开 Actions 页面即可定位原因;其中的 `run` 行可直接跳回对应
的运行记录。
- `scripts/build-deb.sh` 的第三个参数是可选的日志路径;不传则不写日志,行为与之前
完全一致。
- 日志在 `publish-repo.sh` 生成索引**之前**就被放进仓库目录树,因此 `log/` 会和
`dists/`、`pool/` 一起出现在 <https://apt-general.zitzhen.cn> 的根目录列表里。
若在索引生成之后才放日志,`log/` 虽然能用 URL 直接访问,却不会出现在列表中。
- 日志在每次发布时覆盖,并以 `Cache-Control: no-cache` 提供。
- `/log/` 的列表页按 bucket 中实际存在的运行目录重建,因此历史运行同样可以浏览。
重建使用带 delimiter 的 `list-objects-v2`,即使运行次数很多,开销依然很小。
- 同步**不使用** `--delete`,所以归档新日志不会删除旧日志;清理需要手动决定。
- 日志是公开内容,并以 `Cache-Control: no-cache` 提供。切勿让构建把密钥、令牌等
敏感信息打进日志——工作流只会发布构建自己写出的内容。

## 添加软件

Expand Down
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ directory. A manually triggered GitHub Actions workflow:
7. Syncs the repository to Cloudflare R2 via `aws s3 sync` for `apt` to fetch.
The `index.html` files are uploaded separately with a `text/html` content
type, the logs with `text/plain`, and both with a short `max-age`, so
browsers render them instead of downloading them.
browsers render them instead of downloading them. Build logs are archived
per run under `log/<date>-<run-id>/` and are never pruned automatically.

## Repository layout

Expand All @@ -56,8 +57,10 @@ ZGS/
│ ├── diff-software-list.sh # Computes repositories newly added since a base revision
│ ├── build-deb.sh # Builds an amd64 .deb from an upstream repository
│ ├── publish-repo.sh # Assembles, signs, and exports the apt metadata
│ ├── collect-logs.sh # Copies build logs into the staged /log/ directory
│ ├── collect-logs.sh # Copies build logs into /log/<run-dir>/ in the tree
│ ├── log-file-name.sh # Derives the published log name from a repo URL
│ ├── log-run-dir.sh # Derives the per-run archive directory name
│ ├── stage-log-index.sh # Rebuilds /log/ from all run directories
│ ├── generate-index.sh # Writes browsable index.html files for the tree
│ └── test-workflow-build-step.sh # Runs a workflow run: block under bash
├── .github/workflows/ # Build-check and publish CI
Expand Down Expand Up @@ -113,30 +116,39 @@ sudo apt-get install -y git devscripts equivs dpkg-dev gnupg apt-utils

## Build logs

Every package build writes its complete output to a log file, published in
plain text under `/log/`:
Every publish run archives the build log of each package into its own directory,
so past runs are kept instead of being overwritten:

```
https://apt-general.zitzhen.cn/log/
https://apt-general.zitzhen.cn/log/zitzhen-patchsplit.log
https://apt-general.zitzhen.cn/log/ # every run
https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/ # one run
https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/zitzhen-patchsplit.log
```

- The file name is `<owner>-<repo>.log`, derived from the `Software.list` URL
(`https://github.com/zitzhen/patchsplit` → `zitzhen-patchsplit.log`).
- The run directory is `<date>-<run-id>` (`2026-12-01-46640252167`), built from
the workflow's start date and its numeric run id by
`scripts/log-run-dir.sh`. Each run therefore gets a fresh directory and
nothing from an earlier run is replaced.
- Inside a run directory the file name is `<owner>-<repo>.log`, derived from the
`Software.list` URL (`https://github.com/zitzhen/patchsplit` →
`zitzhen-patchsplit.log`).
- Each log starts with the upstream URL, start time, runner and commit, and ends
with the finish time and the build's exit status, so a failed build is
diagnosable without opening the Actions run.
diagnosable without opening the Actions run. The `run` line links straight
back to the workflow run that produced it.
- `scripts/build-deb.sh` takes an optional third argument for the log path. When
it is omitted, nothing is written; the build behaves exactly as before.
- The logs are staged into the repository tree before `publish-repo.sh`
generates the indexes, so `log/` appears in the root listing at
<https://apt-general.zitzhen.cn> alongside `dists/` and `pool/`. Staging them
after the index was generated left `log/` reachable by URL but missing from the
listing.
- Logs are overwritten on every publish run and are served with
`Cache-Control: no-cache`.
- Logs are public. Never let a build print secrets (tokens, credentials) into
them; the workflow only publishes what the build itself wrote.
<https://apt-general.zitzhen.cn> alongside `dists/` and `pool/`.
- 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.
- 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
print secrets (tokens, credentials) into them; the workflow only publishes
what the build itself wrote.

## Adding software

Expand Down
Loading
Loading