Navigation Menu

Skip to content

Commit

Permalink
Add: workflow to automate publishing of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Jan 16, 2020
1 parent 4e0ce2e commit 951e908
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .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 }}"}'
63 changes: 63 additions & 0 deletions .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 }}
9 changes: 9 additions & 0 deletions 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.
12 changes: 12 additions & 0 deletions docs/errors/404.html
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>404 - Not Found</title>
</head>
<body>
<main>
<h1>404 - Not Found</h1>
</main>
</body>
</html>
15 changes: 15 additions & 0 deletions docs/root/index.html
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>OpenTTD documentation</title>
</head>
<body>
<main>
<h1>OpenTTD documentation</h1>
<a href="ai-api/index.html">AI API documentation</a><br />
<a href="gs-api/index.html">GS API documentation</a><br />
<a href="source/index.html">Source documentation</a><br />
</main>
</body>
</html>

0 comments on commit 951e908

Please sign in to comment.