2021-02-28 12:14:12 +00:00
|
|
|
name: 'Documentation'
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
paths:
|
|
|
|
- '.github/workflows/deploy-docs.yml'
|
|
|
|
- 'docs/**'
|
2021-03-11 04:57:16 +00:00
|
|
|
# Responds to tags being pushed (branches and paths conditions above do not apply to tags).
|
|
|
|
# Takes a snapshot of the docs from the tag (unaffected by branch or path restraints above),
|
|
|
|
# Stores build in a subdirectory with name matching the git tag `v<MAJOR>.<MINOR>` substring:
|
|
|
|
tags:
|
|
|
|
- 'v[0-9]+.[0-9]+*'
|
2021-02-28 12:14:12 +00:00
|
|
|
|
2021-03-11 04:57:16 +00:00
|
|
|
env:
|
|
|
|
# Default docs version to build and deploy:
|
|
|
|
DOCS_VERSION: edge
|
|
|
|
# Assign commit authorship to official Github Actions bot when pushing to the `gh-pages` branch:
|
|
|
|
GIT_USER: 'github-actions[bot]'
|
|
|
|
GIT_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
|
2021-02-28 12:14:12 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
deploy:
|
2022-05-11 07:51:15 +00:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2021-02-28 12:14:12 +00:00
|
|
|
name: 'Deploy Docs'
|
|
|
|
runs-on: ubuntu-20.04
|
|
|
|
steps:
|
2022-03-08 22:57:01 +00:00
|
|
|
- uses: actions/checkout@v3
|
2021-02-28 12:14:12 +00:00
|
|
|
|
2021-03-11 04:57:16 +00:00
|
|
|
- name: 'Check if deploy is for a `v<major>.<minor>` tag version instead of `edge`'
|
|
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
|
|
working-directory: docs
|
|
|
|
run: |
|
|
|
|
DOCS_VERSION=$(grep -oE 'v[0-9]+\.[0-9]+' <<< "${GITHUB_REF}")
|
|
|
|
echo "DOCS_VERSION=${DOCS_VERSION}" >> "${GITHUB_ENV}"
|
|
|
|
|
|
|
|
# Docs should build referencing the tagged version instead:
|
|
|
|
sed -i "s|^\(site_url:.*\)edge|\1${DOCS_VERSION}|" mkdocs.yml
|
|
|
|
|
2021-02-28 12:14:12 +00:00
|
|
|
- name: 'Build with mkdocs-material via Docker'
|
2021-03-11 04:57:16 +00:00
|
|
|
working-directory: docs
|
docs(ci): Deploy Previews (#1988)
* docs(ci): Support deploy previews for documentation
Each PR that contributes to docs will generate a unique (to that PR) URL to preview the PR live for review.
* docs(ci): Split workflow
To support previews from non-collaborators PR contributions, we cannot rely on secrets access from workflows triggered by the `pull_request` event.
To do so securely, according to official advice from Github, we must run the third-party contribution in the restricted `pull_request` context, and then use a 2nd workflow to deploy the build (which requires secrets access).
* docs(ci): Rename doc workflows + add commit status
Better naming convention for documentation workflows.
Split workflow only indicated status on PR of the 1st stage (building the preview to deploy), not the deployment progress/result. This needs to be managed more directly until the action better supports split-workflow scenario.
* docs(ci): Add concurrency limit to preview deploy workflow
This would be more ideal on the 2nd phase workflow (`workflow_run`), however keeping it simple for now.
Limits the concurrency of the initial pull request workflow for documentation contributions that have PRs with multiple event triggers in a small time span (before the workflow triggered would complete). The main benefit is to avoid redundant deploys if the initial workflow has been triggered again to build the PR once more. It only will work against concurrent workflows for that PR in the 1st stage, if an existing `workflow_run` (2nd stage) is active for that PR it will not be cancelled.
* docs(ci): Add sponsor branding for deploy preview service
A requirement from Netlify for the [sponsored OSS organization plan](https://www.netlify.com/legal/open-source-policy).
* docs(ci): Use a shared build script
Production and Deploy Preview builds are now maintained via the same shell command, so version updates of docker image is in one place.
Additionally deletes unnecessary build output which upstream provides no support to exclude.
* docs: Add a custom 404 page
This is used by the preview deploys on Netlify. Production deploys on Github Pages require a top-level 404 page manually deployed (since all are deployed to a version subpath).
This 404 page was custom built and optimized by me. This is the final minified output, separate source to build is available if needed.
---
Likewise the `favicon.ico` is a fallback for browsers that implicitly check the domain root for this file if the SVG isn't supported/preferred. Browsers check for this file without it being present in the HTML head meta elements.
On Github Pages the `favicon.ico` isn't likely to be picked up by even top-level as typical deployment has the project name as a subpath. The docs however reference a PNG favicon which should be widely supported.
The `favicon.ico` was generated by RealFaviconGenerator online tool with SVG source input. It contains 16px, 32px and 48px sizes. Quality is better than the `favicon.io` generator.
* chore: Optimized logo
SVG source cleaned up and optimized with SVGO 2.3.
Minified versions (`.min.svg` extension) remove unnecessary data and white-space to reduce size further for production use. This extension better differentiates by filename that it's different from the `src` version.
2021-05-20 10:24:46 +00:00
|
|
|
run: '../.github/workflows/scripts/docs/build-docs.sh'
|
2021-03-11 04:57:16 +00:00
|
|
|
|
|
|
|
- name: 'If a tagged version, fix canonical links and remove `404.html`'
|
|
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
|
|
working-directory: docs/site
|
|
|
|
run: |
|
|
|
|
# 404 is not useful due to how Github Pages implement custom 404 support:
|
|
|
|
# (Note the edge 404.html isn't useful either as it's not copied to the `gh-pages` branch root)
|
|
|
|
rm 404.html
|
|
|
|
|
docs(ci): Deploy Previews (#1988)
* docs(ci): Support deploy previews for documentation
Each PR that contributes to docs will generate a unique (to that PR) URL to preview the PR live for review.
* docs(ci): Split workflow
To support previews from non-collaborators PR contributions, we cannot rely on secrets access from workflows triggered by the `pull_request` event.
To do so securely, according to official advice from Github, we must run the third-party contribution in the restricted `pull_request` context, and then use a 2nd workflow to deploy the build (which requires secrets access).
* docs(ci): Rename doc workflows + add commit status
Better naming convention for documentation workflows.
Split workflow only indicated status on PR of the 1st stage (building the preview to deploy), not the deployment progress/result. This needs to be managed more directly until the action better supports split-workflow scenario.
* docs(ci): Add concurrency limit to preview deploy workflow
This would be more ideal on the 2nd phase workflow (`workflow_run`), however keeping it simple for now.
Limits the concurrency of the initial pull request workflow for documentation contributions that have PRs with multiple event triggers in a small time span (before the workflow triggered would complete). The main benefit is to avoid redundant deploys if the initial workflow has been triggered again to build the PR once more. It only will work against concurrent workflows for that PR in the 1st stage, if an existing `workflow_run` (2nd stage) is active for that PR it will not be cancelled.
* docs(ci): Add sponsor branding for deploy preview service
A requirement from Netlify for the [sponsored OSS organization plan](https://www.netlify.com/legal/open-source-policy).
* docs(ci): Use a shared build script
Production and Deploy Preview builds are now maintained via the same shell command, so version updates of docker image is in one place.
Additionally deletes unnecessary build output which upstream provides no support to exclude.
* docs: Add a custom 404 page
This is used by the preview deploys on Netlify. Production deploys on Github Pages require a top-level 404 page manually deployed (since all are deployed to a version subpath).
This 404 page was custom built and optimized by me. This is the final minified output, separate source to build is available if needed.
---
Likewise the `favicon.ico` is a fallback for browsers that implicitly check the domain root for this file if the SVG isn't supported/preferred. Browsers check for this file without it being present in the HTML head meta elements.
On Github Pages the `favicon.ico` isn't likely to be picked up by even top-level as typical deployment has the project name as a subpath. The docs however reference a PNG favicon which should be widely supported.
The `favicon.ico` was generated by RealFaviconGenerator online tool with SVG source input. It contains 16px, 32px and 48px sizes. Quality is better than the `favicon.io` generator.
* chore: Optimized logo
SVG source cleaned up and optimized with SVGO 2.3.
Minified versions (`.min.svg` extension) remove unnecessary data and white-space to reduce size further for production use. This extension better differentiates by filename that it's different from the `src` version.
2021-05-20 10:24:46 +00:00
|
|
|
# Replace the tagged '${DOCS_VERSION}' in the 'canonical' link element of HTML files,
|
|
|
|
# to point to the 'edge' version of docs as the authoritative source:
|
2021-03-11 04:57:16 +00:00
|
|
|
find . -type f -name "*.html" -exec \
|
|
|
|
sed -i "s|^\(.*<link rel=\"canonical\".*\)${DOCS_VERSION}|\1edge|" \
|
|
|
|
{} +
|
2021-02-28 12:14:12 +00:00
|
|
|
|
|
|
|
- name: 'Deploy to Github Pages'
|
2022-10-24 17:42:28 +00:00
|
|
|
uses: peaceiris/actions-gh-pages@v3.9.0
|
2021-02-28 12:14:12 +00:00
|
|
|
with:
|
|
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
2021-03-11 04:57:16 +00:00
|
|
|
# Build directory contents to publish to the `gh-pages` branch:
|
2021-02-28 12:14:12 +00:00
|
|
|
publish_dir: ./docs/site
|
2021-03-11 04:57:16 +00:00
|
|
|
# Directory to place `publish_dir` contents on the `gh-pages` branch:
|
|
|
|
destination_dir: ${{ env.DOCS_VERSION }}
|
|
|
|
user_name: ${{ env.GIT_USER }}
|
|
|
|
user_email: ${{ env.GIT_EMAIL }}
|
|
|
|
|
|
|
|
add-version-to-docs:
|
2022-05-11 07:51:15 +00:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2021-03-11 04:57:16 +00:00
|
|
|
name: 'Update `versions.json` if necessary'
|
|
|
|
runs-on: ubuntu-20.04
|
|
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
|
|
# Avoid race condition with pushing to `gh-pages` branch by waiting for `deploy` to complete first
|
|
|
|
needs: deploy
|
|
|
|
steps:
|
|
|
|
- name: 'Checkout the tagged commit (shallow clone)'
|
2022-03-08 22:57:01 +00:00
|
|
|
uses: actions/checkout@v3
|
2021-03-11 04:57:16 +00:00
|
|
|
|
|
|
|
- name: 'Checkout the docs deployment branch to a subdirectory'
|
2022-03-08 22:57:01 +00:00
|
|
|
uses: actions/checkout@v3
|
2021-03-11 04:57:16 +00:00
|
|
|
with:
|
|
|
|
ref: gh-pages
|
|
|
|
path: gh-pages
|
|
|
|
|
|
|
|
# Updates `env.DOCS_VERSION` to the tag version; if invalid exits job early.
|
|
|
|
- name: 'Ensure `versions.json` has `v<major>.<minor>` substring from tag name'
|
|
|
|
id: add-version
|
|
|
|
continue-on-error: true
|
|
|
|
working-directory: gh-pages
|
|
|
|
run: '../.github/workflows/scripts/docs/update-versions-json.sh'
|
|
|
|
|
|
|
|
# If an actual change was made to `versions.json`, commit and push it.
|
|
|
|
# Otherwise the step is skipped instead of reporting job failure.
|
|
|
|
- name: 'Push update for `versions.json`'
|
|
|
|
if: ${{ steps.add-version.outcome == 'success' }}
|
|
|
|
working-directory: gh-pages
|
|
|
|
run: |
|
|
|
|
git config user.name ${{ env.GIT_USER }}
|
|
|
|
git config user.email ${{ env.GIT_EMAIL }}
|
|
|
|
git add versions.json
|
|
|
|
git commit -m "chore: Add ${{ env.DOCS_VERSION }} to version selector list"
|
|
|
|
git push
|