-
Notifications
You must be signed in to change notification settings - Fork 9
Add test and generate actions #3221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brage-andreas
wants to merge
3
commits into
fix-deploy-dependance-on-lint
Choose a base branch
from
add-setup-database-action
base: fix-deploy-dependance-on-lint
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
.github/actions/internal/prisma-generate-verify/action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 \ | ||
| "$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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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