|
| 1 | +name: Deploy Web |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Release version" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pages: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: pages |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + deploy: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + environment: |
| 24 | + name: github-pages |
| 25 | + url: ${{ steps.deployment.outputs.page_url }} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v7.0.0 |
| 29 | + - name: Setup site |
| 30 | + env: |
| 31 | + DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} |
| 32 | + run: | |
| 33 | + mkdir -p ~/.ssh |
| 34 | + echo "$DEPLOY_KEY" > ~/.ssh/id_key |
| 35 | + chmod 600 ~/.ssh/id_key |
| 36 | + ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null |
| 37 | + GIT_SSH_COMMAND="ssh -i ~/.ssh/id_key -o StrictHostKeyChecking=no" \ |
| 38 | + git clone --recursive git@github.com:cal-mods/basics.git _mods_src |
| 39 | + for mod_dir in _mods_src/*/; do |
| 40 | + mod_name=$(basename "$mod_dir") |
| 41 | + [ -d "$mod_dir" ] || continue |
| 42 | + if [ -d "mods/$mod_name" ] && [[ "$mod_name" == _* ]]; then |
| 43 | + continue |
| 44 | + fi |
| 45 | + rm -rf "mods/$mod_name" |
| 46 | + cp -r "$mod_dir" "mods/$mod_name" |
| 47 | + done |
| 48 | + rm -rf _mods_src ~/.ssh/id_key |
| 49 | + mkdir _site |
| 50 | + cp -r app/* _site/ |
| 51 | + cp -r mods _site/mods |
| 52 | + cp mods.json _site/mods.json |
| 53 | + # /notice.html fetches and renders this; it is the single source of |
| 54 | + # truth for the project's statement of purpose (see server.js). |
| 55 | + cp NOTICE.md _site/NOTICE.md |
| 56 | + mkdir -p _site/img |
| 57 | + curl -fsSL -o _site/img/achievement-unlocked.jpg \ |
| 58 | + https://cdn.fastly.steamstatic.com/steamcommunity/public/images/apps/2378900/55f956539371a92bd5d24a0a72d84cf983eb4b82.jpg |
| 59 | + curl -fsSL -o _site/img/achievement-locked.jpg \ |
| 60 | + https://cdn.fastly.steamstatic.com/steamcommunity/public/images/apps/2378900/8909a9950e3deb1c38afce9a4b427d5f7dfb461b.jpg |
| 61 | + curl -fsSL -o _site/img/tcoaal-steam-header.jpg \ |
| 62 | + https://shared.fastly.steamstatic.com/store_item_assets/steam/apps/2378900/0badd5423ec8cb36d543b7b156121ac2d38ef330/header.jpg |
| 63 | +
|
| 64 | + - name: Setup Node |
| 65 | + uses: actions/setup-node@v6.4.0 |
| 66 | + with: |
| 67 | + node-version: 20 |
| 68 | + |
| 69 | + - name: Minify and stamp |
| 70 | + run: | |
| 71 | + for f in _site/*.html; do |
| 72 | + npx --yes html-minifier-terser@7 \ |
| 73 | + --collapse-whitespace --remove-comments \ |
| 74 | + --minify-css true \ |
| 75 | + --minify-js '{"compress":true,"mangle":false}' \ |
| 76 | + -o "$f.tmp" "$f" |
| 77 | + mv "$f.tmp" "$f" |
| 78 | + done |
| 79 | + while IFS= read -r f; do |
| 80 | + npx --yes terser@5 "$f" --compress --comments false -o "$f.tmp" |
| 81 | + mv "$f.tmp" "$f" |
| 82 | + done < <(find _site/js _site/sw.js -name '*.js' ! -name '*.min.js') |
| 83 | + BUILD_TS=$(TZ=UTC date '+%d/%m/%Y %H:%M:%S') |
| 84 | + printf '\n<!-- %s -->\n' "$BUILD_TS" >> _site/index.html |
| 85 | + printf '\n<!-- %s -->\n' "$BUILD_TS" >> _site/loader.html |
| 86 | +
|
| 87 | + - name: Upload artifact |
| 88 | + uses: actions/upload-pages-artifact@v5 |
| 89 | + with: |
| 90 | + path: _site |
| 91 | + retention-days: 1 |
| 92 | + |
| 93 | + - name: Deploy to GitHub Pages |
| 94 | + id: deployment |
| 95 | + uses: actions/deploy-pages@v5 |
| 96 | + |
| 97 | + - name: Delete artifact |
| 98 | + uses: geekyeggo/delete-artifact@v6 |
| 99 | + with: |
| 100 | + name: github-pages |
| 101 | + |
| 102 | + - name: Tag the build commit |
| 103 | + env: |
| 104 | + TAG: web/v${{ inputs.version }} |
| 105 | + run: | |
| 106 | + git config user.name "github-actions[bot]" |
| 107 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 108 | + git tag -a "$TAG" -m "$TAG" "$GITHUB_SHA" |
| 109 | + git push origin "refs/tags/$TAG" |
0 commit comments