Import mods #5683
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 | |
# Allows you to run this workflow as an embedded workflow | |
workflow_call: | |
inputs: | |
url: | |
description: "A url to a qmod that should be imported. If not specified, core mods are imported." | |
type: string | |
default: "" | |
targetVersion: | |
description: "The target game version of the qmod. If not specified, it will be read from the qmod itself." | |
type: string | |
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 | |
uses: ./.github/actions/install-modules | |
with: | |
scripts: true | |
- name: Import the core mods | |
if: (inputs.url == '') | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
cd source/scripts | |
npx tsx ./import.ts 2>&1 | |
echo "COMMIT_SUBJECT=$(echo "Update core mods" | jq -R -s '@json')" | tee -a "$GITHUB_ENV" | |
echo "COMMIT_BODY=$(echo "Updated new core mods from https://raw.githubusercontent.com/QuestPackageManager/bs-coremods/main/core_mods.json" | jq -R -s '@json')" | tee -a "$GITHUB_ENV" | |
echo "BRANCH_NAME=core-mods" | tee -a "$GITHUB_ENV" | |
- name: Import the specified mod | |
if: (inputs.url != '') | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
cd source/scripts | |
npx tsx ./import.ts "${{ inputs.url }}" "${{ inputs.targetVersion }}" 2>&1 | |
git add -A ../../mods | |
echo "${{ inputs.url }}" "${{ inputs.targetVersion }}" | | |
tr A-Z a-z | | |
md5sum | | |
awk '{ print "BRANCH_NAME=" $1 }' | tee -a "$GITHUB_ENV" | |
- name: Reset the staging area | |
run: | | |
git reset | |
- name: Configure git user | |
run: | | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Make commits for the new mods. | |
run: | | |
cd source/scripts | |
npx tsx ./commit-new-mods.ts 2>&1 | tee new-mods.txt | |
if grep -q '^Added mod:' new-mods.txt; then | |
echo "MODS_UPDATED=yes" | tee -a "$GITHUB_ENV" | |
fi | |
rm new-mods.txt | |
- name: Update PR info from last commit | |
if: (inputs.url != '') | |
run: | | |
echo "COMMIT_SUBJECT=$(git log -1 --pretty=%s | jq -R -s)" | tee -a "$GITHUB_ENV" | |
echo "COMMIT_BODY=$(git log -1 --pretty=%b | jq -R -s)" | tee -a "$GITHUB_ENV" | |
- name: Reset the repository working directory. | |
run: | | |
git reset --hard | |
- name: Create PR | |
if: (inputs.createPr == true) | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
title: ${{ fromJson(env.COMMIT_SUBJECT) }} | |
body: ${{ fromJson(env.COMMIT_BODY) }} | |
branch: import/${{ env.BRANCH_NAME }} | |
- name: Push the updated files | |
if: ((inputs.createPr != true) && (env.MODS_UPDATED == 'yes')) | |
run: | | |
git pull --rebase | |
git push | |
- name: Trigger deploy | |
if: ((inputs.createPr != true) && (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"}' |