Doc: Fix broken links to Bootstrap CONTRIBUTING guide and doc license
[openttd-github.git] / .github / workflows / preview_build.yml
blob2a280a6fcdcfdeb78b362a52bab64c48dd171a6e
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.31
17     steps:
18     - name: Update deployment status to in progress
19       uses: octokit/request-action@v2.x
20       with:
21         route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
22         mediaType: |
23           previews:
24           - ant-man
25           - flash
26         owner: ${{ github.event.repository.owner.login }}
27         repo: ${{ github.event.repository.name }}
28         deployment_id: ${{ github.event.client_payload.deployment_id }}
29         state: in_progress
30       env:
31         GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
33     - name: Checkout
34       uses: actions/checkout@v2
35       with:
36         ref: ${{ github.event.client_payload.sha }}
38     - name: Name branch
39       run: |
40         name=$(echo "${{ github.event.client_payload.folder }}")
41         git checkout -b ${name}
43     - name: Setup cache
44       uses: actions/cache@v2
45       with:
46         path: /emsdk/upstream/emscripten/cache
47         key: 2.0.31-${{ runner.os }}
49     - name: Patch Emscripten to support LZMA
50       run: |
51         cd /emsdk/upstream/emscripten
52         patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-liblzma.patch
54     - name: Build (host tools)
55       run: |
56         mkdir build-host
57         cd build-host
59         echo "::group::CMake"
60         cmake .. -DOPTION_TOOLS_ONLY=ON
61         echo "::endgroup::"
63         echo "::group::Build"
64         echo "Running on $(nproc) cores"
65         make -j$(nproc) tools
66         echo "::endgroup::"
68     - name: Install GCC problem matcher
69       uses: ammaraskar/gcc-problem-matcher@master
71     - name: Build
72       run: |
73         mkdir build
74         cd build
76         echo "::group::CMake"
77         emcmake cmake .. \
78           -DHOST_BINARY_DIR=../build-host \
79           -DCMAKE_BUILD_TYPE=Release \
80           # EOF
81         echo "::endgroup::"
83         echo "::group::Build"
84         echo "Running on $(nproc) cores"
85         emmake make -j$(nproc)
86         echo "::endgroup::"
88     - name: Publish preview
89       run: |
90         pip3 install awscli
92         aws s3 cp --only-show-errors build/openttd.data s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
93         aws s3 cp --only-show-errors build/openttd.html s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
94         aws s3 cp --only-show-errors build/openttd.js s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
95         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         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 }}