Overhaul validation (#109) #10
This file contains 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
name: Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
env: | |
BRANCH_NAME: ci-${{ github.run_id }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "npm" | |
- name: Install dependencies | |
run: npm ci | |
- name: Install Neon CLI | |
run: npm install -g neonctl | |
- name: Create database branch | |
env: | |
NEON_API_KEY: ${{ secrets.NEON_API_KEY }} | |
run: | | |
neonctl branches create --name ${{ env.BRANCH_NAME }} --project-id ${{ secrets.NEON_PROJECT_ID }} --parent test | |
echo "DATABASE_URL=$(neonctl connection-string --branch-name ${{ env.BRANCH_NAME }} --project-id ${{ secrets.NEON_PROJECT_ID }} --prisma)" >> $GITHUB_ENV | |
- name: Generate Prisma Client | |
run: npx prisma generate | |
- name: Apply Migrations | |
if: github.event_name == 'pull_request' | |
run: | | |
# Reset database to last known good state | |
npx prisma migrate reset --force | |
# Apply any new migrations | |
npx prisma migrate deploy | |
env: | |
DATABASE_URL: ${{ env.DATABASE_URL }} | |
- name: Run tests | |
run: npm test | |
env: | |
DATABASE_URL: ${{ env.DATABASE_URL }} | |
- name: Cleanup database branch | |
env: | |
NEON_API_KEY: ${{ secrets.NEON_API_KEY }} | |
if: always() | |
run: | | |
neonctl branches delete ${{ env.BRANCH_NAME }} --project-id ${{ secrets.NEON_PROJECT_ID }} |