From 4b3c6838daeaf4b3b07ff2d664c0c7008cee58ca Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 12 Jan 2025 23:15:14 +0100 Subject: [PATCH] Refactor GHA workflows --- .github/workflows/add_mod_port.yml | 98 +++++++++++------------ .github/workflows/announce_mod_update.yml | 44 +++++----- .github/workflows/hugo.yml | 65 ++++++++------- 3 files changed, 106 insertions(+), 101 deletions(-) diff --git a/.github/workflows/add_mod_port.yml b/.github/workflows/add_mod_port.yml index e03a58b..2b15480 100644 --- a/.github/workflows/add_mod_port.yml +++ b/.github/workflows/add_mod_port.yml @@ -38,59 +38,59 @@ jobs: runs-on: ubuntu-latest steps: - - name: Echo distinct ID ${{ github.event.inputs.distinct_id }} - run: echo ${{ github.event.inputs.distinct_id }} + - name: Echo distinct ID ${{ github.event.inputs.distinct_id }} + run: echo ${{ github.event.inputs.distinct_id }} - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.12" - cache: "pip" - cache-dependency-path: scripts/requirements.txt + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + cache-dependency-path: scripts/requirements.txt - - name: Install dependencies - run: pip install -r scripts/requirements.txt + - name: Install dependencies + run: pip install -r scripts/requirements.txt - - name: Run add_mod_port.py - run: | - python scripts/add_mod_port.py \ - "${{ github.event.inputs.mod }}" \ - "${{ github.event.inputs.modloader }}" \ - "${{ github.event.inputs.mod_version }}" \ - "${{ github.event.inputs.mc_version }}" \ - ${{ github.event.inputs.modloader == 'fabric' && format('--fapi_version {0}', github.event.inputs.fapi_version) || '' }} \ - "${{ github.event.inputs.file_id }}" + - name: Run add_mod_port.py + run: | + python scripts/add_mod_port.py \ + "${{ github.event.inputs.mod }}" \ + "${{ github.event.inputs.modloader }}" \ + "${{ github.event.inputs.mod_version }}" \ + "${{ github.event.inputs.mc_version }}" \ + ${{ github.event.inputs.modloader == 'fabric' && format('--fapi_version {0}', github.event.inputs.fapi_version) || '' }} \ + "${{ github.event.inputs.file_id }}" - - name: Commit changes - run: | - MOD="${{ github.event.inputs.mod }}" - MOD_VERSION="${{ github.event.inputs.mod_version }}" - MC_VERSION="${{ github.event.inputs.mc_version }}" - MODLOADER="${{ github.event.inputs.modloader }}" - git config --local user.email "contact.wurstimperium@gmail.com" - git config --local user.name "Wurst-Bot" - git add . - git commit -m "[Wurst-Bot] Port $MOD $MOD_VERSION to Minecraft $MC_VERSION ($MODLOADER)" - git push + - name: Commit changes + run: | + MOD="${{ github.event.inputs.mod }}" + MOD_VERSION="${{ github.event.inputs.mod_version }}" + MC_VERSION="${{ github.event.inputs.mc_version }}" + MODLOADER="${{ github.event.inputs.modloader }}" + git config --local user.email "contact.wurstimperium@gmail.com" + git config --local user.name "Wurst-Bot" + git add . + git commit -m "[Wurst-Bot] Port $MOD $MOD_VERSION to Minecraft $MC_VERSION ($MODLOADER)" + git push - - name: Trigger hugo workflow - id: hugo_dispatch - uses: codex-/return-dispatch@v2 - with: - token: ${{ github.token }} - owner: Wurst-Imperium - repo: wimods.net - ref: master - workflow: hugo.yml + - name: Trigger hugo workflow + id: hugo_dispatch + uses: codex-/return-dispatch@v2 + with: + token: ${{ github.token }} + owner: Wurst-Imperium + repo: wimods.net + ref: master + workflow: hugo.yml - - name: Wait for website update to finish (run ${{ steps.hugo_dispatch.outputs.run_id }}) - uses: codex-/await-remote-run@v1 - with: - token: ${{ github.token }} - owner: Wurst-Imperium - repo: wimods.net - run_id: ${{ steps.hugo_dispatch.outputs.run_id }} - run_timeout_seconds: 300 # 5 minutes + - name: Wait for hugo workflow to finish (run ${{ steps.hugo_dispatch.outputs.run_id }}) + uses: codex-/await-remote-run@v1 + with: + token: ${{ github.token }} + owner: Wurst-Imperium + repo: wimods.net + run_id: ${{ steps.hugo_dispatch.outputs.run_id }} + run_timeout_seconds: 300 # 5 minutes diff --git a/.github/workflows/announce_mod_update.yml b/.github/workflows/announce_mod_update.yml index 980a42d..c2b31c8 100644 --- a/.github/workflows/announce_mod_update.yml +++ b/.github/workflows/announce_mod_update.yml @@ -16,28 +16,30 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.12" - cache: "pip" - cache-dependency-path: scripts/requirements.txt + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + cache-dependency-path: scripts/requirements.txt - - name: Install dependencies - run: | - pip install -r scripts/requirements.txt + - name: Install dependencies + run: | + pip install -r scripts/requirements.txt - - name: Run announce_mod_update.py - id: announce - env: - WURSTFORUM_TOKEN: ${{ secrets.WF_BOT_TOKEN }} - run: | - python scripts/announce_mod_update.py "${{ github.event.inputs.mod }}" "${{ github.event.inputs.mod_version }}" + - name: Run announce_mod_update.py + id: announce + env: + WURSTFORUM_TOKEN: ${{ secrets.WF_BOT_TOKEN }} + run: | + python scripts/announce_mod_update.py \ + "${{ github.event.inputs.mod }}" \ + "${{ github.event.inputs.mod_version }}" - - name: Write summary - run: | - echo "Discussion ID: ${{ steps.announce.outputs.discussion_id }}" >> $GITHUB_STEP_SUMMARY - echo "Link: " >> $GITHUB_STEP_SUMMARY + - name: Write summary + run: | + echo "Discussion ID: ${{ steps.announce.outputs.discussion_id }}" >> $GITHUB_STEP_SUMMARY + echo "Link: " >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/hugo.yml b/.github/workflows/hugo.yml index 65e9b6d..4144e9b 100644 --- a/.github/workflows/hugo.yml +++ b/.github/workflows/hugo.yml @@ -2,7 +2,10 @@ name: Deploy Hugo site to Pages on: push: - branches: ["master"] + branches: + - "master" + tags-ignore: + - "**" schedule: # cron: minute, hour, day of month, month, day of week # Update the copyright year on Jan 1st @@ -25,48 +28,48 @@ concurrency: cancel-in-progress: false jobs: + # Build job build: runs-on: ubuntu-latest steps: - - name: Echo distinct ID ${{ github.event.inputs.distinct_id }} - run: echo ${{ github.event.inputs.distinct_id }} - - name: Checkout - uses: actions/checkout@v4 - - name: Install Hugo CLI - run: | - HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c 2-) - wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + - name: Echo distinct ID ${{ github.event.inputs.distinct_id }} + run: echo ${{ github.event.inputs.distinct_id }} + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Hugo CLI + run: | + HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest \ + | grep tag_name | cut -d '"' -f 4 | cut -c 2-) + wget -O ${{ runner.temp }}/hugo.deb \ + https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb - - name: Setup Pages - id: pages - uses: actions/configure-pages@v5 - - name: Build with Hugo - env: - HUGO_ENVIRONMENT: production - run: | - hugo \ - --minify \ - --baseURL "https://www.wimods.net/" - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: public/ + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 + - name: Build with Hugo + env: + HUGO_ENVIRONMENT: production + run: hugo --minify --baseURL "https://www.wimods.net/" + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: public/ # Deployment job deploy: + runs-on: ubuntu-latest + needs: build environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 - - name: Purge Cloudflare cache - run: | - curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE_ID }}/purge_cache" \ + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + - name: Purge Cloudflare cache + run: | + curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE_ID }}/purge_cache" \ -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_TOKEN }}" \ -H "Content-Type: application/json" \ --data '{"purge_everything":true}'