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
68 changes: 66 additions & 2 deletions .github/workflows/publish-apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ name: Publish apt repository to R2

on:
workflow_dispatch:
inputs:
repositories:
description: >-
Optional. Comma-separated GitHub repository URLs to build, e.g.
https://github.com/zitzhen/patchsplit,https://github.com/zitzhen/GitTune
Every URL must already be listed in Software.list, otherwise nothing is
built. Leave empty to build every listed repository.
required: false
default: ''
type: string

permissions:
contents: read
Expand All @@ -21,15 +31,34 @@ jobs:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.parse.outputs.packages }}
filtered: ${{ steps.parse.outputs.filtered }}
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Build the package matrix
# The optional `repositories` input narrows the matrix to a hand-typed
# subset of Software.list. The input is checked, not trusted: a URL that
# is not listed fails this step, so an unlisted (or mistyped) repository
# never reaches the build jobs.
id: parse
env:
REPOSITORIES: ${{ inputs.repositories }}
run: |
packages="$(./scripts/parse-software-list.sh Software.list)"
packages="$(./scripts/select-software.sh Software.list "$REPOSITORIES")"
echo "packages=$packages" >> "$GITHUB_OUTPUT"
# Whether this run is a partial rebuild is decided by comparing the
# selected matrix with the whole manifest, not by looking at the raw
# input: a value that selects every entry (or only separators) still
# publishes everything, and only a real subset needs the publish job to
# restore the packages it did not rebuild.
all_packages="$(./scripts/parse-software-list.sh Software.list)"
if [[ "$packages" == "$all_packages" ]]; then
echo "filtered=false" >> "$GITHUB_OUTPUT"
else
echo "filtered=true" >> "$GITHUB_OUTPUT"
echo "Partial rebuild: publishing will keep the packages not rebuilt"
fi
echo "Build matrix: $packages"

build:
Expand Down Expand Up @@ -78,7 +107,10 @@ jobs:

publish:
name: Sign and publish to R2
needs: build
# prepare is listed explicitly, not just reached through build, so that
# needs.prepare.outputs.filtered is available here without relying on
# transitive needs.
needs: [prepare, build]
runs-on: ubuntu-latest
env:
APT_GPG_KEY_ID: ${{ vars.APT_GPG_KEY_ID || '3B310141DFDBDE77A802C0627DFBD414F81DC0BB' }}
Expand Down Expand Up @@ -109,6 +141,38 @@ jobs:
pattern: build-log-*
merge-multiple: true

- name: Restore the packages already published
# A run that rebuilds only a subset of the manifest must still publish an
# index that contains every package: publish-repo.sh regenerates Packages
# from the artifacts directory alone, so without this the packages that
# were not rebuilt would disappear from the index until the next full run.
# Only runs when the input filtered the matrix, so a full run keeps
# behaving exactly as before and never re-downloads anything.
if: needs.prepare.outputs.filtered == 'true'
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"
mkdir -p "$RUNNER_TEMP/published"
# Only the pool is downloaded: everything in the index comes from there,
# and the generated metadata is rebuilt from scratch by publish-repo.sh.
aws s3 sync "s3://${R2_BUCKET}/pool" "$RUNNER_TEMP/published/pool" \
--endpoint-url "$endpoint" --region auto --no-progress \
--exclude '*' --include '*.deb'
# Fold the published .deb files into the artifacts directory so they are
# re-indexed alongside the packages this run rebuilt. The script keeps
# only the newest published version of each package and skips any
# package built by this run, so a rebuild still supersedes the old .deb.
./scripts/merge-artifacts.sh "$RUNNER_TEMP/packages" "$RUNNER_TEMP/published/pool"

- name: Import the signing key
env:
APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/script-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ jobs:
# builds into exit 1, which skipped publish on every run.
run: ./scripts/test-build-deb-exit-status.sh

- name: Test the optional repository filter
# The workflow input is hand-typed, so it is validated: an unlisted URL
# must stop the run, and a filtered publish must still index the packages
# it did not rebuild.
run: ./scripts/test-repository-filter.sh

- name: Check build-deb.sh survives a failing build
# A failing build must still leave a usable log and must not abort the
# cleanup with "unbound variable" (that regressed once).
Expand Down
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ Packages are not published by a pull request alone. After a change is merged, a
maintainer runs the **Publish apt repository to R2** workflow manually from the
Actions tab.

That workflow takes an optional `repositories` input: a comma-separated list of
repository URLs, which limits the run to those packages. Every URL must already
be in `Software.list` — `scripts/select-software.sh` fails the run otherwise, and
the run then builds nothing. Leaving the input empty builds the whole manifest.
The publish job re-indexes the packages already in the bucket alongside the ones
just built (`scripts/merge-artifacts.sh`), so a filtered run never drops another
package from the apt index. Validate a filter locally before triggering a run:

```bash
# Every listed entry (the empty input)
./scripts/select-software.sh Software.list

# A subset; mixed or full-width separators are accepted and normalised
./scripts/select-software.sh Software.list \
"https://github.com/zitzhen/patchsplit, https://github.com/zitzhen/GitTune"

# Unlisted URLs fail on purpose
./scripts/select-software.sh Software.list https://github.com/not/listed
```

## Local validation

Validate the manifest and, when changing the build pipeline, try a local build:
Expand Down Expand Up @@ -118,6 +138,15 @@ from the workflow and runs it under bash for a given matrix URL:
The `Script checks` workflow runs this for every `Software.list` entry, so a
mistake here fails the pull request instead of the next publish.

The optional repository filter and the artifact merge have their own test suite,
which also asserts the workflow wiring (the `repositories` input reaching
`select-software.sh` through the environment rather than being spliced into the
script):

```bash
./scripts/test-repository-filter.sh
```

To test publishing metadata end to end you need a signing key available to GPG;
`scripts/publish-repo.sh` expects an artifacts directory, an output directory,
and a key ID. Do not export or commit the repository's private signing key.
Expand Down
34 changes: 32 additions & 2 deletions README-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ZGS 出现在 [zhento-Software-Source](https://github.com/zitzhen/zhento-Softwar
仓库的核心是一个 `Software.list` 清单文件,每行列出一个包含 `debian/` 打包目录的上游
GitHub 仓库地址。手动触发的 GitHub Actions 工作流会:

1. 解析 `Software.list`,生成构建矩阵;
1. 解析 `Software.list`,生成构建矩阵(可通过手动运行时的 `repositories` 输入
只构建指定的仓库,见[只构建指定的仓库](#只构建指定的仓库));
2. 依次 clone 上游仓库,用 `mk-build-deps` 安装构建依赖,执行
`dpkg-buildpackage -b -us -uc` 产出 `amd64` 二进制包;
3. 用 `dpkg-scanpackages` / `apt-ftparchive` 生成 apt 索引与 `Release` 元数据;
Expand All @@ -43,6 +44,8 @@ ZGS/
├── Software.list # 上游软件清单(每行一个 GitHub 仓库 URL)
├── scripts/
│ ├── parse-software-list.sh # 解析清单,输出构建矩阵 JSON
│ ├── select-software.sh # 校验并应用可选的仓库过滤输入
│ ├── merge-artifacts.sh # 把已发布的包重新并入索引,避免被挤掉
│ ├── diff-software-list.sh # 计算相对某个基线新增的仓库
│ ├── build-deb.sh # 从上游仓库构建 amd64 .deb
│ ├── publish-repo.sh # 组装、签名并导出 apt 元数据
Expand All @@ -55,7 +58,8 @@ ZGS/
│ ├── publish-log-release.sh # 创建带日志附件的发行版
│ ├── github-app-token.sh # 生成 GitHub App 安装令牌
│ ├── generate-index.sh # 为仓库目录树生成可浏览的 index.html
│ └── test-workflow-build-step.sh # 在 bash 下执行 workflow 的 run 块
│ ├── test-workflow-build-step.sh # 在 bash 下执行 workflow 的 run 块
│ └── test-repository-filter.sh # 测试仓库过滤输入与产物合并
├── .github/workflows/ # 构建检查与发布 CI
├── .githooks/ # DCO 签名的版本化 Git 钩子
├── CONTRIBUTING.md # 贡献指南
Expand Down Expand Up @@ -166,6 +170,32 @@ https://apt-general.zitzhen.cn/log/2026-12-01-46640252167/zitzhen-patchsplit.log
- 重复 URL 会被忽略(并打印警告);
- 上游仓库**必须**包含有效的 `debian/` 目录,且能产出 `amd64` 的 `.deb`。

## 只构建指定的仓库

**Publish apt repository to R2** 工作流新增了一个可选的 `repositories` 输入,
维护者可以只重建一个或几个包,而不必重建整个清单。留空即构建清单中的全部条目,
与之前的行为完全一致。

该输入是单行的仓库地址列表,用逗号分隔,例如:

```
https://github.com/zitzhen/patchsplit,https://github.com/zitzhen/GitTune
```

`scripts/select-software.sh` 会做如下校验:

- 忽略首尾空格,末尾的 `.git` 或 `/` 会被归一化;因为是手工输入,也接受全角
逗号(`,`、`、`)和整体外层方括号;
- 每个地址**必须已经在 `Software.list` 中列出**。清单里没有的地址(或根本不是
GitHub 仓库地址的输入)会让 `prepare` job 直接失败,**该次运行不会构建任何包**,
请先把仓库加入清单;
- 构建矩阵按清单顺序排列,重复的地址只构建一次。

发布行为不受过滤影响:`publish` job 会先从存储桶下载已发布的 `.deb`,与本次刚构建
的包一起重新生成索引,同一个包只保留最新版本并且始终以本次构建的版本为准。因此
只构建部分仓库**不会**把其它包从 apt 索引中挤掉。相关脚本为
`scripts/merge-artifacts.sh`。

## 许可证与贡献

本项目以 [AGPL-3.0-only](LICENSE) 发布。所有提交需遵循 DCO
Expand Down
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ The repository is driven by a `Software.list` manifest file, with each line
pointing to an upstream GitHub repository that contains a `debian/` packaging
directory. A manually triggered GitHub Actions workflow:

1. Parses `Software.list` and produces a build matrix;
1. Parses `Software.list` and produces a build matrix, optionally narrowed to the
repositories given in the manual run's `repositories` input (see
[Building only selected repositories](#building-only-selected-repositories));
2. Clones each upstream repository, installs its build dependencies with
`mk-build-deps`, and runs `dpkg-buildpackage -b -us -uc` to produce `amd64`
binary packages;
Expand All @@ -54,6 +56,8 @@ ZGS/
├── Software.list # Upstream software manifest (one GitHub repo URL per line)
├── scripts/
│ ├── parse-software-list.sh # Parses the manifest, emits the build-matrix JSON
│ ├── select-software.sh # Validates and applies the optional repository filter
│ ├── merge-artifacts.sh # Re-indexes published packages a filtered run skipped
│ ├── 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
Expand All @@ -66,7 +70,8 @@ ZGS/
│ ├── publish-log-release.sh # Publishes a release with the run's logs
│ ├── github-app-token.sh # Mints a GitHub App installation token
│ ├── generate-index.sh # Writes browsable index.html files for the tree
│ └── test-workflow-build-step.sh # Runs a workflow run: block under bash
│ ├── test-workflow-build-step.sh # Runs a workflow run: block under bash
│ └── test-repository-filter.sh # Tests the repository filter and artifact merge
├── .github/workflows/ # Build-check and publish CI
├── .githooks/ # Versioned Git hooks for DCO sign-off
├── CONTRIBUTING.md # Contribution guide
Expand Down Expand Up @@ -196,6 +201,36 @@ Manifest rules (enforced by `scripts/parse-software-list.sh`):
- The upstream repository **must** contain a valid `debian/` directory and
produce an `amd64` `.deb`.

## Building only selected repositories

The **Publish apt repository to R2** workflow has an optional `repositories`
input, so a maintainer can rebuild one or a few packages instead of the whole
manifest. Leave it empty to build every entry, which is the previous behaviour.

The input is a comma-separated list of repository URLs on a single line, for
example:

```
https://github.com/zitzhen/patchsplit,https://github.com/zitzhen/GitTune
```

Rules enforced by `scripts/select-software.sh`:

- Surrounding spaces are ignored, a trailing `.git` or `/` is normalized, and the
full-width comma `,` and the ideographic comma `、` are accepted, because the
field is typed by hand;
- Every URL **must already be listed** in `Software.list`. A URL that is missing
from the manifest (or is not a GitHub repository URL at all) fails the
`prepare` job, so **no package is built** by that run. Add the repository to
the manifest first;
- The matrix follows the manifest order, and repeated URLs are selected once.

Publishing is unaffected by the filter: the `publish` job downloads the
previously published `.deb` files from the bucket and re-indexes them together
with the packages just built, keeping only the newest version of each package
and always preferring the freshly built one. A filtered run therefore never
removes another package from the apt index. See `scripts/merge-artifacts.sh`.

## License and contributing

This project is released under [AGPL-3.0-only](LICENSE). All commits must follow
Expand Down
Loading
Loading