From 14f0e4d65a365e9666b5d645d370cfdbc1d10a9d Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:42:10 +0300 Subject: [PATCH 01/14] Add env SITE_BASE --- vite.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/vite.config.ts b/vite.config.ts index f3d8926..fe26f8a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,6 +5,7 @@ import { defineConfig } from "vite"; // https://vite.dev/config/ export default defineConfig({ + base: process.env.SITE_BASE || "/", plugins: [react(), tailwindcss()], resolve: { alias: { From 89fcbff55b245a12b6b55d02e7ca7f1f97511778 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:44:32 +0300 Subject: [PATCH 02/14] Add pnpm into package.json --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ab18172..3f0887b 100644 --- a/package.json +++ b/package.json @@ -41,5 +41,9 @@ "typescript": "~5.8.3", "typescript-eslint": "^8.39.1", "vite": "^7.1.2" - } + }, + "engines": { + "pnpm": ">=9.0.0" + }, + "packageManager": "pnpm@9.12.0" } From f90ea933f0d8fa1f445cf039be65952cf49a2817 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:45:48 +0300 Subject: [PATCH 03/14] Add basic CI for GP pages and previews --- .github/workflows/ci-build-web.yml | 88 ++++++++++++++++++++++ .github/workflows/ci-delete-pr-preview.yml | 55 ++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 .github/workflows/ci-build-web.yml create mode 100644 .github/workflows/ci-delete-pr-preview.yml diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml new file mode 100644 index 0000000..a37e58a --- /dev/null +++ b/.github/workflows/ci-build-web.yml @@ -0,0 +1,88 @@ +name: Build and deploy web version +on: + push: + branches: + - main + pull_request: + types: + - opened + - synchronize + +jobs: + build_webassembly_version: + name: Build webassembly version + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: start deployment + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: bobheadxi/deployments@v1 + id: deployment + with: + ref: ${{ github.event.pull_request.head.sha }} + step: start + debug: true + env: preview-${{ github.event.pull_request.number }} + + - name: Clone + uses: actions/checkout@v4 + + - name: Set deployment path + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) + id: set-path + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + echo "DEST_DIR=PR-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT + echo "SITE_BASE=/PR-${{ github.event.pull_request.number }}/" >> $GITHUB_OUTPUT + else + echo "DEST_DIR=." >> $GITHUB_OUTPUT + echo "SITE_BASE=/" >> $GITHUB_OUTPUT + fi + echo =============================== + cat $GITHUB_OUTPUT + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + cache: 'pnpm' + + - name: Install pnpm + run: npm install -g pnpm + + - name: Install dependencies + run: | + pnpm install + + - name: Build + run: pnpm run build + env: + SITE_BASE: ${{ steps.set-path.outputs.SITE_BASE }} + + - name: Install rsync (required for the next step) + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) + run: | + sudo apt-get update && sudo apt-get install -y rsync + + - name: Deploy PR preview or main site + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: dist + target-folder: ${{ steps.set-path.outputs.DEST_DIR }} + clean: false + single-commit: true + + - name: Update deployment status + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: bobheadxi/deployments@v1 + with: + step: finish + status: success + debug: true + env: ${{ steps.deployment.outputs.env }} + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + ref: ${{ github.event.pull_request.head.sha }} + env_url: https://fallout2-ce.github.io/PR-${{ github.event.pull_request.number }}/ + diff --git a/.github/workflows/ci-delete-pr-preview.yml b/.github/workflows/ci-delete-pr-preview.yml new file mode 100644 index 0000000..de02e6a --- /dev/null +++ b/.github/workflows/ci-delete-pr-preview.yml @@ -0,0 +1,55 @@ +name: Cleanup PR Preview + +on: + pull_request: + types: + - closed + +jobs: + delete_pr_preview: + name: Delete PR preview from gh-pages + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + permissions: + contents: write + deployments: write + steps: + - name: Checkout gh-pages branch + uses: actions/checkout@v4 + with: + ref: gh-pages + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Remove PR preview folder + run: | + PR_FOLDER="PR-${{ github.event.pull_request.number }}" + echo "Removing preview folder: $PR_FOLDER" + git rm -r --ignore-unmatch "$PR_FOLDER" || true + + - name: Commit and push changes + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + echo "Current branch: $CURRENT_BRANCH" + + if [ "$CURRENT_BRANCH" != "gh-pages" ]; then + echo "❌ Refusing to force-push to non-gh-pages branch: $CURRENT_BRANCH" + exit 1 + fi + + if git diff --cached --quiet; then + echo "No changes to commit" + else + git commit --amend -m "🚮 Remove preview for closed PR #${{ github.event.pull_request.number }}" + git push --force + fi + + - name: mark environment as deactivated + uses: bobheadxi/deployments@v1 + with: + step: deactivate-env + env: preview-${{ github.event.pull_request.number }} + desc: Environment was pruned + debug: true From 99a2f72a8a63a9c1b8fe161cbb20392f98e63662 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:47:10 +0300 Subject: [PATCH 04/14] Remove webassembly from step names --- .github/workflows/ci-build-web.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml index a37e58a..e1302d2 100644 --- a/.github/workflows/ci-build-web.yml +++ b/.github/workflows/ci-build-web.yml @@ -9,8 +9,8 @@ on: - synchronize jobs: - build_webassembly_version: - name: Build webassembly version + build_web: + name: Build web runs-on: ubuntu-latest permissions: write-all steps: From f6cb1503be7117b4e73ee7949c823dd0273a0848 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:49:15 +0300 Subject: [PATCH 05/14] Fixing pnpm install --- .github/workflows/ci-build-web.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml index e1302d2..69c43c2 100644 --- a/.github/workflows/ci-build-web.yml +++ b/.github/workflows/ci-build-web.yml @@ -44,11 +44,12 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 'lts/*' - cache: 'pnpm' + node-version: '22' - name: Install pnpm - run: npm install -g pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 # or your exact version - name: Install dependencies run: | From e812edb504af91b8f4113e61d4ea0d206ea3eb4c Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:51:12 +0300 Subject: [PATCH 06/14] Temp deactivate pnpm opts --- package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/package.json b/package.json index 3f0887b..ab18172 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,5 @@ "typescript": "~5.8.3", "typescript-eslint": "^8.39.1", "vite": "^7.1.2" - }, - "engines": { - "pnpm": ">=9.0.0" - }, - "packageManager": "pnpm@9.12.0" + } } From 107e67a3f7b5389a32df9840605aecf8acd3b7ae Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:53:05 +0300 Subject: [PATCH 07/14] Revert "Temp deactivate pnpm opts" This reverts commit e812edb504af91b8f4113e61d4ea0d206ea3eb4c. --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ab18172..3f0887b 100644 --- a/package.json +++ b/package.json @@ -41,5 +41,9 @@ "typescript": "~5.8.3", "typescript-eslint": "^8.39.1", "vite": "^7.1.2" - } + }, + "engines": { + "pnpm": ">=9.0.0" + }, + "packageManager": "pnpm@9.12.0" } From 29970f61a51eb6283a8e41fcd9ee92b772efb3f8 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:53:37 +0300 Subject: [PATCH 08/14] Update pnpm-workspace --- pnpm-workspace.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 5b23a1c..ab9ca17 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,6 @@ +packages: + - . + onlyBuiltDependencies: - '@tailwindcss/oxide' - esbuild From 2d4f2b8d458c4897196e4052193f07eee76c438e Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:54:46 +0300 Subject: [PATCH 09/14] Fix ci action config --- .github/workflows/ci-build-web.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml index 69c43c2..5b7d1c3 100644 --- a/.github/workflows/ci-build-web.yml +++ b/.github/workflows/ci-build-web.yml @@ -48,8 +48,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v4 - with: - version: 9 # or your exact version - name: Install dependencies run: | From e0a761147561f8fa3c13930aa32c03725dfc8d49 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 11:59:50 +0300 Subject: [PATCH 10/14] Add links --- src/components/Footer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 5637ed7..00451b9 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -11,7 +11,7 @@ const Footer = () => {
{ Date: Sun, 7 Sep 2025 12:02:48 +0300 Subject: [PATCH 11/14] Add debug print for site base --- vite.config.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vite.config.ts b/vite.config.ts index fe26f8a..c5b4382 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,9 +3,13 @@ import react from "@vitejs/plugin-react"; import path from "path"; import { defineConfig } from "vite"; +const base = process.env.SITE_BASE || "/"; + +console.info(`Site base = ${base}`); + // https://vite.dev/config/ export default defineConfig({ - base: process.env.SITE_BASE || "/", + base, plugins: [react(), tailwindcss()], resolve: { alias: { From 4a19a8715a0e4786a6d8ceaf83f346af637873a1 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 12:05:56 +0300 Subject: [PATCH 12/14] Add basename for BrowserRouter --- src/main.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.tsx b/src/main.tsx index b3e1947..f11bc43 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -49,7 +49,7 @@ const Layout = () => { createRoot(document.getElementById("root")!).render( - + }> } /> From 2b620882ac50a89ba6ee7946383df6340d70a83d Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 12:36:17 +0300 Subject: [PATCH 13/14] Add readyness polling --- .github/workflows/ci-build-web.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml index 5b7d1c3..0768875 100644 --- a/.github/workflows/ci-build-web.yml +++ b/.github/workflows/ci-build-web.yml @@ -58,6 +58,9 @@ jobs: env: SITE_BASE: ${{ steps.set-path.outputs.SITE_BASE }} + - name: Place hash file + run: echo "$GITHUB_SHA" > dist/.sitehash + - name: Install rsync (required for the next step) if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) run: | @@ -85,3 +88,22 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} env_url: https://fallout2-ce.github.io/PR-${{ github.event.pull_request.number }}/ + - name: Check that site is deployed + run: | + URL="$SITE_ORIGIN""$SITE_BASE"".sitehash" + echo "Expecting $GITHUB_SHA from $URL" + for i in `seq 1 60`; do + got="$(curl -fsSL --max-time 10 "$URL" | tr -d '\r\n' || true)" + if [ "$got" = "$GITHUB_SHA" ]; then + echo "✅ Match on attempt $i: ${got}" + exit 0 + fi + echo "Received $got, waiting" + sleep 5 + done + exit 1 + + env: + SITE_ORIGIN: https://fallout2-ce.github.io + SITE_BASE: ${{ steps.set-path.outputs.SITE_BASE }} + From 5c1ae35909db7bb53dddcd10e91767366a1de3ae Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 7 Sep 2025 12:40:56 +0300 Subject: [PATCH 14/14] Use site_hash.txt --- .github/workflows/ci-build-web.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml index 0768875..e60f72c 100644 --- a/.github/workflows/ci-build-web.yml +++ b/.github/workflows/ci-build-web.yml @@ -59,7 +59,7 @@ jobs: SITE_BASE: ${{ steps.set-path.outputs.SITE_BASE }} - name: Place hash file - run: echo "$GITHUB_SHA" > dist/.sitehash + run: echo "$GITHUB_SHA" > dist/site_hash.txt - name: Install rsync (required for the next step) if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) @@ -90,7 +90,7 @@ jobs: - name: Check that site is deployed run: | - URL="$SITE_ORIGIN""$SITE_BASE"".sitehash" + URL="$SITE_ORIGIN""$SITE_BASE""site_hash.txt" echo "Expecting $GITHUB_SHA from $URL" for i in `seq 1 60`; do got="$(curl -fsSL --max-time 10 "$URL" | tr -d '\r\n' || true)"