Skip to content

Update docs

Update docs #347

Workflow file for this run

name: Update docs
on:
push:
tags:
- "v*.*.*" # all semver release tags
workflow_run:
workflows:
- Tests
branches:
- main
types:
- completed
jobs:
publish-docs:
runs-on: ubuntu-latest
container:
image: node:20
steps:
- name: Checkout current commit
uses: actions/checkout@v4
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: ./gh-pages
- run: apt-get update && apt-get install jq -y
- run: npm install -g npm@10
- run: npm install
- name: Set VERSION env to devel (default)
run: |
echo "VERSION=devel" >> $GITHUB_ENV
echo "IS_PREVIEW=1" >> $GITHUB_ENV
echo "IS_BACKPORT=0" >> $GITHUB_ENV
- name: Set VERSION env from tag name
if: startsWith(github.ref, 'refs/tags/v')
run: |
export REF_NAME=${{github.ref_name}}
export VERSION=${REF_NAME:1}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "IS_PREVIEW=$(node -p "Number('${VERSION}'.includes('-'))")" >> $GITHUB_ENV
echo "IS_BACKPORT=$(node -p "Number(require('semver').lt('${VERSION}','$(tail -n 1 gh-pages/VERSION.md)'))")" >> $GITHUB_ENV
- name: Update VERSION / latest
if: env.IS_BACKPORT != 1 && env.IS_PREVIEW != 1
run: |
echo '---\npermalink: /VERSION\ntitle: "VERSION"\n---\n' > gh-pages/VERSION.md
echo $VERSION >> gh-pages/VERSION
unlink gh-pages/latest
ln -s $VERSION gh-pages/latest
- name: Update CHANGELOG / MIGRATING
if: env.IS_BACKPORT != 1
run: |
echo '---\npermalink: /CHANGELOG\ntitle: "CHANGELOG"\n---\n' > gh-pages/CHANGELOG.md
cat CHANGELOG.md >> gh-pages/CHANGELOG.md
echo '---\npermalink: /MIGRATING\ntitle: "Migration Guide"\n---\n' > gh-pages/MIGRATING.md
cat MIGRATING.md >> gh-pages/MIGRATING.md
- name: Remove old docs if present
run: |
rm -rf gh-pages/${VERSION}
- name: Rebuild docs for tag
if: env.VERSION != 'devel'
run: |
./node_modules/.bin/typedoc --includeVersion --sourceLinkTemplate "https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/src/{path}#L{line}" --out gh-pages/${VERSION}
node -p 'var all=fs.readdirSync("gh-pages",{withFileTypes:true}).flatMap(f=>f.isDirectory()&&!isNaN(f.name.charAt(0))?[f.name]:[]).sort(require("semver").rcompare);JSON.stringify({all,stable:all.filter(s=>!s.includes("-"))})' > gh-pages/_data/versions.json
- name: Rebuild docs for devel
if: env.VERSION == 'devel'
run: |
./node_modules/.bin/typedoc --sourceLinkTemplate "https://github.com/${{ github.repository }}/blob/${{ github.sha }}/src/{path}#L{line}" --out gh-pages/${VERSION}
- name: Commit to gh-pages
uses: EndBug/add-and-commit@v9
with:
cwd: ./gh-pages
push: origin gh-pages --force
message: Update ${{ env.VERSION }} docs via ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ github.token }}