Files
Khaemhat/.gitea/workflows/ci.yml
T
Alby96andClaude Opus 5.5 5ba28483a8
CI / Build and test (SQLite) (pull_request) Successful in 2m44s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 6s
CI / Docker image (pull_request) Successful in 1m28s
ci: read the login page before grepping it in the image smoke test
The Docker image job failed on main after the M4 merge although the
container was ready: grep -q stops at the first match and closes the pipe,
curl then fails with a write error (exit 23) and pipefail fails the step.
It depends on timing, which is why the same commit passed on the pull
request. The response and the headers are now read into variables first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 13:44:29 +01:00

191 lines
8.0 KiB
YAML

name: CI
# Gitea Actions (ADR 0009). The runner is act_runner in Docker mode on the server that also runs Gitea: one job at a
# time, so the triggers are frugal. The .NET jobs use the SDK image and check out with git (the image has no Node.js
# for JavaScript actions); nothing is cached or uploaded. Builds use BUILD_CPUS cores so the host keeps room for Gitea.
on:
pull_request:
branches: [main]
push:
branches: [main]
tags: ["v*"]
paths-ignore: ["docs/**", "*.md", "assets/**", "deploy/**"]
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
DOTNET_NOLOGO: "1"
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"
BUILD_CPUS: "4"
KHAEMHAT_LICENSE_MODE: test
jobs:
build:
name: Build and test (SQLite)
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:10.0
timeout-minutes: 30
defaults:
run:
shell: bash
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
git log -1 --format='%h %s'
- name: Package allowlist
run: bash scripts/check-packages.sh
- name: Build (warnings are errors)
run: dotnet build Khaemhat.sln -c Release -warnaserror -m:"$BUILD_CPUS"
- name: Test
run: dotnet test Khaemhat.sln -c Release --no-build
# PostgreSQL integration (SPEC §20): only on release tags and manual runs, against the two supported servers.
postgres:
name: PostgreSQL ${{ matrix.pg }} integration
needs: build
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
strategy:
fail-fast: false
matrix:
pg: ["16", "17"]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:10.0
timeout-minutes: 30
services:
postgres:
image: postgres:${{ matrix.pg }}
env:
POSTGRES_USER: khaemhat
POSTGRES_PASSWORD: khaemhat-ci
POSTGRES_DB: khaemhat_test
defaults:
run:
shell: bash
env:
KHAEMHAT_TEST_PG: postgres://khaemhat:khaemhat-ci@postgres:5432/khaemhat_test
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
- name: Test · Data (PostgreSQL)
run: dotnet test tests/Khaemhat.Data.Tests -c Release -m:"$BUILD_CPUS"
# The image builds and answers /health/live (issue #2). The runner's own image has the docker CLI and talks to the
# host's daemon; the job joins a network of its own to reach the container. Everything is labelled with the job
# container's id: a cancelled job skips its clean-up, so the next one removes what a vanished job left on the host.
# Release tags skip it: release.yml builds and tests the same image.
docker:
name: Docker image
needs: build
if: "!startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Remove what cancelled jobs left
run: |
echo "NAME=khaemhat-ci-$(hostname)" >> "$GITHUB_ENV"
for c in $(docker ps -aq --filter label=khaemhat-ci.job); do
job="$(docker inspect -f '{{index .Config.Labels "khaemhat-ci.job"}}' "$c")"
docker inspect "$job" > /dev/null 2>&1 || docker rm -f -v "$c"
done
for n in $(docker network ls -q --filter label=khaemhat-ci.job); do
job="$(docker network inspect -f '{{index .Labels "khaemhat-ci.job"}}' "$n")"
docker inspect "$job" > /dev/null 2>&1 || docker network rm "$n"
done
for i in $(docker image ls -q --filter label=khaemhat-ci.job | sort -u); do
job="$(docker image inspect -f '{{index .Config.Labels "khaemhat-ci.job"}}' "$i")"
docker inspect "$job" > /dev/null 2>&1 || docker image rm -f "$i"
done
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
- name: Build image
run: |
docker build -f docker/Dockerfile --build-arg VERSION=0.0.0-ci --build-arg GIT_SHA="$(git rev-parse --short HEAD)" \
--label khaemhat-ci.job="$(hostname)" -t "$NAME:image" .
- name: Smoke test (start-up, login page, non-root user, PUID/PGID)
run: |
docker network create --label khaemhat-ci.job="$(hostname)" "$NAME"
docker network connect "$NAME" "$(hostname)"
# Since M2 the instance needs a key, a super user and a first company; the key is thrown away with the run.
docker run -d --name "$NAME-app" --network "$NAME" --label khaemhat-ci.job="$(hostname)" \
-e KHAEMHAT_SYSTEM_DB=sqlite:///data/system.db -e KHAEMHAT_LICENSE_MODE=test \
-e KHAEMHAT_SECRET_KEY="$(head -c 32 /dev/urandom | base64)" \
-e KHAEMHAT_SUPERUSER=root -e KHAEMHAT_SUPERUSER_PASSWORD=Ci-Smoke-Test-2026 -e KHAEMHAT_COMPANY_CODE=CI \
-e PUID=99 -e PGID=100 "$NAME:image"
for i in $(seq 1 60); do
if curl -fsS --max-time 5 "http://$NAME-app:8080/health/ready"; then echo; break; fi
sleep 2
done
curl -fsS --max-time 5 "http://$NAME-app:8080/health"
echo
test "$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://$NAME-app:8080/")" = "302"
# Read the whole response first: grep -q closes the pipe at the first match, and with pipefail the
# write error of curl (exit 23) would fail the step depending on timing.
login="$(curl -fsS --max-time 5 "http://$NAME-app:8080/login")"
grep -q "Accedi" <<<"$login"
headers="$(curl -fsS -D - -o /dev/null --max-time 5 "http://$NAME-app:8080/login")"
grep -qi "content-security-policy" <<<"$headers"
test "$(docker exec "$NAME-app" sh -c 'stat -c %u:%g /proc/1')" = "99:100"
test "$(docker exec "$NAME-app" stat -c %u:%g /data)" = "99:100"
docker exec "$NAME-app" pg_dump --version
- name: Container logs and clean-up
if: always()
run: |
docker logs "$NAME-app" || true
docker rm -f -v "$NAME-app" || true
docker network disconnect "$NAME" "$(hostname)" || true
docker network rm "$NAME" || true
docker image rm "$NAME:image" || true
# Gitea fails a workflow that does not parse. The Ruby image has no git: the sources come as an archive.
yaml:
name: YAML check
runs-on: ubuntu-latest
container:
image: ruby:3.3-alpine
timeout-minutes: 10
steps:
- name: Workflows and compose files
env:
TOKEN: ${{ github.token }}
run: |
wget -q --header "Authorization: token $TOKEN" -O /tmp/sources.tar.gz \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/archive/${{ github.sha }}.tar.gz"
mkdir -p /tmp/sources && tar -xzf /tmp/sources.tar.gz -C /tmp/sources
cd /tmp/sources/*/
ruby .gitea/scripts/check-yaml.rb .gitea/workflows/*.yml deploy/*.yml