Skip to content

fix(branch): read branch matrices order- and version-independently #1089

fix(branch): read branch matrices order- and version-independently

fix(branch): read branch matrices order- and version-independently #1089

name: Agrammon backend and models
on:
push:
branches:
- main
tags-ignore:
- '**'
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
raku:
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-24.04
raku-version:
- '2026.04'
runs-on: ${{ matrix.os }}
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: agrammon_test
ports:
- 55432:5432
options: >-
--health-cmd "pg_isready -U postgres -d agrammon_test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Checkout repository first as we need dev/pgpass for PostgreSQL access
- name: Checkout repo
uses: actions/checkout@v4
- name: Load test database
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGPASSFILE: ./dev/pgpass
POSTGRES_DB: postgres
AGRAMMON_DB: agrammon_test
AGRAMMON_OWNER: agrammon
AGRAMMON_GROUP: agrammon_user
AGRAMMON_SCHEMA: ./t/test-data/agrammon.schema.sql
AGRAMMON_TEST_DATA: ./t/test-data/agrammon.test.sql
run: |
chmod 0600 $PGPASSFILE
psql -U $POSTGRES_USER -h localhost --port 55432 -c "CREATE USER $AGRAMMON_OWNER PASSWORD 'agrammon'" > /dev/null
psql -U $POSTGRES_USER -h localhost --port 55432 -c "CREATE ROLE $AGRAMMON_GROUP NOLOGIN" > /dev/null
psql -U $POSTGRES_USER -h localhost --port 55432 -c "GRANT $AGRAMMON_GROUP TO $AGRAMMON_OWNER" > /dev/null
psql -U $POSTGRES_USER -h localhost --port 55432 -c "ALTER DATABASE $AGRAMMON_DB OWNER TO $AGRAMMON_OWNER" > /dev/null
psql -U $AGRAMMON_OWNER -h localhost --port 55432 --file=$AGRAMMON_SCHEMA $AGRAMMON_DB > /dev/null
psql -U $AGRAMMON_OWNER -h localhost --port 55432 --file=$AGRAMMON_TEST_DATA $AGRAMMON_DB > /dev/null
- name: Setup apt cache
uses: actions/cache@v4
id: aptCache
with:
path: |
/var/cache/apt/archives
/var/lib/apt/lists
# Bump the suffix manually when the apt package list below changes.
key: ${{ matrix.os }}-apt-v3
- name: Install system dependencies
run: |
sudo apt update
# fonts-liberation provides "Liberation Sans", the font the typst PDF
# template sets. LaTeX (texlive*) and Inline::Perl5 (libperl-dev) are no
# longer used: PDF export moved to typst, Excel export to the native
# Raku XLSXWriter.
sudo apt-get install -y fonts-liberation
- name: Install typst
run: |
TYPST_VERSION=v0.15.0
curl -sSL -o /tmp/typst.tar.xz \
"https://github.com/typst/typst/releases/download/${TYPST_VERSION}/typst-x86_64-unknown-linux-musl.tar.xz"
tar -xJf /tmp/typst.tar.xz -C /tmp
sudo install -m 0755 /tmp/typst-x86_64-unknown-linux-musl/typst /usr/local/bin/typst
/usr/local/bin/typst --version
- name: Setup raku
uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Setup Raku cache
uses: actions/cache@v4
id: rakuCache
with:
path: .raku
key: ${{ matrix.os }}-${{ matrix.raku-version }}-${{ hashFiles('./dev/META6.json') }}
- name: Install Raku modules
if: steps.rakuCache.outputs.cache-hit != 'true'
run: |
mkdir -p $GITHUB_WORKSPACE/.raku
zef --install-to=inst#$GITHUB_WORKSPACE/.raku --debug --deps-only --/test --test-depends install .
- name: Prepare model cache dir
run: mkdir -p $HOME/.agrammon
- name: Setup model cache
uses: actions/cache@v4
id: modelCache
with:
path: ~/.agrammon
# Key on the actual model sources the tests compile (the old key
# hashed t/test-data/Models/hr-inclNOx*, retired in #642, so it was an
# empty/constant hash → the cache was frozen and every model change
# forced a cold rebuild). Include os + raku-version because ~/.agrammon
# holds platform/compiler-specific precompiled bytecode.
key: AgrammonModels-${{ matrix.os }}-${{ matrix.raku-version }}-${{ hashFiles('share/Models/**', 't/test-data/Models/**') }}
# On a model-cache miss, build the shared ~/.agrammon model cache once
# single-threaded: the parallel test run below must only ever read it, not
# race to build it concurrently. DB tests skip under AGRAMMON_UNIT_TEST, so
# this is just the model-loading warm-up. Skipped when the cache restored.
- name: Warm model cache (cold runs only)
if: steps.modelCache.outputs.cache-hit != 'true'
run: |
AGRAMMON_UNIT_TEST=1 RAKULIB=inst#$GITHUB_WORKSPACE/.raku $GITHUB_WORKSPACE/.raku/bin/prove6 -l t
- name: Run backend tests
run: |
# -j4 matches the GitHub-hosted runner's vCPUs. Tests are parallel-safe:
# DB-backed files use per-process-unique usernames, and the model cache
# is pre-built (restored or warmed above) so it is read-only here.
RAKULIB=inst#$GITHUB_WORKSPACE/.raku $GITHUB_WORKSPACE/.raku/bin/prove6 -l -j4 t