Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/actions/internal/prisma-generate-verify/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Provisions a PostgreSQL container for one Prisma package (monoweb or grades) and fails if committed generated
# artifacts are out of date.

name: Verify Prisma generate
description: Migrate and generate Prisma artifacts for monoweb or grades, then assert generated output matches git.
inputs:
package:
description: Which Prisma package to verify; monoweb (@dotkomonline/db) or grades (@dotkomonline/grades-db)
required: true
runs:
using: composite
steps:
- name: Start PostgreSQL container
shell: bash
env:
PACKAGE: ${{ inputs.package }}
POSTGRES_IMAGE: postgres:16-alpine@sha256:b7587f3cb74f4f4b2a4f9d67f052edbf95eb93f4fec7c5ada3792546caaf7383
run: |
case "$PACKAGE" in
monoweb)
POSTGRES_USER=ow
POSTGRES_PASSWORD=owpassword123
POSTGRES_DB=ow
echo "DATABASE_URL=postgresql://ow:owpassword123@localhost:5432/ow" >> "$GITHUB_ENV"
echo "PNPM_FILTER=@dotkomonline/db" >> "$GITHUB_ENV"
echo "GENERATED_PATH=packages/db/generated" >> "$GITHUB_ENV"
;;
grades)
POSTGRES_USER=grades
POSTGRES_PASSWORD=gradespassword123
POSTGRES_DB=grades
echo "DATABASE_URL=postgresql://grades:gradespassword123@localhost:5432/grades" >> "$GITHUB_ENV"
echo "PNPM_FILTER=@dotkomonline/grades-db" >> "$GITHUB_ENV"
echo "GENERATED_PATH=packages/grades-db/generated" >> "$GITHUB_ENV"
;;
*)
echo "Unknown package: $PACKAGE (expected monoweb or grades)" >&2
exit 1
;;
esac

CONTAINER_NAME="prisma_verify_${PACKAGE}_postgres"
docker rm --force "$CONTAINER_NAME" >/dev/null 2>&1 || true

docker run --detach \
--name "$CONTAINER_NAME" \
--env "POSTGRES_USER=$POSTGRES_USER" \
--env "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" \
--env "POSTGRES_DB=$POSTGRES_DB" \
--publish 5432:5432 \
--health-cmd "pg_isready -U $POSTGRES_USER -d $POSTGRES_DB" \
--health-interval 5s \
--health-timeout 5s \
--health-retries 10 \
Comment on lines +51 to +54
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not using the postgres server on the runner, but use a container? I think this is probably magnitudes slower

"$POSTGRES_IMAGE"

for attempt_number in $(seq 1 30); do
health_status="$(docker inspect --format='{{.State.Health.Status}}' "$CONTAINER_NAME")"
if [ "$health_status" = "healthy" ]; then
exit 0
fi
sleep 2
done

docker logs "$CONTAINER_NAME"
exit 1

- uses: pnpm/action-setup@v2
with:
version: 10.28.2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 22.21.1
cache: 'pnpm'
- name: Install dependencies from pnpm lockfile
shell: bash
run: pnpm install --frozen-lockfile

- name: Apply database migrations
shell: bash
run: pnpm -F "$PNPM_FILTER" prisma migrate deploy

- name: Generate Prisma client and TypedSQL
shell: bash
run: pnpm -F "$PNPM_FILTER" generate

- name: Fail if generated Prisma artifacts are out of date
shell: bash
run: git diff --exit-code "$GENERATED_PATH"
84 changes: 70 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# The main integration pipeline
#
# It is responsible for verifying linting, type checking, and building packages
# in the entire monorepo.
# It is responsible for verifying linting, type checking, testing, and building packages in the entire monorepo.

name: CI & CD
on:
Expand All @@ -14,13 +13,12 @@ on:
- synchronize

permissions:
id-token: write
id-token: write
contents: read

jobs:
# The "check" job is responsible for verifying the minimum requirements to
# build all the packages in the monorepo.
check:
name: Verify build requirements
verify-quality-checks:
name: Lint, type check, and unit tests
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand All @@ -43,15 +41,61 @@ jobs:
- run: pnpm install --frozen-lockfile
name: Install dependencies from pnpm lockfile
- run: pnpm lint-check
name: Run linting and formatting checks
name: Linting and formatting checks
- run: pnpm type-check
name: Run TypeScript type checker
name: TypeScript type checker
- run: pnpm test
name: Unit tests

test-integration:
name: Integration tests
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
- uses: pnpm/action-setup@v2
with:
version: 10.28.2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 22.21.1
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
name: Install dependencies from pnpm lockfile
- run: pnpm test:it
name: Run RPC integration tests

verify-monoweb-prisma-generate:
name: Verify Prisma generate (Monoweb)
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
- uses: ./.github/actions/internal/prisma-generate-verify
with:
package: monoweb

verify-grades-prisma-generate:
name: Verify Prisma generate (Grades)
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
- uses: ./.github/actions/internal/prisma-generate-verify
with:
package: grades

build-dashboard:
name: dashboard
runs-on: ubuntu-24.04-arm
needs:
- check
- verify-quality-checks
- test-integration
- verify-monoweb-prisma-generate
- verify-grades-prisma-generate
steps:
- name: Install local GitHub Actions
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand All @@ -69,7 +113,10 @@ jobs:
name: rpc
runs-on: ubuntu-24.04-arm
needs:
- check
- verify-quality-checks
- test-integration
- verify-monoweb-prisma-generate
- verify-grades-prisma-generate
steps:
- name: Install local GitHub Actions
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand All @@ -87,7 +134,10 @@ jobs:
name: web
runs-on: ubuntu-24.04-arm
needs:
- check
- verify-quality-checks
- test-integration
- verify-monoweb-prisma-generate
- verify-grades-prisma-generate
steps:
- name: Install local GitHub Actions
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand All @@ -105,7 +155,10 @@ jobs:
name: grades-backend
runs-on: ubuntu-24.04-arm
needs:
- check
- verify-quality-checks
- test-integration
- verify-monoweb-prisma-generate
- verify-grades-prisma-generate
steps:
- name: Install local GitHub Actions
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand All @@ -123,7 +176,10 @@ jobs:
name: grades-frontend
runs-on: ubuntu-24.04-arm
needs:
- check
- verify-quality-checks
- test-integration
- verify-monoweb-prisma-generate
- verify-grades-prisma-generate
steps:
- name: Install local GitHub Actions
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand Down
Loading