chore(dx): establish hermetic delivery artifact #29
Workflow file for this run
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
| name: Preview database | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - closed | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: preview-database-pr-${{ github.event.number }} | |
| cancel-in-progress: false | |
| env: | |
| NEON_BRANCH_NAME: preview/pr-${{ github.event.number }} | |
| NEON_PARENT_BRANCH: preview-base | |
| NEON_PROJECT_ID: ${{ vars.NEON_PROJECT_ID }} | |
| PDM_CHECK_UPDATE: "false" | |
| jobs: | |
| provision: | |
| name: Provision and migrate | |
| if: >- | |
| github.event.action != 'closed' && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Set preview expiration | |
| run: >- | |
| echo "EXPIRES_AT=$(date -u --date '+7 days' | |
| +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV" | |
| - name: Create or reuse data-free branch | |
| id: neon | |
| uses: neondatabase/create-branch-action@v6 | |
| with: | |
| project_id: ${{ env.NEON_PROJECT_ID }} | |
| branch_name: ${{ env.NEON_BRANCH_NAME }} | |
| parent_branch: ${{ env.NEON_PARENT_BRANCH }} | |
| role: neondb_owner | |
| expires_at: ${{ env.EXPIRES_AT }} | |
| api_key: ${{ secrets.NEON_API_KEY }} | |
| - name: Set up Python and PDM | |
| uses: pdm-project/setup-pdm@v4 | |
| with: | |
| python-version-file: .python-version | |
| version: 2.27.0 | |
| cache: true | |
| - name: Install frozen migration runtime | |
| run: pdm install --prod --frozen-lockfile | |
| - name: Apply checked-in migrations | |
| env: | |
| DATABASE_URL: ${{ steps.neon.outputs.db_url_pooled }} | |
| run: pdm run db:migrate | |
| - name: Verify exact migration head | |
| env: | |
| DATABASE_URL: ${{ steps.neon.outputs.db_url_pooled }} | |
| run: pdm run container:ready | |
| - name: Publish schema diff to job summary | |
| env: | |
| NEON_API_KEY: ${{ secrets.NEON_API_KEY }} | |
| run: | | |
| diff_file="$RUNNER_TEMP/neon-schema.diff" | |
| npx --yes neonctl@2.36.0 branches schema-diff \ | |
| "$NEON_PARENT_BRANCH" \ | |
| "$NEON_BRANCH_NAME" \ | |
| --project-id "$NEON_PROJECT_ID" \ | |
| --no-color > "$diff_file" | |
| { | |
| echo "### Neon schema diff" | |
| echo | |
| echo '```diff' | |
| cat "$diff_file" | |
| echo '```' | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| cleanup: | |
| name: Delete preview branch | |
| if: github.event.action == 'closed' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Delete deterministic Neon branch | |
| uses: neondatabase/delete-branch-action@v3 | |
| with: | |
| project_id: ${{ env.NEON_PROJECT_ID }} | |
| branch: ${{ env.NEON_BRANCH_NAME }} | |
| api_key: ${{ secrets.NEON_API_KEY }} |