Fix: Invalidate cached vehicle colourmaps when changing liveries setting. (#9006)
[openttd-github.git] / .github / workflows / preview_build.yml
blob9aea890bcecb14cca2f9c623e44a5eaf85b4fc69
1 name: Preview build
3 on:
4   repository_dispatch:
5     types:
6     - Preview*
8 jobs:
9   preview:
10     name: Build preview
12     runs-on: ubuntu-20.04
13     container:
14       # If you change this version, change the number in the cache step too.
15       image: emscripten/emsdk:2.0.10
16       # uid=1001(runner) gid=121(docker)
17       options: -u 1001:121
19     steps:
20     - name: Update deployment status to in progress
21       uses: octokit/request-action@v2.x
22       with:
23         route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
24         mediaType: |
25           previews:
26           - ant-man
27           - flash
28         owner: ${{ github.event.repository.owner.login }}
29         repo: ${{ github.event.repository.name }}
30         deployment_id: ${{ github.event.client_payload.deployment_id }}
31         state: in_progress
32       env:
33         GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
35     - name: Checkout
36       uses: actions/checkout@v2
37       with:
38         ref: ${{ github.event.client_payload.sha }}
40     - name: Name branch
41       run: |
42         name=$(echo "${{ github.event.client_payload.folder }}")
43         git checkout -b ${name}
45     - name: Setup cache
46       uses: actions/cache@v2
47       with:
48         path: /emsdk/upstream/emscripten/cache
49         key: 2.0.10-${{ runner.os }}
51     - name: Build (host tools)
52       run: |
53         mkdir build-host
54         cd build-host
56         echo "::group::CMake"
57         cmake .. -DOPTION_TOOLS_ONLY=ON
58         echo "::endgroup::"
60         echo "::group::Build"
61         echo "Running on $(nproc) cores"
62         make -j$(nproc) tools
63         echo "::endgroup::"
65     - name: Install GCC problem matcher
66       uses: ammaraskar/gcc-problem-matcher@master
68     - name: Build
69       run: |
70         mkdir build
71         cd build
73         echo "::group::CMake"
74         emcmake cmake .. \
75           -DHOST_BINARY_DIR=../build-host \
76           -DCMAKE_BUILD_TYPE=RelWithDebInfo \
77           # EOF
78         echo "::endgroup::"
80         echo "::group::Build"
81         echo "Running on $(nproc) cores"
82         emmake make -j$(nproc)
83         echo "::endgroup::"
85     - name: Publish preview
86       run: |
87         # setuptools is missing in this Docker image, which breaks installing
88         # awscli. So we need to do this in two steps to recover sanity.
89         pip3 install setuptools
90         pip3 install awscli
92         ~/.local/bin/aws s3 cp --only-show-errors build/openttd.data s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
93         ~/.local/bin/aws s3 cp --only-show-errors build/openttd.html s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
94         ~/.local/bin/aws s3 cp --only-show-errors build/openttd.js s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
95         ~/.local/bin/aws s3 cp --only-show-errors build/openttd.wasm s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
97         # Invalidate the cache of the CloudFront distribution
98         ~/.local/bin/aws cloudfront create-invalidation --distribution-id ${{ secrets.PREVIEW_CF_DISTRIBUTION_ID }} --paths "/${{ github.event.client_payload.folder }}/*"
99       env:
100         AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
101         AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
103     - name: Update deployment status to success
104       uses: octokit/request-action@v2.x
105       with:
106         route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
107         mediaType: |
108           previews:
109           - ant-man
110           - flash
111         owner: ${{ github.event.repository.owner.login }}
112         repo: ${{ github.event.repository.name }}
113         deployment_id: ${{ github.event.client_payload.deployment_id }}
114         state: success
115         environment_url: https://preview.openttd.org/${{ github.event.client_payload.folder }}/
116       env:
117         GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
119     - if: failure()
120       name: Update deployment status to failure
121       uses: octokit/request-action@v2.x
122       with:
123         route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
124         mediaType: |
125           previews:
126           - ant-man
127           - flash
128         owner: ${{ github.event.repository.owner.login }}
129         repo: ${{ github.event.repository.name }}
130         deployment_id: ${{ github.event.client_payload.deployment_id }}
131         state: failure
132       env:
133         GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}