Changeset - r27709:13454adf22b6
[Not reviewed]
master
3 2 2
Patric Stout - 11 months ago 2023-07-08 10:30:27
truebrain@openttd.org
Change: [CI] rework preview flow and use Cloudflare Pages to publish (#11116)
7 files changed with 126 insertions and 270 deletions:
0 comments (0 inline, 0 general)
.github/workflows/ci-build.yml
Show inline comments
 
@@ -20,7 +20,7 @@ jobs:
 
    runs-on: ubuntu-20.04
 
    container:
 
      # If you change this version, change the number in the cache step too.
 
      image: emscripten/emsdk:3.1.37
 
      image: emscripten/emsdk:3.1.42
 

	
 
    steps:
 
    - name: Checkout
 
@@ -30,7 +30,7 @@ jobs:
 
      uses: actions/cache@v3
 
      with:
 
        path: /emsdk/upstream/emscripten/cache
 
        key: 3.1.37-${{ runner.os }}
 
        key: 3.1.42-${{ runner.os }}
 

	
 
    - name: Patch Emscripten to support LZMA and nlohmann-json
 
      run: |
.github/workflows/preview-build.yml
Show inline comments
 
new file 100644
 
name: Preview build
 

	
 
on:
 
  workflow_call:
 
    secrets:
 
      PREVIEW_CLOUDFLARE_API_TOKEN:
 
        description: API token to upload a preview to Cloudflare Pages
 
        required: true
 
      PREVIEW_CLOUDFLARE_ACCOUNT_ID:
 
        description: Account ID to upload a preview to Cloudflare Pages
 
        required: true
 

	
 
concurrency:
 
  group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
 
  cancel-in-progress: true
 

	
 
jobs:
 
  preview:
 
    name: Build preview
 

	
 
    environment:
 
      name: preview
 
      url: https://preview.openttd.org/pr${{ github.event.pull_request.number }}/
 

	
 
    runs-on: ubuntu-latest
 
    container:
 
      # If you change this version, change the number in the cache step too.
 
      image: emscripten/emsdk:3.1.42
 

	
 
    steps:
 
    - name: Checkout
 
      uses: actions/checkout@v3
 
      with:
 
        ref: ${{ github.event.pull_request.head.sha }}
 

	
 
    - name: Name branch
 
      run: |
 
        git config --global --add safe.directory ${GITHUB_WORKSPACE}
 
        git checkout -b pr${{ github.event.pull_request.number }}
 

	
 
    - name: Setup cache
 
      uses: actions/cache@v3
 
      with:
 
        path: /emsdk/upstream/emscripten/cache
 
        key: 3.1.42-${{ runner.os }}
 

	
 
    - name: Patch Emscripten to support LZMA and nlohmann_json
 
      run: |
 
        cd /emsdk/upstream/emscripten
 
        patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-liblzma.patch
 
        patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-nlohmann-json.patch
 

	
 
    - name: Build (host tools)
 
      run: |
 
        mkdir build-host
 
        cd build-host
 

	
 
        echo "::group::CMake"
 
        cmake .. -DOPTION_TOOLS_ONLY=ON
 
        echo "::endgroup::"
 

	
 
        echo "::group::Build"
 
        echo "Running on $(nproc) cores"
 
        make -j$(nproc) tools
 
        echo "::endgroup::"
 

	
 
    - name: Install GCC problem matcher
 
      uses: ammaraskar/gcc-problem-matcher@master
 

	
 
    - name: Build
 
      run: |
 
        mkdir build
 
        cd build
 

	
 
        echo "::group::CMake"
 
        emcmake cmake .. \
 
          -DHOST_BINARY_DIR=../build-host \
 
          -DCMAKE_BUILD_TYPE=Release \
 
          # EOF
 
        echo "::endgroup::"
 

	
 
        echo "::group::Build"
 
        echo "Running on $(nproc) cores"
 
        cmake --build . -j $(nproc) --target openttd
 
        echo "::endgroup::"
 

	
 
    - name: Prepare preview
 
      run: |
 
        mkdir public
 

	
 
        cp build/openttd.data public/
 
        cp build/openttd.html public/
 
        cp build/openttd.js public/
 
        cp build/openttd.wasm public/
 

	
 
        # Ensure we use the latest version of npm; the one we get with current
 
        # emscripten doesn't allow running "npx wrangler" as root.
 
        npm install -g npm
 

	
 
    - name: Publish preview
 
      uses: cloudflare/pages-action@v1
 
      with:
 
        apiToken: ${{ secrets.PREVIEW_CLOUDFLARE_API_TOKEN }}
 
        accountId: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }}
 
        projectName: ${{ vars.PREVIEW_CLOUDFLARE_PROJECT_NAME }}
 
        directory: public
 
        branch: pr${{ github.event.pull_request.number }}
.github/workflows/preview.yml
Show inline comments
 
new file 100644
 
name: Preview
 

	
 
on:
 
  pull_request_target:
 
    types:
 
    - labeled
 
    - synchronize
 
    branches:
 
    - master
 

	
 
jobs:
 
  preview:
 
    if: ${{ (github.event.action == 'labeled' && github.event.label.name == 'preview') || (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'preview')) }}
 
    name: Preview
 
    uses: ./.github/workflows/preview-build.yml
 
    secrets: inherit
.github/workflows/preview_build.yml
Show inline comments
 
deleted file
.github/workflows/preview_label.yml
Show inline comments
 
deleted file
.github/workflows/preview_push.yml
Show inline comments
 
deleted file
os/emscripten/Dockerfile
Show inline comments
 
FROM emscripten/emsdk:3.1.37
 
FROM emscripten/emsdk:3.1.42
 

	
 
COPY emsdk-liblzma.patch /
 
RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-liblzma.patch
0 comments (0 inline, 0 general)