mirror of https://github.com/OpenTTD/OpenTTD
Change: [CI] rework preview flow and use Cloudflare Pages to publish (#11116)
parent
153323a4c0
commit
323dd619bb
|
@ -20,7 +20,7 @@ jobs:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
container:
|
container:
|
||||||
# If you change this version, change the number in the cache step too.
|
# 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:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
@ -30,7 +30,7 @@ jobs:
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: /emsdk/upstream/emscripten/cache
|
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
|
- name: Patch Emscripten to support LZMA and nlohmann-json
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
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 }}
|
|
@ -0,0 +1,16 @@
|
||||||
|
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
|
|
@ -1,135 +0,0 @@
|
||||||
name: Preview build
|
|
||||||
|
|
||||||
on:
|
|
||||||
repository_dispatch:
|
|
||||||
types:
|
|
||||||
- Preview*
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
preview:
|
|
||||||
name: Build preview
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Update deployment status to in progress
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
|
|
||||||
mediaType: |
|
|
||||||
previews:
|
|
||||||
- ant-man
|
|
||||||
- flash
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
deployment_id: ${{ github.event.client_payload.deployment_id }}
|
|
||||||
state: in_progress
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
ref: ${{ github.event.client_payload.sha }}
|
|
||||||
|
|
||||||
- name: Name branch
|
|
||||||
run: |
|
|
||||||
git config --global --add safe.directory ${GITHUB_WORKSPACE}
|
|
||||||
name=$(echo "${{ github.event.client_payload.folder }}")
|
|
||||||
git checkout -b ${name}
|
|
||||||
|
|
||||||
- name: Setup cache
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: /emsdk/upstream/emscripten/cache
|
|
||||||
key: 3.1.37-${{ 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: Publish preview
|
|
||||||
run: |
|
|
||||||
pip3 install awscli
|
|
||||||
|
|
||||||
aws s3 cp --only-show-errors build/openttd.data s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
|
|
||||||
aws s3 cp --only-show-errors build/openttd.html s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
|
|
||||||
aws s3 cp --only-show-errors build/openttd.js s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
|
|
||||||
aws s3 cp --only-show-errors build/openttd.wasm s3://${{ secrets.PREVIEW_S3_BUCKET }}/${{ github.event.client_payload.folder }}/
|
|
||||||
|
|
||||||
# Invalidate the cache of the CloudFront distribution
|
|
||||||
aws cloudfront create-invalidation --distribution-id ${{ secrets.PREVIEW_CF_DISTRIBUTION_ID }} --paths "/${{ github.event.client_payload.folder }}/*"
|
|
||||||
env:
|
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
||||||
|
|
||||||
- name: Update deployment status to success
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
|
|
||||||
mediaType: |
|
|
||||||
previews:
|
|
||||||
- ant-man
|
|
||||||
- flash
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
deployment_id: ${{ github.event.client_payload.deployment_id }}
|
|
||||||
state: success
|
|
||||||
environment_url: https://preview.openttd.org/${{ github.event.client_payload.folder }}/
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: failure()
|
|
||||||
name: Update deployment status to failure
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
|
|
||||||
mediaType: |
|
|
||||||
previews:
|
|
||||||
- ant-man
|
|
||||||
- flash
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
deployment_id: ${{ github.event.client_payload.deployment_id }}
|
|
||||||
state: failure
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
|
@ -1,66 +0,0 @@
|
||||||
name: Preview label
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types:
|
|
||||||
- labeled
|
|
||||||
|
|
||||||
env:
|
|
||||||
TEAM_CORE_DEVELOPER: core-developers
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check_preview_label:
|
|
||||||
name: Check for preview label
|
|
||||||
if: github.event.action == 'labeled' && github.event.label.name == 'preview'
|
|
||||||
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check if label was added by core developer
|
|
||||||
id: core_developer
|
|
||||||
continue-on-error: true
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: GET /orgs/OpenTTD/teams/${{ env.TEAM_CORE_DEVELOPER }}/memberships/${{ github.event.sender.login }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: steps.core_developer.outcome == 'failure'
|
|
||||||
name: Remove preview label if not core developer
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: DELETE /repos/{owner}/{repo}/issues/{issue_number}/labels/preview
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
issue_number: ${{ github.event.number }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: steps.core_developer.outcome == 'success'
|
|
||||||
name: Create deployment
|
|
||||||
id: deployment
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: POST /repos/{owner}/{repo}/deployments
|
|
||||||
mediaType: |
|
|
||||||
previews:
|
|
||||||
- ant-man
|
|
||||||
- flash
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
|
||||||
task: deploy:preview
|
|
||||||
auto_merge: false
|
|
||||||
required_contexts: "[]"
|
|
||||||
environment: preview-pr-${{ github.event.number }}
|
|
||||||
description: "Preview for Pull Request #${{ github.event.number }}"
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: steps.core_developer.outcome == 'success'
|
|
||||||
name: Trigger 'preview build'
|
|
||||||
uses: peter-evans/repository-dispatch@v2
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
event-type: "Preview build #${{ github.event.number }}"
|
|
||||||
client-payload: '{"folder": "pr${{ github.event.number }}", "sha": "${{ github.event.pull_request.head.sha }}", "deployment_id": "${{ fromJson(steps.deployment.outputs.data).id }}"}'
|
|
|
@ -1,66 +0,0 @@
|
||||||
name: Preview push
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types:
|
|
||||||
- synchronize
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check_new_preview:
|
|
||||||
name: Check preview needs update
|
|
||||||
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check if earlier preview exists
|
|
||||||
id: earlier_preview
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: GET /repos/{owner}/{repo}/deployments
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
environment: preview-pr-${{ github.event.number }}
|
|
||||||
per_page: 1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: toJson(fromJson(steps.earlier_preview.outputs.data)) != '[]'
|
|
||||||
name: Check for preview label
|
|
||||||
id: preview_label
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: GET /repos/{owner}/{repo}/issues/{issue_number}/labels
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
issue_number: ${{ github.event.number }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: toJson(fromJson(steps.earlier_preview.outputs.data)) != '[]' && contains(fromJson(steps.preview_label.outputs.data).*.name, 'preview')
|
|
||||||
name: Create deployment
|
|
||||||
id: deployment
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: POST /repos/{owner}/{repo}/deployments
|
|
||||||
mediaType: |
|
|
||||||
previews:
|
|
||||||
- ant-man
|
|
||||||
- flash
|
|
||||||
owner: ${{ github.event.repository.owner.login }}
|
|
||||||
repo: ${{ github.event.repository.name }}
|
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
|
||||||
task: deploy:preview
|
|
||||||
auto_merge: false
|
|
||||||
required_contexts: "[]"
|
|
||||||
environment: preview-pr-${{ github.event.number }}
|
|
||||||
description: "Preview for Pull Request #${{ github.event.number }}"
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- if: toJson(fromJson(steps.earlier_preview.outputs.data)) != '[]' && contains(fromJson(steps.preview_label.outputs.data).*.name, 'preview')
|
|
||||||
name: Trigger 'preview build'
|
|
||||||
uses: peter-evans/repository-dispatch@v2
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
|
|
||||||
event-type: "Preview build #${{ github.event.number }}"
|
|
||||||
client-payload: '{"folder": "pr${{ github.event.number }}", "sha": "${{ github.event.pull_request.head.sha }}", "deployment_id": "${{ fromJson(steps.deployment.outputs.data).id }}"}'
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM emscripten/emsdk:3.1.37
|
FROM emscripten/emsdk:3.1.42
|
||||||
|
|
||||||
COPY emsdk-liblzma.patch /
|
COPY emsdk-liblzma.patch /
|
||||||
RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-liblzma.patch
|
RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-liblzma.patch
|
||||||
|
|
Loading…
Reference in New Issue