Skip to content

Commit 49d7b8b

Browse files
committed
Refactor: File improved.
1 parent a273582 commit 49d7b8b

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

.github/workflows/update-controllerdb.yml

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# This workflow automatically updates ShapeEngine/gamecontrollerdb.txt monthly.
2+
# Steps:
3+
# 1. Downloads the latest gamecontrollerdb.txt from SDL_GameControllerDB.
4+
# 2. Stages the file and checks for changes.
5+
# 3. If changes are detected:
6+
# - Creates a new branch
7+
# - Commits the update
8+
# - Pushes the branch
9+
# - Opens a pull request
10+
# 4. If no changes, no branch/commit/PR is created.
11+
# The workflow is triggered monthly and can be run manually.
12+
113
name: Monthly Update gamecontrollerdb.txt
214

315
permissions:
@@ -25,22 +37,43 @@ jobs:
2537
git config --local user.email "github-actions[bot]@users.noreply.github.com"
2638
git config --local user.name "github-actions[bot]"
2739
40+
- name: Stage gamecontrollerdb.txt
41+
run: |
42+
git add ShapeEngine/gamecontrollerdb.txt
43+
44+
- name: Check for changes
45+
id: check_changes
46+
run: |
47+
if git diff --cached --quiet; then
48+
echo "changes_made=false" >> $GITHUB_OUTPUT
49+
else
50+
echo "changes_made=true" >> $GITHUB_OUTPUT
51+
fi
52+
53+
2854
- name: Create update branch
55+
if: steps.check_changes.outputs.changes_made == 'true'
2956
run: |
30-
BRANCH="update-controllerdb-$(date +'%Y%m%d')"
57+
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
58+
BRANCH="update-controllerdb-$(date +'%d%m%Y')-manual"
59+
else
60+
BRANCH="update-controllerdb-$(date +'%d%m%Y')"
61+
fi
3162
git checkout -b $BRANCH
3263
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
3364
3465
- name: Commit changes
66+
if: steps.check_changes.outputs.changes_made == 'true'
3567
run: |
36-
git add ShapeEngine/gamecontrollerdb.txt
37-
git diff --cached --quiet || git commit -m "Automated monthly update of gamecontrollerdb.txt"
68+
git commit -m "Automated monthly update of gamecontrollerdb.txt"
3869
3970
- name: Push branch
71+
if: steps.check_changes.outputs.changes_made == 'true'
4072
run: |
4173
git push origin $BRANCH
4274
4375
- name: Create Pull Request
76+
if: steps.check_changes.outputs.changes_made == 'true'
4477
uses: peter-evans/create-pull-request@v5
4578
with:
4679
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)