diff --git a/.gitea/workflows/update-types.yml b/.gitea/workflows/update-types.yml index c7303be..070f631 100644 --- a/.gitea/workflows/update-types.yml +++ b/.gitea/workflows/update-types.yml @@ -1,19 +1,58 @@ name: Update database types + on: push: branches: - main paths: - - '*.sql' + - supabase/migrations/*.sql jobs: - build: + update: runs-on: ubuntu-latest - if: github.head_ref != 'supabot**' + + env: + SUPABASE_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + PROJECT_REF: ${{ secrets.SUPABASE_PROJECT_ID }} + DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }} + steps: - - uses: lyqht/generate-supabase-db-types-github-action@main - with: - SUPABASE_REF_ID: ${{ secrets.SUPABASE_PROJECT_ID }} - SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} - DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }} - OUTPUT_PATH: supabase/functions/_shared/database.types.ts \ No newline at end of file + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Supabase CLI + run: | + curl -L https://github.com/supabase/cli/releases/latest/download/supabase_linux_amd64.tar.gz \ + | tar -xz + sudo mv supabase /usr/local/bin/ + + - name: Generate database types + run: | + supabase gen types typescript \ + --project-id $PROJECT_REF \ + --db-password $DB_PASSWORD \ + > supabase/functions/_shared/database.types.ts + + - name: Check for changes + id: git_status + run: | + if [[ -n "$(git status --porcelain)" ]]; then + echo "changed=true" >> $GITEA_OUTPUT + else + echo "changed=false" >> $GITEA_OUTPUT + fi + + - name: Commit changes + if: steps.git_status.outputs.changed == 'true' + run: | + git config user.name "supabot" + git config user.email "supabot@example.com" + git add supabase/functions/_shared/database.types.ts + git commit -m "chore: update database types" + + - name: Push changes + if: steps.git_status.outputs.changed == 'true' + run: | + git push \ No newline at end of file