artifacts: - cover.out - bench.txt environment: APK_REPO: alpine/v3.22/bigbes/x86_64 ARTIFACTS_CHANNEL: ~bigbes/main ARTIFACTS_DIST: v3.22 ARTIFACTS_ENDPOINT: https://artifacts.srht.bigb.es BENCH_ORIGIN: https://bench.srht.bigb.es BENCH_REPO: ~bigbes/sr-ht-cover BOOTSTRAP_REV: 779ad9f174ea5ab7e755f6df0ec9e5912d67dd16 BUILD_SUBMITTER: git.sr.ht CORE_VER: 0.84.7 COVER_ORIGIN: https://cov.srht.bigb.es COVER_REPO: ~bigbes/sr-ht-cover GIT_REF: refs/heads/master REPO: sr-ht-cover S3_BUCKET: repo S3_ENDPOINT: https://s3.bigb.es image: alpine/edge packages: - abuild - curl - go - git - rclone - sassc - minify - postgresql - postgresql-client secrets: - apk-ci-s3 - 7dde4219-0783-4581-a67d-c94749de3600 - 0e5b3530-6f19-4f30-9b73-9339dd382e46 - c7968415-1a6d-4ca0-a188-150fb7f57b65 sources: - "https://git.srht.bigb.es/~bigbes/sr-ht-cover#2aabf11a3e7568afbf5a116e153dcfd6e61caa38" submitter: git.sr.ht: allow-refs: - refs/heads/master - refs/tags/v* tasks: - cacher_install: | curl -sSL https://bigbes.pages.srht.bigb.es/ci-cacher/install.sh | sh - cacher_init: | cacher init \ --endpoint https://s3.bigb.es \ --region garage \ --bucket docker-cache \ --prefix sr-ht-cover/deps \ --key-file ~/.s3-cache-key-id \ --secret-file ~/.s3-cache-key-secret - scss: | # Assemble the shared sourcehut partials no apk ships, cached by the two # pins so upstream outages can't fail us. --exec runs on a miss and seeds # the cache after; it sees exported vars only, hence the inline key. # See docs/ci.md#scss. cacher dir download "scss/${CORE_VER}-${BOOTSTRAP_REV}.tar.zst" ~/scss --exec ' git clone --depth 1 --branch "$CORE_VER" \ https://git.sr.ht/~sircmpwn/core.sr.ht /tmp/core mkdir -p ~/scss/bootstrap cp /tmp/core/scss/*.scss /tmp/core/scss/*.css ~/scss/ git init -q /tmp/bootstrap git -C /tmp/bootstrap remote add origin https://github.com/twbs/bootstrap git -C /tmp/bootstrap fetch -q --depth 1 origin "$BOOTSTRAP_REV" git -C /tmp/bootstrap checkout -q FETCH_HEAD cp -r /tmp/bootstrap/scss ~/scss/bootstrap/scss ' sudo mkdir -p /usr/share/sourcehut sudo cp -r ~/scss /usr/share/sourcehut/scss - keygen: | # Throwaway signing key, and -i is not optional: docs/ci.md#keygen. SUDO=sudo abuild-keygen -a -n -i -q - version: | # ONE `git describe` decides both numbers: $ver is the apk pkgver (a tag, # else tag_git, else the family's commit count), $desc is the string # linked into the binaries. Both are EXPORTED and never sed-ed into the # APKBUILD (which reads $PKGVER): rewriting a tracked file flips the VCS # stamp Go puts in the binary to dirty. Do not "tidy" this back into a # sed. The tree is printed on the last line because this is the last # moment it is provably clean. All of it: docs/ci.md#version. cd "$REPO" desc=$(git describe --tags --always --dirty) base=${desc%-dirty} case "$base" in v*-g*) n=${base%-g*}; ver="${n%-*}"; ver="${ver#v}_git${n##*-}" ;; v*) ver="${base#v}" ;; *) ver="0.0.$(git rev-list --count HEAD)" ;; esac echo "export PKGVER=$ver SRHT_VERSION=$desc" >> ~/.buildenv echo "building $ver from $desc" git status --porcelain - cache_restore: | # Go module and build caches keyed by go.sum; --optional makes a miss a # cold build, not an error. abuild re-pins both (docs/ci.md#cache_restore). KEY_MOD=$(cacher key "gomod/{hash}.tar.zst" --hash-from "$REPO/go.sum") KEY_GOC=$(cacher key "gocache/{hash}.tar.zst" --hash-from "$REPO/go.sum") echo "export KEY_MOD=$KEY_MOD KEY_GOC=$KEY_GOC" >> ~/.buildenv cacher dir download "$KEY_MOD" ~/go/pkg/mod --optional cacher dir download "$KEY_GOC" ~/.cache/go-build --optional # Repair block for the HALF-restored module cache — the normal failure # here, not a freak one, and it reads like a code bug (build #284). # Do not remove and do not soften to `|| true`: # docs/ci.md#the-half-restored-module-cache. cd "$REPO" chmod -R u+w ~/go/pkg/mod 2>/dev/null || true if ! go mod verify >/dev/null 2>&1; then echo "restored module cache did not verify — discarding it" rm -rf ~/go/pkg/mod fi # `go mod download`, NOT `go mod download all`: the `all` pattern APPENDS # dependencies' test-only hashes to go.sum — 157 lines in this repo, # measured — which leaves a modified TRACKED file in the checkout for # `go build` to stamp the binary dirty with. bench's build #359 failed # check-version on exactly that. Without `all` go.sum is untouched and # `go mod verify` still passes. docs/ci.md#go-mod-download-never-go-mod-download-all. go mod download go mod verify - postgres: | # SPEC ch. 15's open question 7, answered: a real Postgres in the VM. # Measured: db/ covers 12.6% of statements without it, 87.4% with it. # See docs/ci.md#postgres. sudo install -d -o postgres -g postgres /run/postgresql /var/lib/postgresql/data sudo -u postgres initdb -D /var/lib/postgresql/data sudo -u postgres pg_ctl -D /var/lib/postgresql/data -l /tmp/pg.log -w start \ -o "-k /run/postgresql -h 127.0.0.1 \ -c fsync=off -c full_page_writes=off -c synchronous_commit=off" sudo -u postgres createuser -s "$(id -un)" sudo -u postgres createdb -O "$(id -un)" coversrht_test echo "export COVERSRHT_TEST_PG='postgresql://$(id -un)@127.0.0.1/coversrht_test?sslmode=disable'" \ >> ~/.buildenv - test: | cd "$REPO" # An empty DSN would skip every database suite and leave the build green # over untested code — that is the 12.6% vs 87.4% gap. docs/ci.md#test. if [ -z "$COVERSRHT_TEST_PG" ]; then echo "COVERSRHT_TEST_PG is unset: the postgres task did not export it," >&2 echo "so every database suite would skip and this build would lie." >&2 exit 1 fi # -covermode=atomic (real hit counts) and $HOME (that is where artifacts: # looks, and abuild packages this checkout in place). docs/ci.md#test. go test -covermode=atomic -coverprofile="$HOME/cover.out" ./... go tool cover -func="$HOME/cover.out" | tail -1 - build: | cd "$REPO" # -d: makedepends come from `packages:`. See docs/ci.md#build. REPODEST=$HOME/packages abuild -d find "$HOME/packages" -name '*.apk' - publish: | set +x # never echo the S3 credentials into the build log . ~/.apk-ci.env export RCLONE_CONFIG_GARAGE_TYPE=s3 export RCLONE_CONFIG_GARAGE_PROVIDER=Other export RCLONE_CONFIG_GARAGE_ENDPOINT="$S3_ENDPOINT" export RCLONE_CONFIG_GARAGE_REGION=garage export RCLONE_CONFIG_GARAGE_FORCE_PATH_STYLE=true export RCLONE_CONFIG_GARAGE_ACCESS_KEY_ID="$APK_CI_S3_ACCESS_KEY" export RCLONE_CONFIG_GARAGE_SECRET_ACCESS_KEY="$APK_CI_S3_SECRET_KEY" set -x # Upload only, never delete. See docs/ci.md#publish. find "$HOME/packages" -name '*.apk' -print | while read -r f; do rclone copyto "$f" "garage:$S3_BUCKET/$APK_REPO/$(basename "$f")" echo "uploaded $(basename "$f")" done echo "published; apk-mirror on phoebe re-indexes within 15 minutes" - publish_artifacts: | # The same apk into the artifacts.sr.ht channel, beside the S3 copy above. # The two destinations are independent on purpose: S3 is the road phoebe # still walks, this one is the road being opened. Its failure is its own, # and it never rolls back the upload that already succeeded. # See docs/ci.md#publish_artifacts. if [ ! -r ~/.srht-token ]; then echo "no ~/.srht-token: nothing was published to artifacts.sr.ht" exit 0 fi count=$(find "$HOME/packages" -name '*.apk' | wc -l) test "$count" -gt 0 || { echo "no .apk under $HOME/packages" >&2; exit 1; } url="$ARTIFACTS_ENDPOINT/api/v1/pkg/$ARTIFACTS_CHANNEL/apk/$ARTIFACTS_DIST" # A `find | while read` would run the body in a subshell under ash and # lose $failed with it, so the loop reads a word list instead. failed= for file in $(find "$HOME/packages" -name '*.apk'); do set +x # the token must not reach the log code=$(curl -sS -o /tmp/artifacts.out -w '%{http_code}' -X PUT \ -H "Authorization: Bearer $(cat ~/.srht-token)" \ --data-binary "@$file" "$url") set -x case "$code" in 200|201) echo "published $(basename "$file") -> $code" ;; 409) # Same version, other bytes. abuild stamps mtimes into the archive, # so resubmitting one commit builds a byte-different apk under the # same pkgver; the published copy stands and the build stays green. echo "WARNING: $(basename "$file") already published with other bytes; kept the published copy" ;; *) echo "FAILED $(basename "$file") -> $code" >&2 cat /tmp/artifacts.out >&2 echo >&2 failed=1 ;; esac done test -z "$failed" || exit 1 echo "index: $ARTIFACTS_ENDPOINT/$ARTIFACTS_CHANNEL/apk/$ARTIFACTS_DIST/x86_64/APKINDEX.tar.gz" - cache_save: | # AFTER publish so an S3 hiccup cannot strand a good apk, and fatal on # purpose. Without --force an upload skips a key already there, so the # old `exists ||` guard was dead code. See docs/ci.md#cache_save. cacher dir upload "$KEY_MOD" ~/go/pkg/mod cacher dir upload "$KEY_GOC" ~/.cache/go-build - bench: | # The other half of the dogfooding cross (SPEC ch. 13): this service's own # benchmarks, uploaded to bench.sr.ht. Before coverage and not after, # because that one is this service's own and stays last. docs/ci.md#bench. cd "$REPO" # BenchmarkTrend needs a database and SKIPS without the DSN, printing no # line at all, so the test task's guard stands here too. # docs/ci.md#the-dsn-guard-and-the-two-greps. if [ -z "$COVERSRHT_TEST_PG" ]; then echo "COVERSRHT_TEST_PG is unset: BenchmarkTrend would skip silently," >&2 echo "and this build would upload part of a file without saying so." >&2 exit 1 fi # A redirect and a cat and NOT `| tee`, which would hand the task tee's # exit status. $HOME is where artifacts look. docs/ci.md#bench. make -s bench > "$HOME/bench.txt" cat "$HOME/bench.txt" # One name per package with benchmarks in it: `go test -bench` matching # nothing prints ok and exits 0, and an empty file is valid benchfmt, so # without these the build would upload nothing and report success. # docs/ci.md#the-dsn-guard-and-the-two-greps. grep -q '^BenchmarkParse' "$HOME/bench.txt" grep -q '^BenchmarkTrend' "$HOME/bench.txt" if [ ! -r ~/.srht-token ]; then echo "no ~/.srht-token: this build has no bench.sr.ht credentials" echo "the benchmarks ran and are above; nothing was uploaded" exit 0 fi # GIT_REF is absent on a manual build and ref is optional; key is the # idempotency key; visibility acts only on the POST that creates # $BENCH_REPO. Both prefixes: this pipeline builds tags too. # docs/ci.md#the-bench-request. ref="${GIT_REF#refs/heads/}"; ref="${ref#refs/tags/}" url="$BENCH_ORIGIN/api/v1/repos/$BENCH_REPO/runs" url="$url?commit=$(git rev-parse HEAD)&ref=$ref&key=$JOB_ID&job_url=$JOB_URL" url="$url&visibility=public" echo "uploading bench.txt to $url" # Tracing off to the end: the header must not reach the log. set +x curl -sS --fail-with-body -X POST \ -H "Authorization: Bearer $(cat ~/.srht-token)" \ --data-binary "@$HOME/bench.txt" \ "$url" echo - coverage: | # Dogfooding (SPEC ch. 13), LIVE: the instance is deployed and the token # secret is listed above. The guard below now only covers a build running # without secrets (a manual submission that did not ask for them); with # the file present the upload is fatal on purpose, and this task is last # on purpose. See docs/ci.md#coverage. cd "$REPO" if [ ! -r ~/.srht-token ]; then echo "no ~/.srht-token: this build runs without secrets (see docs/ci.md#coverage)" echo "the profile is still available as this build's cover.out artifact" exit 0 fi # GIT_REF is absent on a manually submitted build; ref is optional for the # API. key is SPEC ch. 4's idempotency key. docs/ci.md#the-request. # Both prefixes are stripped: this pipeline builds tags too, and a tag # build would otherwise report ref=refs/tags/v0.10.0. ref="${GIT_REF#refs/heads/}" ref="${ref#refs/tags/}" url="$COVER_ORIGIN/api/v1/repos/$COVER_REPO/reports" url="$url?commit=$(git rev-parse HEAD)&ref=$ref&key=$JOB_ID&job_url=$JOB_URL" echo "uploading cover.out to $url" # Tracing off to the end: the Authorization header must not reach the log. # No Content-Type (the service sniffs); --fail-with-body prints the JSON # error and still exits non-zero. docs/ci.md#the-request. set +x curl -sS --fail-with-body -X POST \ -H "Authorization: Bearer $(cat ~/.srht-token)" \ --data-binary "@$HOME/cover.out" \ "$url" echo