Merge pull request #97 from fallout2-ce/add_preview_builds

Add preview builds (from this repo branch)
This commit is contained in:
Vasilii Rogin
2025-05-04 15:35:28 +03:00
committed by GitHub
2 changed files with 76 additions and 9 deletions
+43 -9
View File
@@ -12,14 +12,21 @@ jobs:
build_webassembly_version:
name: Build webassembly version
runs-on: ubuntu-latest
container: emscripten/emsdk:4.0.4
permissions: write-all
steps:
- name: Clone
uses: actions/checkout@v4
- name: Install Emscripten SDK
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install 4.0.4
./emsdk activate 4.0.4
- name: Build fallout2 wasm module
run: |
source emsdk/emsdk_env.sh
git config --global --add safe.directory "*"
mkdir -p build
cd build
@@ -27,36 +34,63 @@ jobs:
cd ..
- name: Add node
if: github.ref == 'refs/heads/main'
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
uses: actions/setup-node@v2
with:
node-version: '22'
- name: Checkout web interface
if: github.ref == 'refs/heads/main'
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
uses: actions/checkout@v4
with:
repository: ololoken/fallout2-ce-ems
ref: 46ac3be3da9d01ef204779073b1c1254fa037021
ref: 0764f9fdd0abf27bd9b0d3997ca0a8e61f380058
path: fallout2-ce-ems
- 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=/fallout2-ce/PR-${{ github.event.pull_request.number }}/" >> $GITHUB_OUTPUT
else
echo "DEST_DIR=." >> $GITHUB_OUTPUT
echo "SITE_BASE=/fallout2-ce/" >> $GITHUB_OUTPUT
fi
echo ===============================
cat $GITHUB_OUTPUT
- name: Build web interface
if: github.ref == 'refs/heads/main'
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
run: |
cd fallout2-ce-ems
npm install
cp ../build/fallout2-ce.js src/assets/fallout2ce
cp ../build/fallout2-ce.wasm src/assets/fallout2ce
sed -i 's/\/fallout2-ce-ems/\/fallout2-ce/' vite.config.ts
sed -i 's/Starting wasm module/Starting wasm module ${{github.event.pull_request.head.sha || github.sha }}/' src/pages/Launcher.tsx
npm 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: |
apt-get update && apt-get install -y rsync
sudo apt-get update && sudo apt-get install -y rsync
- name: Deploy to gh-pages
- 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
if: github.ref == 'refs/heads/main'
with:
branch: gh-pages
folder: fallout2-ce-ems/dist
target-folder: ${{ steps.set-path.outputs.DEST_DIR }}
clean: false
- name: Comment preview URL on PR
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
run: |
gh pr comment ${{ github.event.pull_request.number }} \
--body "🚀 WebAssembly PR Preview for ${{github.event.pull_request.head.sha || github.sha }} is available at: https://${{ github.repository_owner }}.github.io/fallout2-ce/PR-${{ github.event.pull_request.number }}/"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,33 @@
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
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"
git commit -am "🚮 Remove preview for closed PR #${{ github.event.pull_request.number }}"
git push