chadtmiller.com/monolith
An atproto PDS
0
0
# Publishes a version of the server once main's version, in Cargo.toml, has
# no release yet and the gates have passed at its commit, as the releases
# docs/guide/getting-started.md names:
#
# - the image, the release of the package `monolith`, named as the
# repository: `docker pull knotless.dev/chadtmiller.com/monolith:<version>`;
# - the binary for Linux x86-64, the release of the package `pds`:
# pds-<version>-x86_64-linux.tar.gz and its .sha256.
#
# Each with the version's CHANGELOG.md section as its notes and the commit
# it was built from; then the commit is tagged `v<version>`. The pages and
# `pds` are built as the Dockerfile builds them, and the image made from the
# binary with no container engine, which this runner's jobs have none of
# (.knotless/image.sh). release-pull.yml keeps a pull open that raises the
# version; once it lands, this publishes it. A version CHANGELOG.md has no
# section for is no release (knope writes one for each), so a pull that
# touches Cargo.toml for another reason publishes nothing. A package with
# that version published already is left alone, so a run that published
# one of them and failed publishes the other when it runs again.
#
# RELEASE_PASSWORD is an app password of the owner's, sealed to this runner
# for pushes to main alone. Asked for on another branch, `knotless run
# rerun knotless://chadtmiller.com/monolith --ref refs/heads/<branch>
# --workflow release`, it builds both and publishes nothing.
image: rust:1.98
runners: [runner.knotless.dev]
on:
push: {refs: [refs/heads/main], paths: [Cargo.toml]}
asked: {refs: [refs/heads/*]}
after: [gates]
superseded: finish
cache: [target, /usr/local/cargo/registry, /usr/local/rustup, /opt/node, /opt/tools, web/node_modules]
secrets: [RELEASE_PASSWORD]
env:
REPO: knotless://chadtmiller.com/monolith
KNOTLESS_APPVIEW: https://knotless.dev
CRANE_VERSION: 0.22.1
CRANE_SHA256: 0ab7a1d6932a213aed964ce97666c3077fe691c8606413674a8b3e0b9ec4cda0
steps:
- name: version
run: |
curl -fsSL https://knotless.dev/install.sh | KNOTLESS_INSTALL_DIR=/usr/local/bin sh
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
echo "$version" > ~/.version
published=""
for package in monolith pds; do
if knotless release list "$REPO" "$package" | cut -f2 | grep -qxF "$version"; then
echo "$package $version is published already"
published="$published $package"
fi
done
echo "$published" > ~/.published
if [ "$published" = " monolith pds" ]; then
touch ~/.done
elif ! grep -q "^## $version " CHANGELOG.md; then
echo "CHANGELOG.md has no section for $version: no release to publish"
[ "$KNOTLESS_RUN_REF" != refs/heads/main ] || touch ~/.done
elif [ "$KNOTLESS_RUN_REF" != refs/heads/main ]; then
echo "on $KNOTLESS_RUN_REF: building $version, publishing nothing"
fi
- uses: chadtmiller.com/steps/node@1
with: {version: 24.22.1}
- uses: chadtmiller.com/steps/npm-ci@1
with: {dir: web}
# The pages, which pds-server embeds, then the server: as the Dockerfile's
# stages build them.
- name: build
run: |
[ ! -e ~/.done ] || exit 0
(cd web && PATH=/opt/node/bin:$PATH npm run build)
cargo build --release --locked -p pds
- name: files
run: |
[ ! -e ~/.done ] || exit 0
version=$(cat ~/.version)
if [ "$(cat /opt/tools/.crane 2>/dev/null)" != "$CRANE_VERSION" ]; then
mkdir -p /opt/tools/bin && cd /tmp
curl -fsSLO "https://github.com/google/go-containerregistry/releases/download/v$CRANE_VERSION/go-containerregistry_Linux_x86_64.tar.gz"
echo "$CRANE_SHA256 go-containerregistry_Linux_x86_64.tar.gz" | sha256sum -c -
tar -xzf go-containerregistry_Linux_x86_64.tar.gz -C /opt/tools/bin crane
echo "$CRANE_VERSION" > /opt/tools/.crane
cd - > /dev/null
fi
command -v jq > /dev/null || { apt-get update -qq && apt-get install -y -qq --no-install-recommends jq > /dev/null; }
rm -rf target/release-files && mkdir -p target/release-files
# The binary and its licenses, as getting-started.md downloads and checks it.
name=pds-$version-x86_64-linux.tar.gz
epoch=$(git log -1 --format=%ct HEAD)
tar -cf - --sort=name --mtime="@$epoch" --owner=0 --group=0 --numeric-owner \
-C target/release pds -C "$PWD" LICENSE-APACHE LICENSE-MIT |
gzip -9n > "target/release-files/$name"
(cd target/release-files && sha256sum "$name" > "$name.sha256" && cat "$name.sha256")
# The image.
PATH=/opt/tools/bin:$PATH SOURCE_DATE_EPOCH=$epoch \
.knotless/image.sh target/release/pds "$version" "$KNOTLESS_RUN_SHA" target/image
- name: publish
on: {refs: [refs/heads/main]}
run: |
[ ! -e ~/.done ] || exit 0
version=$(cat ~/.version)
owner=${REPO#knotless://}
export KNOTLESS_IDENTIFIER=${owner%%/*} KNOTLESS_PASSWORD="$RELEASE_PASSWORD"
# The version's section of the changelog, less its heading.
awk -v v="$version" '/^## / { on = ($2 == v); next } on' CHANGELOG.md > ~/.notes
case "$(cat ~/.published)" in *pds*) ;; *)
knotless release publish "$REPO" pds "$version" target/release-files/* --commit "$KNOTLESS_RUN_SHA" --notes - < ~/.notes ;;
esac
case "$(cat ~/.published)" in *monolith*) ;; *)
knotless release publish "$REPO" monolith "$version" --oci target/image --commit "$KNOTLESS_RUN_SHA" --notes - < ~/.notes ;;
esac
# Tagged once published, at the commit it was built from.
if knotless repo refs "$REPO" | cut -f2 | grep -qxF "refs/tags/v$version"; then
echo "v$version is tagged already"
else
knotless tag create "$REPO" "v$version" "$KNOTLESS_RUN_SHA"
fi