diff --git a/.github/workflows/ci-build-web.yml b/.github/workflows/ci-build-web.yml new file mode 100644 index 0000000..e60f72c --- /dev/null +++ b/.github/workflows/ci-build-web.yml @@ -0,0 +1,109 @@ +name: Build and deploy web version +on: + push: + branches: + - main + pull_request: + types: + - opened + - synchronize + +jobs: + build_web: + name: Build web + 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: '22' + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: | + pnpm install + + - name: Build + run: pnpm run build + env: + SITE_BASE: ${{ steps.set-path.outputs.SITE_BASE }} + + - name: Place hash file + 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) + 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 }}/ + + - name: Check that site is deployed + run: | + 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)" + 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 }} + 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 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" } 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 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 = () => {
{ { createRoot(document.getElementById("root")!).render( - + }> } /> diff --git a/vite.config.ts b/vite.config.ts index f3d8926..c5b4382 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,8 +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, plugins: [react(), tailwindcss()], resolve: { alias: {