From dc051541bd17c7650dd953fa8aa5ef92d3da9218 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 1 Nov 2021 23:35:25 -0400 Subject: [PATCH] actions: create automatic controller db updating workflow --- .../scripts/controller-db/.gitignore | 1 + .../scripts/controller-db/update-db.py | 38 +++++++++++++++++++ .github/workflows/update-controller-db.yml | 29 ++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 .github/workflows/scripts/controller-db/.gitignore create mode 100644 .github/workflows/scripts/controller-db/update-db.py create mode 100644 .github/workflows/update-controller-db.yml diff --git a/.github/workflows/scripts/controller-db/.gitignore b/.github/workflows/scripts/controller-db/.gitignore new file mode 100644 index 0000000000..2211df63dd --- /dev/null +++ b/.github/workflows/scripts/controller-db/.gitignore @@ -0,0 +1 @@ +*.txt diff --git a/.github/workflows/scripts/controller-db/update-db.py b/.github/workflows/scripts/controller-db/update-db.py new file mode 100644 index 0000000000..8dbce37ad5 --- /dev/null +++ b/.github/workflows/scripts/controller-db/update-db.py @@ -0,0 +1,38 @@ +import os + +relevant_categories = [ + "# Mac OS X", + "# Linux" +] + +header_lines = [] +new_db_contents = [] + +def is_relevant_category(line): + for category in relevant_categories: + if category in line: + return True + return False + +with open("./game_controller_db.txt") as file: + lines = file.readlines() + finished_header = False + processing_section = False + for line in lines: + if finished_header is False: + header_lines.append(line) + if line == "\n": + finished_header = True + if processing_section and line == "\n": + processing_section = False + new_db_contents.append("\n") + if is_relevant_category(line) and processing_section is False: + processing_section = True + new_db_contents.append(line) + elif processing_section: + new_db_contents.append(line) + +os.remove("./game_controller_db.txt") +with open("./game_controller_db.txt", "w") as f: + f.writelines(header_lines) + f.writelines(new_db_contents) diff --git a/.github/workflows/update-controller-db.yml b/.github/workflows/update-controller-db.yml new file mode 100644 index 0000000000..4afb018abd --- /dev/null +++ b/.github/workflows/update-controller-db.yml @@ -0,0 +1,29 @@ +name: 🏭 Update Controller Database + +on: + schedule: + - cron: "0 16 * * 1" # every monday @ 12pm EST - https://crontab.guru/#0_16_*_*_1 + +jobs: + update-controller-db: + if: github.repository == 'PCSX2/pcsx2' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Get Latest DB and Prepare DB File + run: | + cd .github/workflows/scripts/controller-db/ + wget -O game_controller_db.txt https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt + python ./update-db.py + mv ./game_controller_db.txt ${{github.workspace}}/pcsx2/PAD/Linux/res/game_controller_db.txt + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + title: "pad-linux: Update to latest controller database" + commit-message: "pad-linux: Update to latest controller database." + committer: "PCSX2 Bot " + author: "PCSX2 Bot " + body: "Weekly automatic update of SDL Controller DB for Linux / Mac OS" + reviewers: lightningterror