Skip to content

trigger_deploy

trigger_deploy #529

Workflow file for this run

# Simple workflow for deploying static content to GitHub Pages
name: Deploy content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
purgeCache:
description: "A list of URLs to purge from the cache, separated by \"|\".\n\nTo clear the entire cache, use \"--all\"."
default: ""
recheckUrls:
description: "Should the existing URLs be re-checked to determine if there are any missing?"
type: boolean
default: false
schedule:
- cron: "48 0 * * *"
repository_dispatch:
types: [trigger_deploy]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Get username and repository
run: |
echo "REPO_USERNAME=${GITHUB_REPOSITORY%%/*}" >> $GITHUB_ENV
echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
echo "REPO_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
- name: Set pages url
run: |
HOMEPAGE_URL="$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/pages" | jq -r '.html_url' | sed 's/\/$//')"
if [ "$HOMEPAGE_URL" == "null" ]; then
echo "PAGES_URL=https://$REPO_USERNAME.github.io/$REPO_NAME" >> $GITHUB_ENV
else
echo "PAGES_URL=$HOMEPAGE_URL" >> $GITHUB_ENV
fi
- name: Set page path
run: |
echo "PAGES_PATH=$(echo "$PAGES_URL" | awk -F/ -v OFS="/" '{$1=$2=$3=""; print $0}' | sed 's/\/\+/\//')" >> $GITHUB_ENV
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Download cache
if: (github.event.inputs.purgeCache != '--all')
continue-on-error: true
run: |
wget "https://github.com/$GITHUB_REPOSITORY/releases/download/cache/cache.txz?`date +%s`" -O cache.txz
- name: Extract cache
if: (github.event.inputs.purgeCache != '--all')
continue-on-error: true
run: |
tar -xJvf cache.txz
- name: Delete cache
if: (github.event.inputs.purgeCache != '--all')
continue-on-error: true
run: |
rm cache.txz
- name: Install npm modules
run: |
(cd source/scripts && npm install)
(cd source/website && npm install)
- name: Purge specified items from cache
if: ((github.event.inputs.purgeCache != '') && (github.event.inputs.purgeCache != '--all'))
run: |
cd source/scripts
npx tsx ./purgecache.ts "${{ github.event.inputs.purgeCache }}"
- name: Update mirror
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p mod-mirror
cd source/scripts
npx tsx ./mirror-mods.ts 2>&1
cd ../../mod-mirror
find -type f | while read file; do
gh release upload mod-mirror "$file" || true
done
if [ -f "metadata.json" ]; then
gh release upload mod-mirror --clobber "metadata.json"
fi
- name: Process the json (schedule)
if: (github.event_name == 'schedule' || github.event.inputs.recheckUrls == 'true')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd source/scripts
npx tsx ./combine.ts "--baseHref=$PAGES_URL" --updateFunding --recheckUrls 2>&1 | tee ../website/public/deploy-log.txt
- name: Process the json (normal)
if: (github.event_name != 'schedule')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd source/scripts
npx tsx ./combine.ts "--baseHref=$PAGES_URL" 2>&1 | tee ../website/public/deploy-log.txt
- name: "Archive cache"
run: |
tar -cJvf cache.txz \
source/website/public/covers \
source/website/public/funding-info.json \
source/website/public/mod-metadata.json
- name: Build website
run: |
cd source/website
npx astro build --base "$PAGES_PATH"
- name: Precompress assets
run: |
find source/website/out -type f | while read -r file; do
if [[ "$file" == *.html || "$file" == *.css || "$file" == *.js || "$file" == *.json ]]; then
echo "$file"
brotli -k -q 11 "$file"
fi
done
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: "./source/website/out"
- name: Push cache
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload cache --clobber "cache.txz"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4