update-cdn #1294
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update CDN | |
on: | |
repository_dispatch: | |
types: | |
- update-cdn | |
# client_payload should contain both fields as mentioned in workflow_dispatch | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The version of the new release, e.g.: 20200101-master-g12345' | |
required: true | |
folder: | |
description: 'The folder in which the release is located openttd-nightlies/2020' | |
required: true | |
jobs: | |
update_cdn: | |
name: Update CDN | |
runs-on: ubuntu-latest | |
steps: | |
- name: Sanity check | |
run: | | |
if [ -z "${{ inputs.version || github.event.client_payload.version }}" ]; then | |
echo "::error::version in client_payload is not set" | |
exit 1 | |
fi | |
if [ -z "${{ inputs.folder || github.event.client_payload.folder }}" ]; then | |
echo "::error::folder in client_payload is not set" | |
exit 1 | |
fi | |
if [ -z "${{ secrets.CDN_R2_BUCKET }}" ]; then | |
echo "::error::secret CDN_R2_BUCKET is not set" | |
exit 1 | |
fi | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r cdn/requirements.txt | |
# By default, mime.types doesn't include one for YAML files. This results | |
# in empty content-type on the CDN, which means browsers want to download | |
# the file instead of showing it inline. By adding this entry to | |
# mime.types, we fix that problem. | |
- name: Fix mimetypes | |
run: | | |
echo "text/vnd.yaml yaml" | sudo tee -a /etc/mime.types | |
- name: Publish CDN files | |
run: | | |
set -x | |
cd cdn | |
S3_ENDPOINT_URL=${{ secrets.CDN_R2_ENDPOINT }} python -m cdn_generator \ | |
--bucket-id ${{ secrets.CDN_R2_BUCKET }} \ | |
--new-release ${{ inputs.folder || github.event.client_payload.folder }}/${{ inputs.version || github.event.client_payload.version }} | |
aws s3 cp \ | |
--recursive \ | |
--endpoint-url ${{ secrets.CDN_R2_ENDPOINT }} \ | |
--only-show-errors \ | |
generated/ \ | |
s3://${{ secrets.CDN_R2_BUCKET }}/ | |
env: | |
AWS_REGION: ${{ secrets.CDN_R2_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.CDN_R2_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.CDN_R2_SECRET_ACCESS_KEY }} | |
- name: Generate access token | |
id: generate_token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{ secrets.DEPLOYMENT_APP_ID }} | |
private_key: ${{ secrets.DEPLOYMENT_APP_PRIVATE_KEY }} | |
installation_retrieval_mode: "repository" | |
installation_retrieval_payload: "OpenTTD/website" | |
- name: Trigger 'publish website' | |
uses: peter-evans/repository-dispatch@v3 | |
with: | |
token: ${{ steps.generate_token.outputs.token }} | |
repository: OpenTTD/website | |
event-type: publish_latest_tag |