Update simulator documentation #54
Workflow file for this run
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: Build & Publish | |
on: | |
push: | |
branches: | |
- main | |
pull_request: {} | |
jobs: | |
build-validate: | |
env: | |
# ruby/setup-ruby@v1 does not offer a way to change the cached gems path. | |
# See https://github.com/ruby/setup-ruby/issues/291 | |
GLOBAL_GEMS: 1 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
cache-version: 3 | |
- name: Build & Validate | |
run: rake validate | |
- name: Upload Pages artifact | |
uses: actions/upload-pages-artifact@v3 | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build container | |
run: docker compose build | |
- name: Build site in container | |
run: docker compose run docs rake build | |
changes: | |
runs-on: ubuntu-latest | |
if: github.ref != 'refs/heads/main' | |
outputs: | |
build-system: ${{ steps.filter.outputs.build-system }} | |
steps: | |
- name: Check if build system changed | |
uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: | | |
build-system: | |
- _config.yml | |
- .github/**/* | |
- Gemfile* | |
- Rakefile | |
build-main: | |
needs: | |
- changes | |
if: needs.changes.outputs.build-system == 'true' | |
env: | |
# ruby/setup-ruby@v1 does not offer a way to change the cached gems path. | |
# See https://github.com/ruby/setup-ruby/issues/291 | |
GLOBAL_GEMS: 1 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: main | |
submodules: recursive | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
cache-version: 2 | |
- name: Build | |
run: rake build | |
- name: Upload reference artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
name: build-from-main | |
diff: | |
runs-on: ubuntu-latest | |
needs: | |
- build-validate | |
- build-main | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Download artifact from this branch's build | |
uses: actions/download-artifact@v4 | |
with: | |
name: github-pages | |
- name: Unpack local build | |
run: | | |
mkdir local | |
pushd local | |
tar --extract --file ../artifact.tar | |
popd | |
mv artifact.tar local.tar | |
- name: Download artifact from main branch build | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-from-main | |
- name: Unpack main build | |
run: | | |
mkdir main | |
pushd main | |
tar --extract --file ../artifact.tar | |
popd | |
mv artifact.tar main.tar | |
- name: Normalise JSON | |
shell: python | |
run: | | |
import json | |
from pathlib import Path | |
ROOTS = [ | |
Path('main'), | |
Path('local'), | |
] | |
FILES = [ | |
'redirects.json', | |
] | |
for root in ROOTS: | |
for name in FILES: | |
p = root / name | |
p.write_text(json.dumps( | |
json.loads(p.read_text()), | |
sort_keys=True, | |
)) | |
- name: Diff | |
id: diff | |
run: | | |
set +e | |
diff -ru main local > ./result.diff | |
result=$? | |
set -euo pipefail | |
delimiter="gha-delim-$RANDOM-$RANDOM-gha-delim" | |
{ | |
echo "diff<<${delimiter}" | |
cat ./result.diff | |
echo "${delimiter}" | |
} >> "$GITHUB_OUTPUT" | |
cat ./result.diff | |
if [[ $result -ne 0 ]] | |
then | |
echo has-changes=true >> "$GITHUB_OUTPUT" | |
else | |
echo has-changes=false >> "$GITHUB_OUTPUT" | |
fi | |
- name: Build comment | |
id: build-comment | |
if: always() | |
run: | | |
{ | |
if [[ "${{ steps.diff.outputs.has-changes }}" = "true" ]] | |
then | |
echo "🔀 Build diff:" | |
echo '```diff' | |
cat ./result.diff | |
echo '```' | |
else | |
echo "Build has no changes." | |
fi | |
} > ./comment.md | |
- name: Post diff to PR | |
uses: thollander/actions-comment-pull-request@v2 | |
if: always() | |
with: | |
comment_tag: build-diff | |
filePath: ./comment.md | |
deploy: | |
name: Deploy to GitHub Pages | |
runs-on: ubuntu-latest | |
needs: build-validate | |
if: ${{ github.ref == 'refs/heads/main' }} | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
# Tell GitHub where we deployed to | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |