diff --git a/.github/workflows/publish-apt.yml b/.github/workflows/publish-apt.yml index dc27583..d021fbf 100644 --- a/.github/workflows/publish-apt.yml +++ b/.github/workflows/publish-apt.yml @@ -98,6 +98,17 @@ jobs: path: ${{ runner.temp }}/packages merge-multiple: true + - name: Download build logs + # Logs are staged into the repository tree below so that the root index + # lists log/. Generating the index before the logs exist is why log/ was + # missing from the root listing even though the files were published. + continue-on-error: true + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/logs + pattern: build-log-* + merge-multiple: true + - name: Import the signing key env: APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }} @@ -109,6 +120,14 @@ jobs: printf '%s\n' "$APT_GPG_PRIVATE_KEY" | gpg --batch --import gpg --batch --list-secret-keys "$APT_GPG_KEY_ID" + - name: Stage build logs into the repository tree + # 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. + run: | + mkdir -p "$RUNNER_TEMP/repo" + ./scripts/collect-logs.sh "$RUNNER_TEMP/logs" "$RUNNER_TEMP/repo" + - name: Generate and sign repository metadata env: APT_GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }} @@ -127,12 +146,13 @@ jobs: : "${R2_ACCOUNT_ID:?R2_ACCOUNT_ID is required}" : "${R2_BUCKET:?R2_BUCKET is required}" endpoint="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" - # Exclude every generated index (fnmatch patterns match the path tail, - # so '*index.html' also covers nested directories); they are uploaded - # in the second pass below with an explicit content type. + # Three passes, each with the content type the objects need. Everything + # else syncs first; the generated indexes and the build logs are held + # back because .log has no registered MIME type and would otherwise be + # 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 '*index.html' --exclude 'log/*.log' # Upload the generated directory indexes separately so they get an # explicit MIME type; browsers then render them instead of downloading @@ -143,67 +163,11 @@ jobs: --content-type 'text/html; charset=utf-8' \ --cache-control 'no-cache, max-age=60' - echo "Repository published to $APT_REPO_URL" - - publish-logs: - name: Publish build logs to R2 - # Runs even if one of the builds failed: a log for a broken package is worth - # more than a log for a working one. It is skipped only when the matrix - # itself could not be parsed. - needs: [prepare, build] - if: always() && needs.prepare.result == 'success' - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Download build logs - # With fail-fast disabled a matrix entry can fail before it writes a log, - # and download-artifact errors when nothing matches the pattern; the - # staging step below tolerates an empty result. - continue-on-error: true - uses: actions/download-artifact@v4 - with: - path: ${{ runner.temp }}/logs - pattern: build-log-* - merge-multiple: true - - - name: Stage the log tree - run: | - mkdir -p "$RUNNER_TEMP/logtree/log" - ./scripts/collect-logs.sh "$RUNNER_TEMP/logs" "$RUNNER_TEMP/logtree" - ./scripts/generate-index.sh "$RUNNER_TEMP/logtree" \ - "ZGS · Build logs · Generated $(date -u '+%Y-%m-%d %H:%M UTC')" - # The staging root's own index.html must never reach the bucket: it would - # overwrite the apt repository's root listing. Only log/ is uploaded. - rm -f "$RUNNER_TEMP/logtree/index.html" - - - name: Sync the logs to Cloudflare R2 - 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" - - # Logs are plain text; without an explicit type browsers download them. - # They are also overwritten on every run, so keep them uncached. - aws s3 sync "$RUNNER_TEMP/logtree/log" "s3://${R2_BUCKET}/log" \ + # Build logs, plain text, uncached so a re-publish shows up immediately. + aws s3 sync "$RUNNER_TEMP/repo" "s3://${R2_BUCKET}" \ --endpoint-url "$endpoint" --region auto --no-progress \ - --exclude '*index.html' \ + --exclude '*' --include 'log/*.log' \ --content-type 'text/plain; charset=utf-8' \ --cache-control 'no-cache, max-age=60' - aws s3 sync "$RUNNER_TEMP/logtree/log" "s3://${R2_BUCKET}/log" \ - --endpoint-url "$endpoint" --region auto --no-progress \ - --exclude '*' --include '*index.html' \ - --content-type 'text/html; charset=utf-8' \ - --cache-control 'no-cache, max-age=60' - - echo "Build logs published under /log/" + echo "Repository published to $APT_REPO_URL" diff --git a/README-zh-cn.md b/README-zh-cn.md index 5764d52..348ee11 100644 --- a/README-zh-cn.md +++ b/README-zh-cn.md @@ -113,8 +113,9 @@ https://apt-general.zitzhen.cn/log/zitzhen-patchsplit.log 因此构建失败时无需打开 Actions 页面即可定位原因。 - `scripts/build-deb.sh` 的第三个参数是可选的日志路径;不传则不写日志,行为与之前 完全一致。 -- 日志由独立的 `publish-logs` job 发布,即使某个包构建失败也会执行,所以坏包同样会 - 留下日志。日志先作为 artifact 保存 14 天,随后同步到 R2。 +- 日志在 `publish-repo.sh` 生成索引**之前**就被放进仓库目录树,因此 `log/` 会和 + `dists/`、`pool/` 一起出现在 的根目录列表里。 + 若在索引生成之后才放日志,`log/` 虽然能用 URL 直接访问,却不会出现在列表中。 - 日志在每次发布时覆盖,并以 `Cache-Control: no-cache` 提供。 ## 添加软件 diff --git a/README.md b/README.md index d44db24..c774424 100644 --- a/README.md +++ b/README.md @@ -128,9 +128,11 @@ https://apt-general.zitzhen.cn/log/zitzhen-patchsplit.log diagnosable without opening the Actions run. - `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 published by a separate `publish-logs` job that runs even when a - build failed, so a broken package still leaves its log behind. Logs are capped - by the workflow's 14-day artifact retention before being synced. +- The logs are staged into the repository tree before `publish-repo.sh` + generates the indexes, so `log/` appears in the root listing at + 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