web build from ci/wasm-build #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Web (WebAssembly) Build | |
| run-name: web build from ${{ inputs.ref || github.ref_name }} | |
| on: | |
| push: | |
| branches: | |
| - bobtista/topic/trunk | |
| # Working branches for build-infrastructure changes, so a push iterates on CI | |
| # without opening a pull request first. | |
| - 'ci/**' | |
| paths: | |
| - '.github/workflows/web-build.yml' | |
| - 'CMakePresets.json' | |
| - 'CMakeLists.txt' | |
| - 'cmake/**' | |
| - 'scripts/build/web/**' | |
| - 'Core/**' | |
| - 'Dependencies/**' | |
| - 'GeneralsMD/**' | |
| pull_request: | |
| paths: | |
| - '.github/workflows/web-build.yml' | |
| - 'CMakePresets.json' | |
| - 'CMakeLists.txt' | |
| - 'cmake/**' | |
| - 'scripts/build/web/**' | |
| - 'Core/**' | |
| - 'Dependencies/**' | |
| - 'GeneralsMD/**' | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: "Branch, tag, or SHA to build" | |
| required: false | |
| type: string | |
| concurrency: | |
| group: web-build-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| web: | |
| name: web-generalsmd-sdl3-bgfx | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| # The Emscripten SDK image carries emcc, cmake, make, node and a host g++ (needed | |
| # for the host shaderc the cross build compiles its shaders with). | |
| container: emscripten/emsdk:6.0.5 | |
| env: | |
| # Job-level so the deploy step can test for the token in its `if` (the secrets | |
| # context is not available there). Absent secrets expand to an empty string. | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ inputs.ref || github.ref_name }} | |
| - name: Mark Workspace Safe For Git | |
| run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" | |
| - name: Install Build Tools | |
| # The Emscripten image ships cmake and make but not ninja (the generator the | |
| # presets use) or zip (used to package the artifact below). The X11 and GL | |
| # headers are for the host shaderc build: configuring bgfx.cmake natively on | |
| # Linux runs find_package(X11) for the bgfx library target, even though only | |
| # the shaderc tool is actually built from that tree. | |
| run: | | |
| apt-get update | |
| apt-get install -y --no-install-recommends \ | |
| ninja-build zip libx11-dev libgl1-mesa-dev | |
| - name: Cache FFmpeg For wasm | |
| id: cache-ffmpeg-wasm | |
| uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 | |
| with: | |
| path: ${{ github.workspace }}/build/ffmpeg-wasm | |
| key: ffmpeg-wasm-${{ hashFiles('scripts/build/web/build-ffmpeg-wasm.sh') }} | |
| - name: Build FFmpeg For wasm | |
| if: steps.cache-ffmpeg-wasm.outputs.cache-hit != 'true' | |
| run: | | |
| NPROC="$(nproc)" bash scripts/build/web/build-ffmpeg-wasm.sh "${GITHUB_WORKSPACE}/build/ffmpeg-wasm" | |
| - name: Cache CMake Dependencies | |
| uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 | |
| with: | |
| path: | | |
| build/web-generalsmd-sdl3-bgfx/_deps | |
| build/web-generalsmd-sdl3-bgfx/host-shaderc | |
| key: cmake-deps-web-generalsmd-sdl3-bgfx-${{ hashFiles('CMakePresets.json','cmake/**/*.cmake','**/CMakeLists.txt') }} | |
| restore-keys: | | |
| cmake-deps-web-generalsmd-sdl3-bgfx- | |
| - name: Configure with CMake | |
| run: | | |
| FFMPEG_PREFIX="${GITHUB_WORKSPACE}/build/ffmpeg-wasm" | |
| cmake --preset web-generalsmd-sdl3-bgfx \ | |
| -DFFMPEG_INCLUDE_DIR="${FFMPEG_PREFIX}/include" \ | |
| -DFFMPEG_AVCODEC_LIBRARY="${FFMPEG_PREFIX}/lib/libavcodec.a" \ | |
| -DFFMPEG_AVFORMAT_LIBRARY="${FFMPEG_PREFIX}/lib/libavformat.a" \ | |
| -DFFMPEG_AVUTIL_LIBRARY="${FFMPEG_PREFIX}/lib/libavutil.a" \ | |
| -DFFMPEG_SWSCALE_LIBRARY="${FFMPEG_PREFIX}/lib/libswscale.a" | |
| - name: Build GeneralsMD | |
| run: | | |
| cmake --build build/web-generalsmd-sdl3-bgfx --config Release --target z_generals -j"$(nproc)" | |
| - name: Stage | |
| run: | | |
| STAGE="${GITHUB_WORKSPACE}/stage-web/GeneralsZH-web" | |
| mkdir -p "${STAGE}" | |
| # Ninja Multi-Config appends the configuration to the output directory. | |
| WEB_DIR="build/web-generalsmd-sdl3-bgfx/web" | |
| if [ -d "${WEB_DIR}/Release" ]; then | |
| WEB_DIR="${WEB_DIR}/Release" | |
| fi | |
| cp -r "${WEB_DIR}"/. "${STAGE}/" | |
| cp scripts/build/web/serve.py "${STAGE}/serve.py" | |
| # Cross-origin isolation headers for a Vercel deployment of this directory. | |
| cp scripts/build/web/vercel.json "${STAGE}/vercel.json" | |
| { | |
| echo "Command & Conquer Generals Zero Hour (GeneralsMD) WebAssembly build" | |
| echo "preset: web-generalsmd-sdl3-bgfx (Release, wasm32)" | |
| echo "ref: ${{ inputs.ref || github.ref_name }}" | |
| echo "commit: $(git rev-parse HEAD)" | |
| echo "built: $(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| echo | |
| echo "Serve this directory over HTTP with cross-origin isolation enabled" | |
| echo "(COOP: same-origin, COEP: require-corp); vercel.json sets both for a" | |
| echo "Vercel deployment, and serve.py sets them for local runs. The page" | |
| echo "will not boot from file://." | |
| echo | |
| echo "The page ships no game data. Served locally, serve.py streams it from" | |
| echo "an install on the same machine; hosted, the page asks the player for" | |
| echo "their own installation folder and keeps a copy in browser storage." | |
| } > "${STAGE}/BUILD_INFO.txt" | |
| - name: Zip | |
| run: | | |
| cd "${GITHUB_WORKSPACE}/stage-web/GeneralsZH-web" | |
| zip -ry "${GITHUB_WORKSPACE}/GeneralsZH-web.zip" . | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| with: | |
| name: GeneralsZH-web | |
| path: GeneralsZH-web.zip | |
| retention-days: 30 | |
| if-no-files-found: error | |
| # Deploying is opt-in: without a VERCEL_TOKEN secret the step is skipped, so the | |
| # workflow still builds and uploads the artifact in forks and pull requests. | |
| - name: Deploy To Vercel | |
| if: ${{ env.VERCEL_TOKEN != '' && github.event_name != 'pull_request' }} | |
| run: | | |
| npx --yes vercel@latest deploy "${GITHUB_WORKSPACE}/stage-web/GeneralsZH-web" \ | |
| --prod --yes --archive=tgz --token "${VERCEL_TOKEN}" |