-
Notifications
You must be signed in to change notification settings - Fork 1
76 lines (73 loc) · 2.87 KB
/
update-database.yaml
File metadata and controls
76 lines (73 loc) · 2.87 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
64
65
66
67
68
69
70
71
72
73
74
75
76
name: update-database
on:
# Triggers the workflow on issue close.
issues:
types: [closed]
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:
# If we make any changes to the repository manually, this will ensure that the database stays up-to-date with the timestamp on the repo.
push:
jobs:
check-permission:
runs-on: ubuntu-latest
outputs:
authorised: ${{ steps.check-permission.outputs.authorised }}
steps:
- name: Determine if user has permission to update the database
id: check-permission
run: |
USER=${{ github.event.sender.login }}
REPO=${{ github.repository }}
RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$REPO/collaborators/$USER/permission")
PERMISSION=$(echo "$RESPONSE" | sed -n 's/.*"permission": "\(.*\)".*/\1/p')
if [ "$PERMISSION" = "admin" ] || [ "$PERMISSION" = "maintain" ] || [ "$PERMISSION" = "write" ]; then
AUTHORISED="true"
else
AUTHORISED="false"
fi
echo "authorised=$AUTHORISED" >> $GITHUB_OUTPUT
update-database:
needs: check-permission
# If the workflow was triggered by closing an issue, only run if the issue contains the 'add-plugin' label.
if: |
needs.check-permission.outputs.authorised == 'true' &&
(github.event_name == 'workflow_dispatch' || github.event.label.name == 'add-plugin')
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v4
- name: Retrieve database timestamp
id: time
run: echo "time=${{ github.event.repository.updated_at }}" >> $GITHUB_OUTPUT
- name: Retrieve URL submission
id: url
run: |
if [ "${{ github.event_name }}" == "issues" ]; then
echo "url=${{ github.event.issue.body }}" >> $GITHUB_OUTPUT
else
echo "url=''" >> $GITHUB_OUTPUT
fi
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python packages
run: |
python -m pip install --upgrade pip
pip install -r generation/requirements.txt
- name: Run Python script
run: python generation/update_database.py ${{ steps.time.outputs.time }} ${{ steps.url.outputs.url }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git diff-index --quiet HEAD || (git commit -a -m "Update database." --allow-empty)
- name: Push changes
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main