|
| 1 | +name: Reseed database |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + target: |
| 7 | + description: "Target database" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - staging |
| 12 | + - production |
| 13 | + preset: |
| 14 | + description: "Seeding preset" |
| 15 | + required: true |
| 16 | + default: "full" |
| 17 | + type: choice |
| 18 | + options: |
| 19 | + - full |
| 20 | + - lite |
| 21 | + - minimal |
| 22 | + - uk-lite |
| 23 | + - uk-minimal |
| 24 | + - us-lite |
| 25 | + - us-minimal |
| 26 | + - testing |
| 27 | + confirm: |
| 28 | + description: "Type 'reseed-staging' or 'reseed-prod' to confirm" |
| 29 | + required: true |
| 30 | + type: string |
| 31 | + pull_request: |
| 32 | + paths: |
| 33 | + - ".github/workflows/db-reseed.yml" |
| 34 | + |
| 35 | +jobs: |
| 36 | + validate: |
| 37 | + name: Validate workflow |
| 38 | + runs-on: ubuntu-latest |
| 39 | + if: github.event_name == 'pull_request' |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout code |
| 43 | + uses: actions/checkout@v6 |
| 44 | + |
| 45 | + - name: Validate workflow syntax |
| 46 | + run: | |
| 47 | + bash <(curl -sSL https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) |
| 48 | + ./actionlint -color |
| 49 | +
|
| 50 | + reseed-db: |
| 51 | + name: Reseed ${{ inputs.target }} database |
| 52 | + runs-on: ubuntu-latest |
| 53 | + if: github.event_name == 'workflow_dispatch' |
| 54 | + environment: ${{ inputs.target }} |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Verify confirmation |
| 58 | + run: | |
| 59 | + EXPECTED="reseed-staging" |
| 60 | + if [ "${{ inputs.target }}" = "production" ]; then |
| 61 | + EXPECTED="reseed-prod" |
| 62 | + fi |
| 63 | + if [ "${{ inputs.confirm }}" != "$EXPECTED" ]; then |
| 64 | + echo "Confirmation failed. You must type '$EXPECTED' to proceed." |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + echo "Confirmation verified for ${{ inputs.target }}" |
| 68 | +
|
| 69 | + - name: Checkout code |
| 70 | + uses: actions/checkout@v6 |
| 71 | + |
| 72 | + - name: Install uv |
| 73 | + uses: astral-sh/setup-uv@v8.1.0 |
| 74 | + with: |
| 75 | + save-cache: false |
| 76 | + |
| 77 | + - name: Setup Python |
| 78 | + run: uv python install 3.13 |
| 79 | + |
| 80 | + - name: Sync dependencies |
| 81 | + run: uv sync |
| 82 | + |
| 83 | + - name: Reseed database |
| 84 | + env: |
| 85 | + SUPABASE_DB_URL: ${{ secrets.SUPABASE_DB_URL }} |
| 86 | + SUPABASE_URL: ${{ secrets.SUPABASE_URL }} |
| 87 | + SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} |
| 88 | + SUPABASE_SECRET_KEY: ${{ secrets.SUPABASE_SECRET_KEY }} |
| 89 | + HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }} |
| 90 | + STORAGE_BUCKET: ${{ vars.STORAGE_BUCKET }} |
| 91 | + LOGFIRE_TOKEN: ${{ secrets.LOGFIRE_TOKEN }} |
| 92 | + LOGFIRE_ENVIRONMENT: ${{ inputs.target }} |
| 93 | + run: | |
| 94 | + echo "Reseeding ${{ inputs.target }} database with preset '${{ inputs.preset }}'..." |
| 95 | + uv run python scripts/seed.py --preset="${{ inputs.preset }}" |
| 96 | +
|
| 97 | + - name: Summary |
| 98 | + run: | |
| 99 | + echo "Database reseed complete." |
| 100 | + echo "Target: ${{ inputs.target }}" |
| 101 | + echo "Preset: ${{ inputs.preset }}" |
| 102 | + echo "Triggered by: ${{ github.actor }}" |
0 commit comments