From 951e908d99211fff348da0e101913e086401d6b9 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 16 Jan 2020 20:36:43 +0100 Subject: [PATCH] Add: workflow to automate publishing of documentation --- .github/workflows/new_openttd_release.yml | 36 +++++++++++++ .github/workflows/publish_docs.yml | 63 +++++++++++++++++++++++ README.md | 9 ++++ docs/errors/404.html | 12 +++++ docs/root/index.html | 15 ++++++ 5 files changed, 135 insertions(+) create mode 100644 .github/workflows/new_openttd_release.yml create mode 100644 .github/workflows/publish_docs.yml create mode 100644 README.md create mode 100644 docs/errors/404.html create mode 100644 docs/root/index.html diff --git a/.github/workflows/new_openttd_release.yml b/.github/workflows/new_openttd_release.yml new file mode 100644 index 0000000..c6fe9db --- /dev/null +++ b/.github/workflows/new_openttd_release.yml @@ -0,0 +1,36 @@ +name: New OpenTTD release + +on: + repository_dispatch: + types: + - new_tag + - new_master + +jobs: + new_release: + name: New OpenTTD release + runs-on: ubuntu-latest + + steps: + - name: Trigger website (staging) + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.DEPLOYMENT_TOKEN }} + repository: OpenTTD/website + event-type: publish_master + + - name: Trigger website (Production) + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.DEPLOYMENT_TOKEN }} + repository: OpenTTD/website + event-type: publish_latest_tag + + - if: github.event.action == 'new_master' + name: Trigger docs + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.DEPLOYMENT_TOKEN }} + repository: OpenTTD/workflows + event-type: publish_docs + client-payload: '{"version": "${{ github.event.client_payload.version }}"}' diff --git a/.github/workflows/publish_docs.yml b/.github/workflows/publish_docs.yml new file mode 100644 index 0000000..43d3371 --- /dev/null +++ b/.github/workflows/publish_docs.yml @@ -0,0 +1,63 @@ +name: Publish docs + +on: + repository_dispatch: + types: + - publish_docs + +jobs: + publish_docs: + name: Publish docs + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Publish docs + run: | + set -x + + VERSION=${{ github.event.client_payload.version }} + + if [ -z "${VERSION}" ]; then + echo "::error::version in client_payload is not set" + exit 1 + fi + if [ -z "${{ secrets.S3_BUCKET }}" ]; then + echo "::error::secret S3_BUCKET is not set" + exit 1 + fi + if [ -z "${{ secrets.CF_DISTRIBUTION_ID }}" ]; then + echo "::error::secret CF_DISTRIBUTION_ID is not set" + exit 1 + fi + + # Fetch and extract the docs + curl --fail -s -L -o docs-ai.tar.xz https://proxy.binaries.openttd.org/openttd-nightlies/${VERSION}/openttd-${VERSION}-docs-ai.tar.xz + curl --fail -s -L -o docs-gs.tar.xz https://proxy.binaries.openttd.org/openttd-nightlies/${VERSION}/openttd-${VERSION}-docs-gs.tar.xz + curl --fail -s -L -o docs.tar.xz https://proxy.binaries.openttd.org/openttd-nightlies/${VERSION}/openttd-${VERSION}-docs.tar.xz + tar xf docs-ai.tar.xz + tar xf docs-gs.tar.xz + tar xf docs.tar.xz + + # Sync all the new/modified files + aws s3 sync --only-show-errors docs/root/ s3://${{ secrets.S3_BUCKET }}/ + aws s3 sync --only-show-errors docs/errors/ s3://${{ secrets.S3_BUCKET }}/errors/ + aws s3 sync --only-show-errors openttd-${VERSION}-docs-ai/html/ s3://${{ secrets.S3_BUCKET }}/ai-api/ + aws s3 sync --only-show-errors openttd-${VERSION}-docs-gs/html/ s3://${{ secrets.S3_BUCKET }}/gs-api/ + aws s3 sync --only-show-errors openttd-${VERSION}-docs/html/ s3://${{ secrets.S3_BUCKET }}/source/ + + # Delete any unknown file; this is a separate step, as 'aws s3 sync' + # can delete before uploading, which could mean files temporary link + # to invalid files. + aws s3 sync --only-show-errors --delete docs/errors/ s3://${{ secrets.S3_BUCKET }}/errors/ + aws s3 sync --only-show-errors --delete openttd-${VERSION}-docs-ai/html/ s3://${{ secrets.S3_BUCKET }}/ai-api/ + aws s3 sync --only-show-errors --delete openttd-${VERSION}-docs-gs/html/ s3://${{ secrets.S3_BUCKET }}/gs-api/ + aws s3 sync --only-show-errors --delete openttd-${VERSION}-docs/html/ s3://${{ secrets.S3_BUCKET }}/source/ + + # Invalidate the cache of the CloudFront distribution + aws cloudfront create-invalidation --distribution-id ${{ secrets.CF_DISTRIBUTION_ID }} --paths "/*" + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/README.md b/README.md new file mode 100644 index 0000000..07d82d7 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# OpenTTD's workflows + +To automate all kinds of things, we use GitHub Actions, and especially, their workflow. +This repository runs a few workflows that don't belong to a repository we have. + +## Workflows + +- [New OpenTTD Release](.github/workflows/new_openttd_release.yml): workflow that is triggered when a new OpenTTD binary is produced +- [Publish Docs](.github/workflows/publish_docs.yml): publishes the HTML docs to https://docs.openttd.org/ based on an openttd-nightly version. diff --git a/docs/errors/404.html b/docs/errors/404.html new file mode 100644 index 0000000..578cca5 --- /dev/null +++ b/docs/errors/404.html @@ -0,0 +1,12 @@ + + + + + 404 - Not Found + + +
+

404 - Not Found

+
+ + diff --git a/docs/root/index.html b/docs/root/index.html new file mode 100644 index 0000000..a589845 --- /dev/null +++ b/docs/root/index.html @@ -0,0 +1,15 @@ + + + + + OpenTTD documentation + + +
+

OpenTTD documentation

+ AI API documentation
+ GS API documentation
+ Source documentation
+
+ +