feat: add GitHub Action to check Prisma migrations match schema (#26897)
* feat: add GitHub Action to check Prisma migrations match schema Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * refactor: use CI_DATABASE_URL secret instead of hardcoded URL Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * test: add test field to verify prisma migration check workflow Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: use git-based check for prisma changes to bypass paths-filter issue Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * feat: add migration for test field to verify prisma migration check workflow Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * chore: revert test field and migration after verifying workflow Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: split paths-filter into two actions to fix predicate-quantifier issue Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: rename has_companion to has-companion for consistent naming Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: update steps.filter references to steps.filter-exclusions Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
joe@cal.com
Devin AI
parent
c0302bfc51
commit
463987c02d
@@ -0,0 +1,41 @@
|
||||
name: Check Prisma Migrations
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
env:
|
||||
DATABASE_URL: ${{ secrets.CI_DATABASE_URL }}
|
||||
|
||||
jobs:
|
||||
check-prisma-migrations:
|
||||
name: Check migrations match schema
|
||||
runs-on: blacksmith-2vcpu-ubuntu-2404
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
credentials:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: calendso
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
sparse-checkout: .github
|
||||
- uses: ./.github/actions/cache-checkout
|
||||
- uses: ./.github/actions/yarn-install
|
||||
- name: Check if migrations match schema
|
||||
working-directory: packages/prisma
|
||||
run: |
|
||||
npx prisma migrate diff --exit-code \
|
||||
--from-migrations ./migrations \
|
||||
--to-schema-datamodel ./schema.prisma \
|
||||
--shadow-database-url ${{ env.DATABASE_URL }}
|
||||
+29
-10
@@ -166,9 +166,10 @@ jobs:
|
||||
permissions:
|
||||
pull-requests: read
|
||||
outputs:
|
||||
has-files-requiring-all-checks: ${{ steps.filter.outputs.has-files-requiring-all-checks }}
|
||||
has_companion: ${{ steps.filter.outputs.has_companion }}
|
||||
has-api-v2-changes: ${{ steps.filter.outputs.has-api-v2-changes }}
|
||||
has-files-requiring-all-checks: ${{ steps.filter-exclusions.outputs.has-files-requiring-all-checks }}
|
||||
has-companion: ${{ steps.filter-inclusions.outputs.has-companion }}
|
||||
has-api-v2-changes: ${{ steps.filter-inclusions.outputs.has-api-v2-changes }}
|
||||
has-prisma-changes: ${{ steps.filter-inclusions.outputs.has-prisma-changes }}
|
||||
commit-sha: ${{ steps.get_sha.outputs.commit-sha }}
|
||||
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' }}
|
||||
db-cache-hit: ${{ steps.cache-db-check.outputs.cache-hit }}
|
||||
@@ -187,8 +188,9 @@ jobs:
|
||||
path: backups/backup.sql
|
||||
key: ${{ steps.cache-db-key.outputs.key }}
|
||||
lookup-only: true
|
||||
- uses: dorny/paths-filter@v3
|
||||
id: filter
|
||||
- name: Check for files requiring all checks (with exclusions)
|
||||
uses: dorny/paths-filter@v3
|
||||
id: filter-exclusions
|
||||
with:
|
||||
predicate-quantifier: "every"
|
||||
filters: |
|
||||
@@ -203,7 +205,12 @@ jobs:
|
||||
- '!help/**'
|
||||
- '!apps/web/public/static/locales/**/common.json'
|
||||
- '!i18n.lock'
|
||||
has_companion:
|
||||
- name: Check for specific path changes
|
||||
uses: dorny/paths-filter@v3
|
||||
id: filter-inclusions
|
||||
with:
|
||||
filters: |
|
||||
has-companion:
|
||||
- "companion/**"
|
||||
has-api-v2-changes:
|
||||
- "apps/api/v2/**"
|
||||
@@ -215,6 +222,9 @@ jobs:
|
||||
- "packages/trpc/**"
|
||||
- "packages/prisma/schema.prisma"
|
||||
- "docs/api-reference/v2/**"
|
||||
has-prisma-changes:
|
||||
- "packages/prisma/schema.prisma"
|
||||
- "packages/prisma/migrations/**"
|
||||
- name: Get Latest Commit SHA
|
||||
id: get_sha
|
||||
run: |
|
||||
@@ -280,11 +290,11 @@ jobs:
|
||||
console.log('Found the label?', labelFound);
|
||||
core.setOutput('run-e2e', labelFound);
|
||||
- uses: ./.github/actions/yarn-install
|
||||
if: ${{ steps.filter.outputs.has-files-requiring-all-checks == 'true' }}
|
||||
if: ${{ steps.filter-exclusions.outputs.has-files-requiring-all-checks == 'true' }}
|
||||
with:
|
||||
skip-install-if-cache-hit: "true"
|
||||
- uses: ./.github/actions/yarn-playwright-install
|
||||
if: ${{ steps.filter.outputs.has-files-requiring-all-checks == 'true' }}
|
||||
if: ${{ steps.filter-exclusions.outputs.has-files-requiring-all-checks == 'true' }}
|
||||
with:
|
||||
skip-install-if-cache-hit: "true"
|
||||
|
||||
@@ -316,6 +326,13 @@ jobs:
|
||||
uses: ./.github/workflows/api-v2-unit-tests.yml
|
||||
secrets: inherit
|
||||
|
||||
check-prisma-migrations:
|
||||
name: Check Prisma Migrations
|
||||
needs: [prepare]
|
||||
if: ${{ needs.prepare.outputs.has-prisma-changes == 'true' }}
|
||||
uses: ./.github/workflows/check-prisma-migrations.yml
|
||||
secrets: inherit
|
||||
|
||||
setup-db:
|
||||
name: Setup Database
|
||||
needs: [prepare]
|
||||
@@ -356,7 +373,7 @@ jobs:
|
||||
build-companion:
|
||||
name: Companion builds
|
||||
needs: [prepare]
|
||||
if: needs.prepare.outputs.has_companion == 'true'
|
||||
if: needs.prepare.outputs.has-companion == 'true'
|
||||
uses: ./.github/workflows/companion-build.yml
|
||||
secrets: inherit
|
||||
|
||||
@@ -432,6 +449,7 @@ jobs:
|
||||
unit-test,
|
||||
api-v2-unit-test,
|
||||
check-api-v2-breaking-changes,
|
||||
check-prisma-migrations,
|
||||
integration-test,
|
||||
build,
|
||||
build-api-v1,
|
||||
@@ -471,6 +489,7 @@ jobs:
|
||||
needs.unit-test.result != 'success' ||
|
||||
needs.api-v2-unit-test.result != 'success' ||
|
||||
(needs.prepare.outputs.has-api-v2-changes == 'true' && needs.check-api-v2-breaking-changes.result != 'success') ||
|
||||
(needs.prepare.outputs.has-prisma-changes == 'true' && needs.check-prisma-migrations.result != 'success') ||
|
||||
needs.build.result != 'success' ||
|
||||
needs.build-api-v1.result != 'success' ||
|
||||
needs.build-api-v2.result != 'success' ||
|
||||
@@ -486,6 +505,6 @@ jobs:
|
||||
)
|
||||
) ||
|
||||
(
|
||||
needs.prepare.outputs.has_companion == 'true' &&
|
||||
needs.prepare.outputs.has-companion == 'true' &&
|
||||
needs.build-companion.result != 'success'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user