Import mods #3137
This file contains 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
# Simple workflow for deploying static content to GitHub Pages | |
name: Import mods | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
url: | |
description: "A url to a qmod that should be imported. If not specified, core mods are imported." | |
default: "" | |
targetVersion: | |
description: "The target game version of the qmod. If not specified, it will be read from the qmod itself." | |
default: "" | |
createPr: | |
description: "Should a PR be created? If false, the result will be committed automatically." | |
type: boolean | |
default: true | |
# Every 30 minutes | |
schedule: | |
- cron: "0 * * * *" | |
# Sets permissions of the GITHUB_TOKEN to allow push | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
# Single deploy job since we're just deploying | |
import-mods: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install npm modules | |
run: | | |
(cd source/scripts && npm install) | |
- name: Import the core mods | |
if: (github.event.inputs.url == '') | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
cd source/scripts | |
npx tsx ./import.ts 2>&1 | |
echo "COMMIT_MSG=Update core mods" >> $GITHUB_ENV | |
echo "BRANCH_NAME=core-mods" >> $GITHUB_ENV | |
- name: Import the specified mod | |
if: (github.event.inputs.url != '') | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
cd source/scripts | |
npx tsx ./import.ts "${{ github.event.inputs.url }}" "${{ github.event.inputs.targetVersion }}" 2>&1 | |
git add -A ../../mods | |
echo "COMMIT_MSG=Update $(git diff --name-only --cached)" >> $GITHUB_ENV | |
echo "${{ github.event.inputs.url }}" "${{ github.event.inputs.targetVersion }}" | | |
tr A-Z a-z | | |
md5sum | | |
awk '{ print "BRANCH_NAME=" $1 }' >> $GITHUB_ENV | |
- name: Create PR | |
if: (github.event.inputs.createPr == 'true') | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
title: ${{ env.COMMIT_MSG }} | |
commit-message: ${{ env.COMMIT_MSG }} | |
branch: import/${{ env.BRANCH_NAME }} | |
- name: Configure git user | |
if: (github.event.inputs.createPr != 'true') | |
run: | | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Commit the updated files | |
if: (github.event.inputs.createPr != 'true') | |
run: | | |
git add -A mods | |
( | |
git commit -m "$COMMIT_MSG" && | |
( | |
echo "MODS_UPDATED=yes" >> $GITHUB_ENV | |
) | |
) || true | |
- name: Push the updated files | |
if: (env.MODS_UPDATED == 'yes') | |
run: | | |
git pull --rebase | |
git push | |
- name: Trigger deploy | |
if: (env.MODS_UPDATED == 'yes') | |
run: | | |
curl -X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/dispatches \ | |
-d '{"event_type":"trigger_deploy"}' |