220 lines
8.5 KiB
YAML
220 lines
8.5 KiB
YAML
name: ci
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
# Nachts alles auf main. Gestaffelt mit den anderen Apps auf dem einen
|
|
# Runner (Relay 05:30, Rocket 06:00, Insilo 06:30 MESZ): Lunch 07:00 MESZ.
|
|
# Der Cron ist UTC.
|
|
schedule:
|
|
- cron: "0 5 * * *"
|
|
workflow_dispatch:
|
|
|
|
# Ein neuer Push in einen PR ersetzt seinen älteren Lauf.
|
|
concurrency:
|
|
group: ci-${{ github.head_ref || github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
chart:
|
|
name: olares chart · sanity
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# get.helm.sh ist vom Gitea-Runner nicht erreichbar: Helm liegt als
|
|
# Release-Anhang in aimighty/ci-tools, get.helm.sh bleibt Rückfall.
|
|
- name: install helm 3.16.2
|
|
run: |
|
|
for url in \
|
|
"https://git.aimighty.olares.de/aimighty/ci-tools/releases/download/helm-3.16.2/helm-v3.16.2-linux-amd64.tar.gz" \
|
|
"https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz"; do
|
|
echo "hole $url"
|
|
if curl -fsSL --retry 3 --retry-all-errors --max-time 180 -o /tmp/helm.tgz "$url" \
|
|
&& tar -tzf /tmp/helm.tgz >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
done
|
|
tar -C /tmp -xzf /tmp/helm.tgz
|
|
install -m 0755 /tmp/linux-amd64/helm /usr/local/bin/helm
|
|
helm version --short
|
|
|
|
- name: codified Olares lessons (scripts/check-chart.sh)
|
|
run: bash scripts/check-chart.sh
|
|
|
|
app:
|
|
name: app · types + tests + build
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres:16
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
# Kein ports: — auf Gitea läuft der Job in einem Container neben dem
|
|
# Dienst und erreicht ihn über dessen Namen (Muster aimighty/rocket).
|
|
options: >-
|
|
--health-cmd "pg_isready -U postgres"
|
|
--health-interval 5s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: database host
|
|
run: |
|
|
if getent hosts postgres >/dev/null 2>&1; then H=postgres; else H=localhost; fi
|
|
echo "PGHOST=$H" >> "$GITHUB_ENV"
|
|
echo "DB_HOST=$H" >> "$GITHUB_ENV"
|
|
echo "TEST_DATABASE_URL=postgres://lunch:lunch_dev_only@$H/lunch" >> "$GITHUB_ENV"
|
|
echo "Datenbank unter $H"
|
|
|
|
- name: psql
|
|
run: |
|
|
command -v psql >/dev/null && { psql --version; exit 0; }
|
|
SUDO=""; [ "$(id -u)" != "0" ] && command -v sudo >/dev/null && SUDO="sudo"
|
|
$SUDO apt-get update -qq
|
|
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq postgresql-client
|
|
psql --version
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "22"
|
|
cache: "npm"
|
|
|
|
- name: install
|
|
run: npm ci
|
|
|
|
- name: type-check
|
|
run: npm run type-check
|
|
|
|
# Wie auf der Box: Die Migrationen laufen mit der Rolle der App, die
|
|
# (createdb nur für die eigene Datenbank von tests/backup.test.ts)
|
|
# dadurch Eigentümerin der Tabellen wird — kein Superuser. Nur so prüft
|
|
# der Test mit zwei Haushalten, dass FORCE ROW LEVEL SECURITY greift.
|
|
- name: database and migrations
|
|
run: |
|
|
PGPASSWORD=postgres psql -U postgres -c "create role lunch login password 'lunch_dev_only' createdb;"
|
|
PGPASSWORD=postgres psql -U postgres -c "create database lunch owner lunch;"
|
|
DATABASE_URL="$TEST_DATABASE_URL" MIGRATE_ATTEMPTS=3 npm run migrate
|
|
# Ein zweiter Lauf darf nichts tun.
|
|
DATABASE_URL="$TEST_DATABASE_URL" MIGRATE_ATTEMPTS=3 npm run migrate
|
|
|
|
- name: unit and database tests
|
|
run: npm test
|
|
|
|
- name: build
|
|
run: npm run build
|
|
env:
|
|
NEXT_TELEMETRY_DISABLED: "1"
|
|
|
|
# Der Browser: Ablauf einer Familie am iPhone (einrichten, einladen, anmelden,
|
|
# Gerät, entfernen, Rückweg) und der Rundgang über jede Seite am iPhone hell
|
|
# und dunkel und am Desktop (Überbreite, Ziele unter 44 px, axe, Skriptfehler).
|
|
oberflaeche:
|
|
name: oberfläche · Browser am iPhone
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
services:
|
|
postgres:
|
|
image: postgres:16
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
options: >-
|
|
--health-cmd "pg_isready -U postgres"
|
|
--health-interval 5s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
env:
|
|
NEXT_TELEMETRY_DISABLED: "1"
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: database host
|
|
run: |
|
|
if getent hosts postgres >/dev/null 2>&1; then H=postgres; else H=localhost; fi
|
|
echo "PGHOST=$H" >> "$GITHUB_ENV"
|
|
echo "DATABASE_URL=postgres://lunch:lunch_dev_only@$H/lunch" >> "$GITHUB_ENV"
|
|
|
|
- name: psql
|
|
run: |
|
|
command -v psql >/dev/null && exit 0
|
|
SUDO=""; [ "$(id -u)" != "0" ] && command -v sudo >/dev/null && SUDO="sudo"
|
|
$SUDO apt-get update -qq
|
|
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq postgresql-client
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "22"
|
|
cache: "npm"
|
|
|
|
- name: install, migrate, build, start
|
|
run: |
|
|
npm ci
|
|
PGPASSWORD=postgres psql -U postgres -c "create role lunch login password 'lunch_dev_only';"
|
|
PGPASSWORD=postgres psql -U postgres -c "create database lunch owner lunch;"
|
|
MIGRATE_ATTEMPTS=3 npm run migrate
|
|
npm run build
|
|
cp -r public .next/standalone/ && cp -r .next/static .next/standalone/.next/
|
|
mkdir -p "$RUNNER_TEMP/lunchdaten"
|
|
echo "LUNCH_DATA=$RUNNER_TEMP/lunchdaten" >> "$GITHUB_ENV"
|
|
# HOSTNAME: Next bindet sich daran; im Container ist es die Kennung des Containers.
|
|
(cd .next/standalone && HOSTNAME=0.0.0.0 PORT=3020 BACKUP_DISABLED=1 IMPORT_TEST_ORIGIN=http://127.0.0.1:3021 APP_DATA_DIR="$RUNNER_TEMP/lunchdaten" MAIL_TEST_DIR="$RUNNER_TEMP/lunchdaten/mails" \
|
|
nohup node server.js > "$RUNNER_TEMP/server.log" 2>&1 &)
|
|
for i in $(seq 30); do curl -sf localhost:3020/api/ready && exit 0; sleep 1; done
|
|
cat "$RUNNER_TEMP/server.log"; exit 1
|
|
|
|
# Der Browser: Der Runner erreicht cdn.playwright.dev nicht. Die Chromium
|
|
# Headless Shell, die Playwright 1.63 braucht (Revision 1243), liegt
|
|
# deshalb in aimighty/ci-tools (drei Teile, Prüfsumme). Systembibliotheken
|
|
# kommen per apt (install-deps). Bei einem neuen Playwright: neue
|
|
# Revision dort ablegen und hier eintragen.
|
|
- name: playwright version
|
|
id: pw
|
|
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> "$GITHUB_OUTPUT"
|
|
|
|
- uses: actions/cache@v4
|
|
id: pwcache
|
|
with:
|
|
path: ~/.cache/ms-playwright
|
|
key: playwright-headless-2-${{ runner.os }}-${{ steps.pw.outputs.version }}
|
|
|
|
- name: install browser (from aimighty/ci-tools)
|
|
if: steps.pwcache.outputs.cache-hit != 'true'
|
|
timeout-minutes: 15
|
|
run: |
|
|
BASE=https://git.aimighty.olares.de/aimighty/ci-tools/releases/download/playwright-chromium-1243
|
|
F=playwright-headless-shell-1243-linux64.tar.gz
|
|
for i in 0 1 2; do curl -fsSL --retry 3 --retry-all-errors --max-time 600 -o "/tmp/$F.part$i" "$BASE/$F.part$i"; done
|
|
cat /tmp/$F.part0 /tmp/$F.part1 /tmp/$F.part2 > /tmp/$F
|
|
echo "8cc010f5e06f7fd95a97cee5d3a6b2abf67b7144f5b47d86413b7508d9c02797 /tmp/$F" | sha256sum -c -
|
|
mkdir -p ~/.cache/ms-playwright
|
|
tar -xzf /tmp/$F -C ~/.cache/ms-playwright
|
|
# Im Archiv ist chrome-headless-shell ein Startskript, das auf einen
|
|
# festen Pfad der Werkstatt zeigt; hier gilt die Datei daneben.
|
|
D=~/.cache/ms-playwright/chromium_headless_shell-1243/chrome-headless-shell-linux64
|
|
if [ -f "$D/chrome-headless-shell.real" ]; then mv -f "$D/chrome-headless-shell.real" "$D/chrome-headless-shell"; fi
|
|
"$D/chrome-headless-shell" --version || true
|
|
|
|
- name: system libraries for the browser
|
|
timeout-minutes: 15
|
|
run: npx playwright install-deps chromium
|
|
|
|
- name: browser tests
|
|
run: npx playwright test
|
|
env:
|
|
LUNCH_URL: http://localhost:3020
|
|
IMPORT_TEST_ORIGIN: http://127.0.0.1:3021
|
|
|
|
- name: server log on failure
|
|
if: failure()
|
|
run: tail -80 "$RUNNER_TEMP/server.log" || true
|
|
|
|
- uses: actions/upload-artifact@v4
|
|
if: failure()
|
|
with:
|
|
name: browser-report
|
|
path: |
|
|
e2e-bericht
|
|
test-results
|
|
retention-days: 7
|