feat: provide way to build and attach platforms
Pipeline / check (push) Successful in 1m56s
Pipeline / release (push) Skipped
Pipeline / docs (push) Successful in 1m47s
Pipeline / nightly (push) Successful in 6m41s

This commit is contained in:
2026-08-08 11:46:15 -04:00
parent fdc53ae210
commit 3a7a0d5873
12 changed files with 230 additions and 81 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Attach files to an existing Gitea release, found by tag. Re-runnable: an
# asset of the same name is replaced. Use this to add a build CI can't produce
# (e.g., the macOS arm64 bundle, built on a Mac) to a release CI already made.
#
# Required env:
# GITEA_API e.g., https://git.scient.ing/api/v1/repos/<owner>/<repo>
# GITEA_TOKEN a token with contents:write
# TAG the release tag the assets belong to
# ASSETS space-separated list of files to upload
# Optional env:
# JQ jq command (default: jq); on a Mac without jq, set to
# "pixi exec --spec jq -- jq"
set -euo pipefail
: "${GITEA_API:?}"; : "${GITEA_TOKEN:?}"; : "${TAG:?}"; : "${ASSETS:?}"
: "${JQ:=jq}"
auth="Authorization: token ${GITEA_TOKEN}"
rid="$(curl -fsSL -H "$auth" "${GITEA_API}/releases/tags/${TAG}" | $JQ -r '.id')"
[ -n "$rid" ] && [ "$rid" != "null" ] || { echo "no release found for tag ${TAG}" >&2; exit 1; }
for f in $ASSETS; do
n="$(basename "$f")"
for aid in $(curl -fsSL -H "$auth" "${GITEA_API}/releases/${rid}/assets" \
| $JQ -r --arg n "$n" '.[] | select(.name==$n) | .id'); do
curl -fsSL -X DELETE -H "$auth" "${GITEA_API}/releases/${rid}/assets/${aid}" || true
done
echo "uploading $n to release ${TAG}"
curl -fsSL -X POST -H "$auth" -F "attachment=@${f}" \
"${GITEA_API}/releases/${rid}/assets?name=${n}"
done
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Fail unless the release tag matches the crate version.
# Env: TAG (a leading "v" is tolerated). Run from the repository root.
set -euo pipefail
: "${TAG:?set TAG to the tag being released}"
here="$(cd "$(dirname "$0")" && pwd)"
tag="${TAG#v}"
version="$(bash "$here/version.sh")"
if [ "$tag" != "$version" ]; then
echo "tag ${TAG} does not match Cargo.toml version ${version}" >&2
exit 1
fi
echo "tag ${TAG} matches crate version ${version}"
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Build the host-native release bundle and attach it to an existing Gitea
# release. Meant for targets CI cannot build. Check out
# the tagged commit first, so the crate version matches the tag.
#
# Required env: GITEA_API, GITEA_TOKEN (contents:write).
# Optional env: TAG (defaults to the crate version), JQ.
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
: "${GITEA_API:?set GITEA_API, e.g., https://git.scient.ing/api/v1/repos/<owner>/<repo>}"
: "${GITEA_TOKEN:?set GITEA_TOKEN to a token with contents:write}"
version="$(bash "$here/version.sh")"
tag="${TAG:-$version}"
asset="coursebank-${version}-$(bash "$here/platform-tag.sh").tar.gz"
echo "building ${asset} for release ${tag}"
pixi run setup-tools
pixi run dist
bash "$here/package.sh" "$asset" dist
TAG="$tag" ASSETS="$asset $asset.sha256" bash "$here/attach-asset.sh"
echo "done: ${asset} attached to ${tag}"
+6 -1
View File
@@ -2,7 +2,7 @@
# Create (or replace) a Gitea release and upload assets, using the Gitea API.
#
# Required env:
# GITEA_API e.g. https://git.scient.ing/api/v1/repos/<owner>/<repo>
# GITEA_API e.g., https://git.scient.ing/api/v1/repos/<owner>/<repo>
# GITEA_TOKEN a token with contents:write
# TAG the release tag
# ASSETS space-separated list of files to attach
@@ -14,7 +14,9 @@
# TARGET_COMMITISH (default: empty; Gitea uses the default branch)
# JQ jq command (default: jq); set to e.g. "pixi exec --spec jq -- jq"
# DRY_RUN set to anything to print actions instead of calling the API
set -euo pipefail
: "${GITEA_API:?}"; : "${GITEA_TOKEN:?}"; : "${TAG:?}"; : "${ASSETS:?}"
: "${JQ:=jq}"
name="${RELEASE_NAME:-$TAG}"
@@ -24,6 +26,7 @@ replace="${REPLACE:-false}"
target="${TARGET_COMMITISH:-}"
auth="Authorization: token ${GITEA_TOKEN}"
dry="${DRY_RUN:-}"
say() { echo "[gitea-release] $*"; }
if [ "$replace" = "true" ]; then
@@ -66,4 +69,6 @@ for f in $ASSETS; do
"${GITEA_API}/releases/${rid}/assets?name=${n}"
fi
done
say "done"
+5 -3
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# Print an auto-generated nightly version string derived from git history:
#
# <last-release-tag>+<commits-since>.g<short-sha> e.g., 26.8.0+14.gb1a2c3d4
@@ -12,14 +13,15 @@
# and never sorts ahead of the release it is based on. Needs full history and
# tags (check out with fetch-depth: 0 and fetch-tags: true). Release tags are
# matched as N.N.N; the moving `nightly` tag is ignored.
set -euo pipefail
sha="$(git rev-parse --short=8 HEAD)"
if desc="$(git describe --tags --long \
--match '[0-9]*.[0-9]*.[0-9]*' --exclude nightly 2>/dev/null)"; then
# desc is <tag>-<n>-g<hash>; the tag itself has no '-', so strip from the right.
rest="${desc%-g*}" # <tag>-<n>
n="${rest##*-}" # <n>
tag="${rest%-*}" # <tag>
rest="${desc%-g*}"
n="${rest##*-}"
tag="${rest%-*}"
echo "${tag}+${n}.g${sha}"
else
n="$(git rev-list --count HEAD)"
+4
View File
@@ -1,9 +1,13 @@
#!/usr/bin/env bash
# Tar the contents of a directory into an asset and write its checksum.
# Usage: package.sh <asset.tar.gz> <dir>
set -euo pipefail
asset="${1:?usage: package.sh <asset.tar.gz> <dir>}"
dir="${2:?usage: package.sh <asset.tar.gz> <dir>}"
tar -czf "$asset" -C "$dir" .
sha256sum "$asset" > "$asset.sha256"
echo "packaged $asset ($(wc -c < "$asset") bytes) and $asset.sha256"
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Print a short platform tag for asset names, derived from the host:
# linux-x64, linux-arm64, macos-arm64, macos-x64, ...
set -euo pipefail
case "$(uname -s)" in
Linux) os=linux ;;
Darwin) os=macos ;;
*) os="$(uname -s | tr '[:upper:]' '[:lower:]')" ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch=x64 ;;
aarch64|arm64) arch=arm64 ;;
*) arch="$(uname -m)" ;;
esac
echo "${os}-${arch}"
+5
View File
@@ -3,13 +3,18 @@
# rustdoc serves the crate under <crate>/, so the target includes that segment.
# Env: WWW_ROOT (default /srv/www), SITE_SLUG (default coursebank),
# CRATE (default coursebank).
set -euo pipefail
root="${WWW_ROOT:-/srv/www}/${SITE_SLUG:-coursebank}"
crate="${CRATE:-coursebank}"
if [ -e "$root/release/$crate/index.html" ]; then
target="release/$crate/"
else
target="nightly/$crate/"
fi
printf '%s\n' "<!doctype html><meta http-equiv=\"refresh\" content=\"0; url=${target}\">" > "$root/index.html"
echo "site root -> $target"