Codechange: change DestinationID into class with conversion helpers
[openttd-github.git] / .github / workflows / preview-build.yml
blobcf9e8394af69d320b52d34313e144102bd70c169
1 name: Preview build
3 on:
4   workflow_call:
5     secrets:
6       PREVIEW_CLOUDFLARE_API_TOKEN:
7         description: API token to upload a preview to Cloudflare Pages
8         required: true
9       PREVIEW_CLOUDFLARE_ACCOUNT_ID:
10         description: Account ID to upload a preview to Cloudflare Pages
11         required: true
13 jobs:
14   preview:
15     name: Build preview
17     environment:
18       name: preview
19       url: https://preview.openttd.org/pr${{ github.event.pull_request.number }}/
21     runs-on: ubuntu-latest
22     container:
23       # If you change this version, change the numbers in the cache step,
24       # .github/workflows/ci-emscripten.yml (2x) and os/emscripten/Dockerfile too.
25       image: emscripten/emsdk:3.1.57
27     steps:
28     - name: Checkout
29       uses: actions/checkout@v4
30       with:
31         ref: ${{ github.event.pull_request.head.sha }}
33     - name: Name branch
34       run: |
35         git config --global --add safe.directory ${GITHUB_WORKSPACE}
36         git checkout -b pr${{ github.event.pull_request.number }}
38     - name: Update to modern GCC
39       run: |
40         apt-get update
41         apt-get install -y gcc-12 g++-12
42         update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
43         update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
45     - name: Setup cache
46       uses: actions/cache@v4
47       with:
48         path: /emsdk/upstream/emscripten/cache
49         # If you change this version, change the numbers in the image configuration step,
50         # .github/workflows/ci-emscripten.yml (2x) and os/emscripten/Dockerfile too.
51         key: 3.1.57-${{ runner.os }}
53     - name: Add liblzma support
54       run: |
55         cp ${GITHUB_WORKSPACE}/os/emscripten/ports/liblzma.py /emsdk/upstream/emscripten/tools/ports/contrib/
57     - name: Build (host tools)
58       run: |
59         mkdir build-host
60         cd build-host
62         echo "::group::CMake"
63         cmake .. -DOPTION_TOOLS_ONLY=ON
64         echo "::endgroup::"
66         echo "::group::Build"
67         echo "Running on $(nproc) cores"
68         make -j$(nproc) tools
69         echo "::endgroup::"
71     - name: Install GCC problem matcher
72       uses: ammaraskar/gcc-problem-matcher@master
74     - name: Build
75       run: |
76         mkdir build
77         cd build
79         echo "::group::CMake"
80         emcmake cmake .. \
81           -DHOST_BINARY_DIR=../build-host \
82           -DCMAKE_BUILD_TYPE=Release \
83           # EOF
84         echo "::endgroup::"
86         echo "::group::Build"
87         echo "Running on $(nproc) cores"
88         cmake --build . -j $(nproc) --target openttd
89         echo "::endgroup::"
91     - name: Prepare preview
92       run: |
93         mkdir public
95         cp build/openttd.data public/
96         cp build/openttd.html public/
97         cp build/openttd.js public/
98         cp build/openttd.wasm public/
100         # Ensure we use the latest version of npm; the one we get with current
101         # emscripten doesn't allow running "npx wrangler" as root.
102         # Current emscripten can't install npm>=10.0.0 because node is too old.
103         npm install -g npm@9
105     - name: Publish preview
106       uses: cloudflare/pages-action@v1
107       with:
108         apiToken: ${{ secrets.PREVIEW_CLOUDFLARE_API_TOKEN }}
109         accountId: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }}
110         projectName: ${{ vars.PREVIEW_CLOUDFLARE_PROJECT_NAME }}
111         directory: public
112         branch: pr${{ github.event.pull_request.number }}