chadtmiller.com/knotless
git that lives in your Atmosphere account
7
# Publishes the client as a release of the `knotless` package
# (docs/design/packages.md): when main's version, in Cargo.toml, has no
# release yet and this commit's checks all pass, it builds every target
# deploy/build-client.sh builds and publishes them with `knotless publish`,
# as the repository's owner, with the version's CHANGELOG.md section as its
# notes, and tags its commit `v<version>`. `knope release` bumps the
# version in a pull; once that lands, this publishes it. A version
# published already is left alone, so the run passes at once.
#
# RELEASE_PASSWORD is an app password of the owner's, granted to pushes to
# main alone in the runner's secrets file. Asked for on any other branch,
# `knotless rerun <repo> --ref refs/heads/<branch> --workflow release`, it
# builds everything and publishes nothing, to try the build.
on:
push: {refs: [refs/heads/main], paths: [Cargo.toml]}
asked: {refs: [refs/heads/*]}
superseded: finish
image: rust:1.98
cache: [target, /usr/local/cargo/registry, /usr/local/rustup, /opt/tools]
secrets: [RELEASE_PASSWORD]
env:
REPO: knotless://chadtmiller.com/knotless
KNOTLESS_APPVIEW: https://knotless.dev
ZIG_VERSION: 0.16.0
ZIGBUILD_VERSION: 0.23.4
steps:
- name: version
run: |
cargo build --release --locked -p knotless
cp target/release/knotless /usr/local/bin/
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
echo "$version" > ~/.version
if knotless releases "$REPO" knotless | cut -f2 | grep -qxF "$version"; then
echo "knotless $version is published already"
touch ~/.done
elif [ "$KNOTLESS_RUN_REF" != refs/heads/main ]; then
echo "on $KNOTLESS_RUN_REF: building $version, publishing nothing"
fi
# All seven, over 25 minutes, with the knotless just built. At main
# alone, as publish is, and even when the version is published already,
# as the step cannot see ~/.done: it then waits for checks it does not
# need.
- uses: chadtmiller.com/steps/wait-for-checks@2
name: checks pass
on: {refs: [refs/heads/main]}
with: {workflows: check test web lexicons shots docs e2e}
- name: tools
run: |
[ ! -e ~/.done ] || exit 0
if [ "$(cat /opt/tools/.zig 2>/dev/null)" != "$ZIG_VERSION $ZIGBUILD_VERSION" ]; then
find /opt/tools -mindepth 1 -delete
mkdir -p /opt/tools/zig
curl -fsSL "https://ziglang.org/download/$ZIG_VERSION/zig-x86_64-linux-$ZIG_VERSION.tar.xz" | tar -xJ -C /opt/tools/zig --strip-components 1
cargo install --locked --root /opt/tools cargo-zigbuild --version "$ZIGBUILD_VERSION"
echo "$ZIG_VERSION $ZIGBUILD_VERSION" > /opt/tools/.zig
fi
ln -sf /opt/tools/zig/zig /usr/local/bin/zig
ln -sf /opt/tools/bin/cargo-zigbuild /usr/local/cargo/bin/cargo-zigbuild
- name: build
timeout: 60
run: |
[ ! -e ~/.done ] || exit 0
TOOLCHAIN= deploy/build-client.sh target/client
ls -l target/client
- name: publish
on: {refs: [refs/heads/main]}
run: |
[ ! -e ~/.done ] || exit 0
version=$(cat ~/.version)
# The version's section of the changelog, less its heading.
awk -v v="$version" '/^## / { on = ($2 == v); next } on' CHANGELOG.md > ~/.notes
KNOTLESS_PASSWORD="$RELEASE_PASSWORD" knotless publish "$REPO" knotless "$version" target/client/*.tar.gz --notes - < ~/.notes
# Tagged once published, at the commit it was built from, as the
# owner, so a git checkout finds the version by name.
owner=${REPO#knotless://}
KNOTLESS_IDENTIFIER=${owner%%/*} KNOTLESS_PASSWORD="$RELEASE_PASSWORD" knotless tag "$REPO" "v$version" "$KNOTLESS_RUN_SHA"