Update DB #8
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: Update DB | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| queries: | |
| description: 'Write SQL queries' | |
| required: false | |
| default: 'false' | |
| jobs: | |
| update: | |
| name: Update | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v3 | |
| - name: Install SQLite | |
| if: ${{github.event.inputs.queries != 'false'}} | |
| run: sudo apt-get install sqlite3 | |
| - name: Create SQL queries file ans activate FK | |
| if: ${{github.event.inputs.queries != 'false'}} | |
| run: | | |
| echo "PRAGMA foreign_keys = ON;" > queries.sql | |
| echo "${{ github.event.inputs.queries }}" | base64 -d > queries.json | |
| jq -r '.[]' queries.json >> queries.sql | |
| cat queries.sql | |
| - name: Run SQL queries | |
| if: ${{github.event.inputs.queries != 'false'}} | |
| run: | | |
| set -e | |
| sqlite3 ./public/CollecTF.db.gz < queries.sql | |
| - name: Delete SQL queries file | |
| if: ${{github.event.inputs.queries != 'false'}} | |
| run: rm queries.sql && rm queries.json | |
| - name: Commit updated database | |
| if: ${{ github.event.inputs.queries != 'false' }} | |
| env: | |
| TOKEN: ${{ secrets.BOT_TOKEN }} | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| git add ./public/CollecTF.db.gz | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Update database via workflow_dispatch" | |
| git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} | |
| git push origin main | |
| echo "${{ github.repository }}" | |
| curl -X POST \ | |
| -H "Authorization: token ${TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/workflows/deploy.yml/dispatches \ | |
| -d '{"ref":"main"}' | |
| else | |
| echo "No changes to commit." | |
| fi |