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
398 changes: 398 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
Loading