initial: π first commit #3
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: db commit migration | |
on: push | |
env: | |
DATABASE_URL: postgresql://postgres:postgres@localhost:54322/postgres | |
SUPABASE_DATABASE_PASSWORD: ${{ secrets.SUPABASE_DATABASE_PASSWORD }} | |
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | |
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | |
jobs: | |
filter: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: read | |
outputs: | |
db: ${{ steps.changes.outputs.db }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.workflow_run.head_sha }} | |
- name: check for file changes | |
uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
token: ${{ github.token }} | |
filters: .github/filter.yaml | |
commit: | |
runs-on: ubuntu-latest | |
needs: filter | |
if: needs.filter.outputs.db == 'true' | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.workflow_run.head_sha }} | |
token: ${{ secrets.PAT }} | |
- uses: supabase/setup-cli@v1 | |
with: | |
version: latest | |
- name: setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: "package.json" | |
- name: setup pnpm | |
uses: pnpm/action-setup@v2 | |
id: pnpm-install | |
with: | |
run_install: false | |
- name: setup pnpm environment variable | |
id: pnpm-env | |
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
- name: cache pnpm dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ${{ steps.pnpm-env.outputs.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-dependencies-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: ${{ runner.os }}-pnpm-dependencies- | |
- name: install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: update migration file | |
run: echo y | (supabase db pull --schema public --password ${{ env.SUPABASE_DATABASE_PASSWORD }} && supabase migration squash --password ${{ env.SUPABASE_DATABASE_PASSWORD }}) | |
continue-on-error: true | |
- name: commit migration file update | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
if git diff --name-only --diff-filter=D | grep -q "supabase/migrations/.*_remote_schema.sql"; then \ | |
git add $(git diff --name-only --diff-filter=D); \ | |
OLD_VERSION=$(git diff --name-only --diff-filter=D --staged | grep "supabase/migrations/.*_remote_schema.sql" | cut -d/ -f3 | cut -d_ -f1); \ | |
git add supabase/migrations/*_remote_schema.sql -N; \ | |
NEW_VERSION=$(git diff --name-only --diff-filter=A | grep "supabase/migrations/.*_remote_schema.sql" | cut -d/ -f3 | cut -d_ -f1); \ | |
pnpm supabase migration repair ${OLD_VERSION} --status reverted --password ${{ env.SUPABASE_DATABASE_PASSWORD }}; \ | |
pnpm supabase migration repair ${NEW_VERSION} --status reverted --password ${{ env.SUPABASE_DATABASE_PASSWORD }}; \ | |
pnpm supabase migration repair ${NEW_VERSION} --status applied --password ${{ env.SUPABASE_DATABASE_PASSWORD }}; \ | |
git add supabase/migrations/*_remote_schema.sql; \ | |
git commit -m "actions: π€ (supabase) updated migration file"; \ | |
git push origin HEAD:${GITHUB_REF} --force; \ | |
echo "Committed changes to migration history"; \ | |
elif grep -q "supabase/migrations/.*_remote_schema.sql"; then \ | |
git add supabase/migrations/*_remote_schema.sql; \ | |
git commit -m "actions: π€ (supabase) created migration file"; \ | |
git push origin HEAD:${GITHUB_REF} --force; \ | |
echo "Committed changes to migration history"; \ | |
else \ | |
echo "No changes detected in migration history"; \ | |
fi | |
db-commit-migration-check: | |
runs-on: ubuntu-latest | |
needs: commit | |
if: ${{ ! failure() }} | |
steps: | |
- name: check | |
run: echo "test is successfully executed." |