-
Notifications
You must be signed in to change notification settings - Fork 2
63 lines (54 loc) · 1.99 KB
/
update-db.yml
File metadata and controls
63 lines (54 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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