From 73c2a297f42475ef2b0a6333dd3c1ffccf0209fe Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Sat, 28 Nov 2026 15:07:15 +0100 Subject: [PATCH] ci: add a release workflow Currently, whoever wants the C library has to build libuapi16 with build.sh and install.sh, and so needs a Rust toolchain. Let's ship it prebuilt with every release instead. A push of a v* tag builds the library for x86_64 and aarch64 Linux, each on GitHub's native runner, with rustc 1.85, the oldest one we support. The build is build.sh and install.sh as they are. The linker binds every glibc symbol the library uses to the newest version of that symbol in the glibc it links against, and a glibc without that version can't load the library. So the build runs in a container with AlmaLinux 9.8, pinned by its digest, whose glibc is 2.34, and not on the runner, whose glibc is newer. That covers RHEL 9, CentOS Stream 9, Amazon Linux 2023 and every distribution with a newer glibc. Each architecture gets uapi16---linux-gnu.tar.gz, with a directory of that name at its top, laid out as the prefix install.sh installs to: lib/libuapi16.so., with the links .so.0 and .so lib/libuapi16.a lib/pkgconfig/uapi16.pc include/uapi16.h share/licenses/uapi16/ install.sh writes the prefix into uapi16.pc. The tarball's uapi16.pc has prefix=${pcfiledir}/../.. instead, so the tarball can be unpacked anywhere. The library links Rust's standard library and the crates it depends on, so the tarball carries their license texts next to its own. The texts of the standard library come from the toolchain. For every crate of Cargo.lock that is linked into the library, as cargo tree lists them, they are the license files of its source. A crate without a license file fails the job. Before anything is uploaded the job checks the layout of the tarball, that the shared library exports its functions at LIBUAPI16_0.1.0 and nothing else, that it needs no glibc symbol newer than GLIBC_2.34, and that the examples build against the unpacked tarball with pkg-config and run. The full C tests stay in the CI of every pull request. Each tarball gets a build provenance attestation from actions/attest, which says what workflow run built it from which commit: gh attestation verify -R systemd/uapi16 \ --source-ref refs/tags/ \ --signer-workflow systemd/uapi16/.github/workflows/release.yml For a tag the version has to be the version of src/uapi16/Cargo.toml. A job of its own writes SHA256SUMS over the tarballs, and the workflow then makes a draft release with the tarballs and SHA256SUMS, with the message of the tag as its notes. Nothing is signed in CI. SHA256SUMS gets signed by hand, and SHA256SUMS.asc is uploaded to the draft before it is published. Every pull request runs the build job as well, on each architecture and with all of its checks. So a change that breaks the tarballs shows up in its pull request and not only once a tag is pushed. A pull request gets no attestation, no artifact and no release. One from a fork gets a token that can only read, which is all the build needs. A new push to a pull request cancels the run for the push before it. A run by hand, with workflow_dispatch, builds, checks and attests the tarballs of a branch, writes SHA256SUMS and keeps all of it as artifacts of the run. So it does everything a tag does except for the draft release itself, which first runs with the first tag. The README now says how to install the prebuilt library and how to check a release. Signed-off-by: Christian Brauner (Amutable) --- .github/workflows/release.yml | 398 ++++++++++++++++++++++++++++++++++ README.md | 38 ++++ 2 files changed, 436 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b229932 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,398 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# The C library of a release, for x86_64 and for aarch64: a tarball of +# libuapi16 for each, with a directory at its top that is laid out as +# install.sh installs and has the license texts in share/licenses/uapi16, +# built against glibc 2.34 so that it works there and with every newer +# glibc. Each tarball gets a build provenance attestation. +# +# A tag v* gets a draft release with the two tarballs and SHA256SUMS, with +# the message of the tag as its notes. Nothing is signed here: +# SHA256SUMS.asc is uploaded to the draft by hand, and the release is +# published by hand after that. +# +# A pull request builds and checks the tarballs, and does nothing else: +# no attestation, no artifact and no release. A pull request from a fork +# gets a token that can only read, which is all the build needs. +# +# A run by hand builds, checks and attests the tarballs of a branch, and +# keeps them and their SHA256SUMS as artifacts of the run. It makes no +# release. + +name: Release + +on: + push: + tags: + - 'v*' + pull_request: + workflow_dispatch: + +permissions: {} + +# A new push to a pull request cancels the run for the push before it. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +defaults: + run: + shell: bash + +jobs: + build: + name: Build (${{ matrix.arch }}) + runs-on: ${{ matrix.runner }} + timeout-minutes: 30 + permissions: + contents: read + id-token: write + attestations: write + strategy: + fail-fast: false + matrix: + include: + - arch: x86_64 + runner: ubuntu-26.04 + rustup-init: b1c8cb14e30889e7e2999e6b69e62d9e9b9ffc0f4df8180564d306d9680e6c55 + - arch: aarch64 + runner: ubuntu-26.04-arm + rustup-init: 9f608c142e0e38a78957d0661ba1dfaf0b6fb37184cfaa4b9a0aa57af6184282 + # AlmaLinux 9.8, whose glibc is 2.34. The linker binds every glibc + # symbol the library uses to the newest version of it in the glibc it + # links against, and a glibc without that version can't load the + # library. The runner's glibc is newer. + container: + image: quay.io/almalinuxorg/almalinux@sha256:3b958c0ee1c6f610f39a23143117ebcf5812a17aa42b0b09ebdb6fed18da3ae5 # 9.8-20261114 + env: + # The oldest rustc uapi16 supports, and the rustup that installs it. + RUST: '1.85.0' + RUSTUP: '1.29.3' + steps: + - name: Install dependencies + # git for the checkout, the C compiler that links the shared + # library and builds the examples, and pkg-config, which the + # examples take their flags from. readelf, nm and objdump are in + # the image. + run: dnf install -y -q --setopt=install_weak_deps=False gcc git-core pkgconf-pkg-config + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Version + # The version of the crate, which is the version of the library. A + # tag has to name it: v0.1.0 for 0.1.0. install.sh reads it the + # same way. + env: + EVENT: ${{ github.event_name }} + REF: ${{ github.ref_name }} + ARCH: ${{ matrix.arch }} + run: | + version=$(sed -n '/^version = "\(.*\)"$/{s//\1/p;q;}' src/uapi16/Cargo.toml) + [ -n "$version" ] || { echo "::error::src/uapi16/Cargo.toml has no version"; exit 1; } + if [ "$EVENT" = push ] && [ "$REF" != "v$version" ]; then + echo "::error::the tag $REF does not name $version, the version of src/uapi16/Cargo.toml" + exit 1 + fi + [ "$(uname -m)" = "$ARCH" ] || { echo "::error::this is $(uname -m) and not $ARCH"; exit 1; } + { + echo "VERSION=$version" + echo "NAME=uapi16-$version-$ARCH-linux-gnu" + echo "TARBALL=uapi16-$version-$ARCH-linux-gnu.tar.gz" + } >> "$GITHUB_ENV" + + - name: Install rustc + # The image has no rustup. Its installer comes from the Rust + # project and is checked against the hash of the matrix before it + # runs. + env: + ARCH: ${{ matrix.arch }} + SHA256: ${{ matrix.rustup-init }} + run: | + init=$RUNNER_TEMP/rustup-init + curl --proto '=https' --tlsv1.2 -sSf -o "$init" \ + "https://static.rust-lang.org/rustup/archive/$RUSTUP/$ARCH-unknown-linux-gnu/rustup-init" + echo "$SHA256 $init" | sha256sum --check --strict + chmod +x "$init" + "$init" -y --no-modify-path --profile minimal --default-toolchain "$RUST" + rm "$init" + echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" + "$HOME/.cargo/bin/rustc" --version + + - name: Build the static and the shared library + run: src/uapi16/build.sh -- --locked + + - name: Install into the directory of the tarball + # What install.sh installs into a prefix of its own, which becomes + # the directory at the top of the tarball and has its name. + # uapi16.pc names that prefix, so in the tarball it names the + # directory two levels above uapi16.pc instead, wherever the tarball + # is unpacked. + run: | + prefix=$RUNNER_TEMP/$NAME + src/uapi16/install.sh --prefix="$prefix" + pc=$prefix/lib/pkgconfig/uapi16.pc + sed -i \ + -e 's|^prefix=.*|prefix=${pcfiledir}/../..|' \ + -e 's|^libdir=.*|libdir=${prefix}/lib|' \ + -e 's|^includedir=.*|includedir=${prefix}/include|' \ + "$pc" + if grep -qF "$prefix" "$pc"; then + echo "::error::uapi16.pc still names $prefix:" + cat "$pc" + exit 1 + fi + cat "$pc" + + - name: Add the license texts + # The license of libuapi16, and the licenses of what is linked into + # it: the Rust standard library, with the license texts of the + # toolchain, and every crate of Cargo.lock that is linked, with the + # license files of its source. cargo tree lists those crates, and + # leaves out procedural macros and the dependencies of builds and + # tests, which are not linked. A crate without a license file fails + # the job. + run: | + licenses=$RUNNER_TEMP/$NAME/share/licenses/uapi16 + mkdir -p "$licenses/rust" "$licenses/crates" + cp src/uapi16/LICENSE "$licenses/LICENSE" + doc=$(rustc --print sysroot)/share/doc/rust + cp "$doc/COPYRIGHT" "$doc/LICENSE-APACHE" "$doc/LICENSE-MIT" "$licenses/rust/" + cargo tree --locked -p uapi16 --features capi -e normal,no-proc-macro --prefix none \ + --format '{p}' | sed 's/ (\*)$//' | LC_ALL=C sort -u > "$RUNNER_TEMP/tree" + registry=${CARGO_HOME:-$HOME/.cargo}/registry/src + : > "$RUNNER_TEMP/crates" + bad=0 + while read -r name version source; do + [ "$name" != uapi16 ] || continue + crate=$name-${version#v} + if [ -n "$source" ]; then + echo "::error::$crate is not from crates.io: $source" + bad=1 + continue + fi + set -- "$registry"/*/"$crate" + if [ $# != 1 ] || [ ! -d "$1" ]; then + echo "::error::the source of $crate is not in $registry" + bad=1 + continue + fi + mkdir "$licenses/crates/$crate" + find "$1" -maxdepth 1 -type f \( -iname 'LICEN[CS]E*' -o -iname 'COPYING*' \ + -o -iname 'COPYRIGHT*' -o -iname 'NOTICE*' -o -iname 'UNLICENSE*' \) \ + -exec cp -t "$licenses/crates/$crate" {} + + if [ -z "$(ls -A "$licenses/crates/$crate")" ]; then + echo "::error::$crate has no license file" + bad=1 + continue + fi + echo "$crate" >> "$RUNNER_TEMP/crates" + echo "$crate:" $(ls "$licenses/crates/$crate") + done < "$RUNNER_TEMP/tree" + exit "$bad" + + - name: Make the tarball + # The checks below take the tarball unpacked somewhere else. + run: | + mkdir dist + tar -C "$RUNNER_TEMP" -czf "dist/$TARBALL" "$NAME" + rm -r "${RUNNER_TEMP:?}/${NAME:?}" + tar -tvzf "dist/$TARBALL" + mkdir "$RUNNER_TEMP/unpacked" + tar -C "$RUNNER_TEMP/unpacked" -xzf "dist/$TARBALL" + + - name: Check the layout of the tarball + # Only the directory of the tarball's name at the top, and in it + # what install.sh installs, the links of the shared library and the + # license texts, with a directory of license files for every crate. + run: | + top=$(tar -tzf "dist/$TARBALL" | cut -d / -f 1 | LC_ALL=C sort -u) + if [ "$top" != "$NAME" ]; then + echo "::error::the tarball has" $top "at its top, and not only $NAME" + exit 1 + fi + cd "$RUNNER_TEMP/unpacked/$NAME" + licenses=share/licenses/uapi16 + { + printf '%s\n' include include/uapi16.h lib lib/libuapi16.a lib/libuapi16.so \ + lib/libuapi16.so.0 "lib/libuapi16.so.$VERSION" lib/pkgconfig lib/pkgconfig/uapi16.pc \ + share share/licenses "$licenses" "$licenses/LICENSE" "$licenses/rust" \ + "$licenses/rust/COPYRIGHT" "$licenses/rust/LICENSE-APACHE" "$licenses/rust/LICENSE-MIT" \ + "$licenses/crates" + sed "s|^|$licenses/crates/|" "$RUNNER_TEMP/crates" + } | LC_ALL=C sort > "$RUNNER_TEMP/expected" + find . -mindepth 1 ! -path "./$licenses/crates/*/*" | sed 's|^\./||' | LC_ALL=C sort \ + > "$RUNNER_TEMP/found" + if [ "$(cat "$RUNNER_TEMP/expected")" != "$(cat "$RUNNER_TEMP/found")" ]; then + echo "::error::the tarball does not have the layout it should" + LC_ALL=C comm -23 "$RUNNER_TEMP/expected" "$RUNNER_TEMP/found" | sed 's/^/missing: /' + LC_ALL=C comm -13 "$RUNNER_TEMP/expected" "$RUNNER_TEMP/found" | sed 's/^/not expected: /' + exit 1 + fi + for f in include/uapi16.h lib/libuapi16.a "lib/libuapi16.so.$VERSION" lib/pkgconfig/uapi16.pc; do + [ -f "$f" ] && [ ! -L "$f" ] || { echo "::error::$f is not a regular file"; exit 1; } + done + for l in lib/libuapi16.so lib/libuapi16.so.0; do + [ "$(readlink "$l")" = "libuapi16.so.$VERSION" ] || + { echo "::error::$l does not link to libuapi16.so.$VERSION"; exit 1; } + done + while read -r crate; do + [ -n "$(ls -A "$licenses/crates/$crate")" ] || + { echo "::error::$licenses/crates/$crate is empty"; exit 1; } + done < "$RUNNER_TEMP/crates" + echo "the layout is right, with the license files of $(wc -l < "$RUNNER_TEMP/crates") crates" + + - name: Check what the shared library exports + # Functions and nothing else, all at LIBUAPI16_0.1.0, as many as + # 0.1.0 has. GNU ld also lists the node as an absolute symbol of + # its name, which is no export. + env: + EXPORTS: 132 + run: | + so=$RUNNER_TEMP/unpacked/$NAME/lib/libuapi16.so.$VERSION + exports=$(nm -D --defined-only --with-symbol-versions "$so" | + sed '/ A LIBUAPI16_0\.1\.0$/d') + other=$(echo "$exports" | grep -v ' T uapi16_[a-z0-9_]*@@LIBUAPI16_0\.1\.0$' || true) + if [ -n "$other" ]; then + echo "::error::$so exports more than functions at LIBUAPI16_0.1.0:" + echo "$other" + exit 1 + fi + count=$(echo "$exports" | wc -l) + if [ "$count" != "$EXPORTS" ]; then + echo "::error::$so exports $count functions and not $EXPORTS" + exit 1 + fi + echo "$count functions at LIBUAPI16_0.1.0" + + - name: Check the glibc the shared library needs + # No symbol of a glibc newer than 2.34, and none of GLIBC_PRIVATE. + run: | + so=$RUNNER_TEMP/unpacked/$NAME/lib/libuapi16.so.$VERSION + versions=$(objdump -T "$so" | grep -o 'GLIBC_[A-Z0-9_.]*' | sort -u -V) + for v in $versions; do + newest=$(printf '%s\n' "$v" GLIBC_2.34 | sort -V | tail -n 1) + case $v in + GLIBC_[0-9]*) [ "$newest" = GLIBC_2.34 ] ;; + *) false ;; + esac || { echo "::error::$so needs $v, which glibc 2.34 does not have"; exit 1; } + done + echo "glibc versions:" $versions + + - name: Build and run the examples + # The six programs of examples/, built against the unpacked tarball + # with the flags its uapi16.pc gives, and each run once on a small + # tree. + run: | + export PKG_CONFIG_PATH=$RUNNER_TEMP/unpacked/$NAME/lib/pkgconfig + cflags=$(pkg-config --cflags uapi16) + libs=$(pkg-config --libs uapi16) + libdir=$(pkg-config --variable=libdir uapi16) + work=$RUNNER_TEMP/examples + mkdir -p "$work/tree/dir" + echo data > "$work/tree/file" + ln "$work/tree/file" "$work/tree/dir/link" + ln -s file "$work/tree/symlink" + for example in generate listing build assemble sorted signed; do + # shellcheck disable=SC2086 + cc -std=c11 -Wall -Wextra -Werror $cflags -o "$work/$example" \ + "src/uapi16/examples/$example.c" $libs -Wl,-rpath,"$libdir" + done + "$work/generate" "$work/tree" "$work" generate.manifest + "$work/listing" "$work" listing.manifest + "$work/build" "$work/tree" "$work/image" > "$work/build.manifest" + "$work/assemble" "$work/image" "$work/assembled" < "$work/build.manifest" + "$work/sorted" "$work/tree" > "$work/sorted.manifest" + "$work/signed" "$work/signed.manifest" + + # A build provenance attestation, which gh attestation verify + # checks. GitHub keeps it, and Sigstore's transparency log has it. + # Not for a pull request. + - name: Attest the tarball + if: github.event_name != 'pull_request' + uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 + with: + subject-path: dist/${{ env.TARBALL }} + + # For the draft release, and for a run by hand to keep. Not for a + # pull request. + - name: Upload the tarball + if: github.event_name != 'pull_request' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: ${{ env.TARBALL }} + path: dist/${{ env.TARBALL }} + if-no-files-found: error + + checksums: + name: SHA256SUMS + # For a tag and for a run by hand, never for a pull request. So a run + # by hand does everything a tag does but the draft release. + if: github.event_name != 'pull_request' + needs: build + runs-on: ubuntu-26.04 + timeout-minutes: 10 + permissions: {} + steps: + - name: Download the tarballs + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: dist + merge-multiple: true + + - name: Write SHA256SUMS + # The version is in the names of the tarballs. + working-directory: dist + run: | + set -- uapi16-*-x86_64-linux-gnu.tar.gz + if [ $# != 1 ] || [ ! -f "$1" ]; then + echo "::error::not one tarball for x86_64:" "$@" + exit 1 + fi + version=${1#uapi16-} + version=${version%-x86_64-linux-gnu.tar.gz} + sha256sum "uapi16-$version-x86_64-linux-gnu.tar.gz" "uapi16-$version-aarch64-linux-gnu.tar.gz" \ + > SHA256SUMS + cat SHA256SUMS + + - name: Upload SHA256SUMS + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: SHA256SUMS + path: dist/SHA256SUMS + if-no-files-found: error + + release: + name: Draft release + # For a tag, never for a pull request or a run by hand. + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + needs: checksums + runs-on: ubuntu-26.04 + timeout-minutes: 10 + permissions: + contents: write + steps: + # gh takes the notes from the message of the tag in the checkout, and + # the repository from its remote. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Download the tarballs and SHA256SUMS + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: dist + merge-multiple: true + + - name: Make the draft release + # With both tarballs and SHA256SUMS, which is what gets signed. + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + run: | + version=${TAG#v} + gh release create "$TAG" --draft --verify-tag --notes-from-tag \ + "dist/uapi16-$version-x86_64-linux-gnu.tar.gz" \ + "dist/uapi16-$version-aarch64-linux-gnu.tar.gz" \ + dist/SHA256SUMS diff --git a/README.md b/README.md index 9e4a9fa..4be0383 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,43 @@ it into /usr: src/uapi16/build.sh src/uapi16/install.sh --prefix=/usr +## Prebuilt C library + +Every release has the C library prebuilt for x86_64 and aarch64 Linux +with glibc 2.34 or newer, in uapi16-VERSION-ARCH-linux-gnu.tar.gz. The +tarball holds a directory of that name with what install.sh installs, +and with the license texts in share/licenses/uapi16. These install it +into /opt/uapi16: + + mkdir -p /opt/uapi16 + tar --strip-components=1 -C /opt/uapi16 \ + -xf uapi16-0.1.0-x86_64-linux-gnu.tar.gz + export PKG_CONFIG_PATH=/opt/uapi16/lib/pkgconfig + +The directory can be moved or copied as a whole, but uapi16.pc can't be +copied or symlinked out of it. + +SHA256SUMS lists the hashes of the tarballs. SHA256SUMS.asc is its +signature by Christian Brauner , with this key and +its signing subkey: + + key 4880 B8C9 BD0E 5106 FC07 0F4F 7B3C 391E FEA9 3624 + subkey 4087 3457 1EA7 0C78 B332 6928 91C6 1BC0 6578 DCA2 + +The key is in the [keyring of kernel.org][keyring]. These check a +tarball against the sums and the key: + + sha256sum --ignore-missing -c SHA256SUMS + gpg --verify SHA256SUMS.asc SHA256SUMS + +Each tarball also has an attestation of the GitHub workflow run that +built it, which the GitHub CLI checks: + + gh attestation verify uapi16-0.1.0-x86_64-linux-gnu.tar.gz \ + -R systemd/uapi16 \ + --source-ref refs/tags/v0.1.0 \ + --signer-workflow systemd/uapi16/.github/workflows/release.yml + ## Submitting changes Changes go in as pull requests on GitHub. Every commit carries a @@ -24,3 +61,4 @@ DCO. Merge commits don't need one. LGPL-2.1-or-later, see LICENSE. [spec]: https://uapi-group.org/specifications/specs/file_manifest/ +[keyring]: https://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git/plain/keys/7B3C391EFEA93624.asc