From 36eecee6ca267f14c0d32409f6f490a34d45aebb Mon Sep 17 00:00:00 2001 From: Marko Ivankovic Date: Tue, 10 Nov 2026 23:17:40 +0100 Subject: [PATCH 1/2] packaging: an RPM, and a signed dnf repository beside the APT one cargo generate-rpm builds it from the same static binary, man pages and completions as the .deb, for x86_64 and aarch64, with no dependencies, no scriptlets, and the .deb's weak dependencies. The release attests it and attaches it; a new dnf job, after apt, signs the copies it publishes under rpm/ on gh-pages and signs the index, with the APT key. CI's rpm job builds it, publishes it to a throwaway repository with a throwaway key through the same script, and installs and upgrades from it on Fedora 43, Rocky 9 and Rocky 8, with a tampered index refused. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FNs394W7GMp53qrHNPrACN --- .github/workflows/ci.yml | 91 ++++++++++++++++++++++ .github/workflows/release.yml | 135 ++++++++++++++++++++++++++++++++- CHANGELOG.md | 19 +++++ Cargo.toml | 42 ++++++++++ RELEASING.md | 77 +++++++++++++------ packaging/apt/index.html | 27 +++++-- packaging/rpm/check-install.sh | 64 ++++++++++++++++ packaging/rpm/stop-bots.repo | 16 ++++ scripts/build-rpm-repo.sh | 133 ++++++++++++++++++++++++++++++++ scripts/rpm-version.sh | 27 +++++++ src/docs.rs | 5 +- 11 files changed, 601 insertions(+), 35 deletions(-) create mode 100755 packaging/rpm/check-install.sh create mode 100644 packaging/rpm/stop-bots.repo create mode 100755 scripts/build-rpm-repo.sh create mode 100755 scripts/rpm-version.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 459c230..c882e32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -355,6 +355,97 @@ jobs: stop-bots status --quiet || true sudo apt-get remove -y stop-bots + # The RPM, built the way release.yml builds it, then published to a + # throwaway dnf repository with a throwaway key by the same + # scripts/build-rpm-repo.sh the release uses, and installed from it on + # Fedora, Rocky 9 and Rocky 8 by packaging/rpm/check-install.sh. That is + # the only place the repository is exercised before a tag publishes it. + # + # Two packages go into it: this version as a release candidate, and this + # version. Installing the first and upgrading to the second proves the + # `~` in scripts/rpm-version.sh sorts a candidate before its release, on + # the rpm each distribution ships rather than on a comparison here. + rpm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stable + with: + targets: x86_64-unknown-linux-musl + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + key: musl-rpm + + # rpm for rpmsign and for reading the package back; createrepo-c for + # the repository. Both are what the release's `dnf` job installs. + - name: Install musl, rpm and createrepo_c + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -y musl-tools rpm createrepo-c + + - uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1 + with: + tool: cargo-generate-rpm@0.21.1 + + - name: Build the packages + env: + CC_x86_64_unknown_linux_musl: musl-gcc + run: | + cargo build --release --target x86_64-unknown-linux-musl + target/x86_64-unknown-linux-musl/release/stop-bots generate-docs --out target/assets + mkdir -p dist + release="$(scripts/rpm-version.sh)" + candidate="$(scripts/rpm-version.sh "${release}-ci.1")" + for version in "$candidate" "$release"; do + cargo generate-rpm --target x86_64-unknown-linux-musl \ + --set-metadata "version = \"$version\"" -o dist/ + done + echo "RPM_RELEASE=$release" >> "$GITHUB_ENV" + echo "RPM_CANDIDATE=$candidate" >> "$GITHUB_ENV" + ls -l dist + + # As the `deb` job's check: the paths the rest of the project tells + # people about, and the man pages and completions where Fedora and + # RHEL look for them (zsh's site-functions, not Debian's + # vendor-completions). And no dependency beyond rpm's own features: + # the binary is static, so anything else would be a mistake. + - name: Check the contents + run: | + package="dist/stop-bots-${RPM_RELEASE}-1.x86_64.rpm" + rpm -qpi "$package" + echo "recommends: $(rpm -qp --recommends "$package")" + echo "suggests: $(rpm -qp --suggests "$package")" + extra="$(rpm -qp --requires "$package" | grep -v '^rpmlib(' || true)" + [ -z "$extra" ] || { echo "::error::the package requires: $extra"; exit 1; } + contents="$(rpm -qpl "$package")" + for path in /usr/bin/stop-bots /usr/share/doc/stop-bots/README.md \ + /usr/share/licenses/stop-bots/LICENSE \ + /usr/share/man/man1/stop-bots-batch.1 \ + /usr/share/bash-completion/completions/stop-bots \ + /usr/share/zsh/site-functions/_stop-bots \ + /usr/share/fish/vendor_completions.d/stop-bots.fish; do + echo "$contents" | grep -qx "$path" \ + || { echo "::error::the package does not ship $path"; exit 1; } + done + + - name: Publish to a throwaway repository + run: | + export GNUPGHOME="$(mktemp -d)" + gpg --batch --pinentry-mode loopback --passphrase '' \ + --quick-gen-key 'stop-bots CI ' rsa4096 sign never + key="$(gpg --list-secret-keys --with-colons | awk -F: '/^fpr:/ { print $10; exit }')" + scripts/build-rpm-repo.sh pages dist "$key" + + # No network inside: every package comes from the repository above, + # so a mirror being slow cannot fail this and cannot be what passed it. + - name: Install from it + run: | + for image in fedora:43 rockylinux:9 rockylinux:8; do + docker run --rm --network none \ + -v "$PWD/pages:/pages:ro" -v "$PWD/packaging/rpm:/rpm:ro" \ + "$image" sh /rpm/check-install.sh "$RPM_CANDIDATE" "$RPM_RELEASE" + done + # The README's quick start, as a stranger would follow it, on a fresh # Debian 12 and a fresh Ubuntu 24.04 under real systemd: `apt install` # of the package the `deb` job just built, then `status`, `batch`, diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 399f966..40ad380 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -111,16 +111,23 @@ jobs: # Viable here only because the dependency tree has no C TLS in it — # `reqwest` resolves to `rustls` — so `musl-gcc` has exactly one thing # to compile: the SQLite that `rusqlite`'s `bundled` feature carries. + # `rpm` only to read the .rpm back in "Inspect the package"; it is + # built by cargo-generate-rpm, which needs nothing installed. - name: Install musl toolchain run: | sudo apt-get update - sudo apt-get install --no-install-recommends -y musl-tools + sudo apt-get install --no-install-recommends -y musl-tools rpm - name: Install cargo-deb uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1 with: tool: cargo-deb + - name: Install cargo-generate-rpm + uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1 + with: + tool: cargo-generate-rpm@0.21.1 + # The target-specific `CC_*` rather than a bare `CC`: build scripts and # proc macros are compiled for the *host*, and pointing their C compiler # at musl too is how a build that looks cross-aware fails inside a @@ -175,6 +182,16 @@ jobs: cargo deb --no-build --no-strip --deb-version "$(scripts/deb-version.sh)" --target ${{ matrix.target }} --output dist/ + # From the same binary, man pages and completions as the .deb, by + # `[package.metadata.generate-rpm]`. `--set-metadata` so a release + # candidate is `0.1.0~rc.1`, which sorts before `0.1.0`; see + # scripts/rpm-version.sh. Unsigned here, like everything else on the + # release page: the `dnf` job signs the copies it publishes. + - name: Build .rpm + run: >- + cargo generate-rpm --target ${{ matrix.target }} + --set-metadata "version = \"$(scripts/rpm-version.sh)\"" --output dist/ + # The tarball stays, for the AUR `-bin` package and for anyone who would # rather not add a repository to their machine. Same binary as the .deb. - name: Package tarball @@ -198,7 +215,7 @@ jobs: - name: Checksums working-directory: dist run: | - for asset in *.tar.gz *.deb; do + for asset in *.tar.gz *.deb *.rpm; do sha256sum "$asset" > "$asset.sha256" done cat ./*.sha256 @@ -207,6 +224,8 @@ jobs: run: | dpkg-deb --info dist/*.deb dpkg-deb --contents dist/*.deb + rpm -qpi dist/*.rpm + rpm -qpl dist/*.rpm - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: @@ -250,6 +269,7 @@ jobs: subject-path: | dist/*.tar.gz dist/*.deb + dist/*.rpm release: needs: [verify-version, build, attest] @@ -283,7 +303,7 @@ jobs: for sum in *.sha256; do sha256sum --check --strict "$sum" done - sha256sum *.tar.gz *.deb > SHA256SUMS + sha256sum *.tar.gz *.deb *.rpm > SHA256SUMS cat SHA256SUMS - name: Create release @@ -436,3 +456,112 @@ jobs: fi git commit -m "apt: publish ${GITHUB_REF_NAME}" git push "https://x-access-token:${{ github.token }}@github.com/${GITHUB_REPOSITORY}.git" gh-pages + + # Republishes the dnf repository, rpm/ on the same `gh-pages` branch, with + # this release's .rpms signed and added. scripts/build-rpm-repo.sh says + # what is signed and why. + # + # After `apt`, because both push to `gh-pages` and the second push of two + # started together would be rejected. Whatever `apt` concluded, though: + # the two repositories are independent, and a failed `apt` should leave + # one of them published rather than neither. Each can be re-run alone. + # Not for a release candidate, for the reason `apt` gives. + dnf: + needs: [release, apt] + if: ${{ always() && needs.release.result == 'success' && !contains(github.ref_name, '-') }} + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: source + + # Cloned now, after `apt` pushed, so this builds on its commit. Never + # an orphan here: `apt` creates the branch, and a branch that is + # missing at this point means something is wrong that a fresh one + # would hide. + - name: Check out gh-pages + run: | + git clone --branch gh-pages --single-branch \ + "https://github.com/${GITHUB_REPOSITORY}.git" pages + echo "Found gh-pages with $(find pages/rpm -name '*.rpm' 2>/dev/null | wc -l) RPM(s)." + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: dist-* + merge-multiple: true + path: dist + + - name: Install createrepo_c and rpmsign + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -y createrepo-c rpm + + - name: Import the signing key + id: gpg + env: + APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }} + run: | + if [ -z "${APT_GPG_PRIVATE_KEY}" ]; then + echo "::error::secret APT_GPG_PRIVATE_KEY is not set — see RELEASING.md" + exit 1 + fi + printf '%s' "${APT_GPG_PRIVATE_KEY}" | gpg --batch --import + key="$(gpg --list-secret-keys --with-colons | awk -F: '/^fpr:/ { print $10; exit }')" + echo "key=${key}" >> "$GITHUB_OUTPUT" + echo "Imported ${key}" + + - name: Build and sign the repository + env: + GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }} + run: | + mkdir rpms + cp dist/*.rpm rpms/ + source/scripts/build-rpm-repo.sh pages rpms "${{ steps.gpg.outputs.key }}" + cp source/packaging/rpm/stop-bots.repo pages/stop-bots.repo + + # What `apt`'s verify step is for the APT side: dnf refuses a bad + # repository, but every host configured for it would get that + # refusal, so prove it is right before pushing. + - name: Verify the signatures and the index + run: | + cd pages/rpm + gpg --verify repodata/repomd.xml.asc repodata/repomd.xml + db="$(mktemp -d)" + rpmkeys --dbpath "$db" --import ../key.asc + version="$(../../source/scripts/rpm-version.sh "${GITHUB_REF_NAME#v}")" + primary="$(zcat repodata/*-primary.xml.gz)" + for arch in x86_64 aarch64; do + package="packages/stop-bots-${version}-1.${arch}.rpm" + # `digests signatures OK`, and not merely `digests OK`, which is + # what an unsigned package says. + rpmkeys --dbpath "$db" --checksig "$package" | grep -q 'digests signatures OK$' \ + || { echo "::error::${package} is not signed by the imported key"; rpmkeys --dbpath "$db" --checksig -v "$package"; exit 1; } + echo "$primary" | grep -q "href=\"${package}\"" \ + || { echo "::error::the index does not list ${package}"; exit 1; } + done + # Every package the index lists must exist, or dnf fails at + # install time having already said it was available. + missing="" + for href in $(echo "$primary" | sed -n 's/.*