name: Build and deploy web version on: push: branches: - main - master 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: 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 }} - 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 }}/