docs #1814
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 docs | |
on: | |
push: | |
branches: | |
- master | |
repository_dispatch: | |
types: [docs] | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build docs | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# you must not use anything but include here or the version.json generation will fail! | |
include: | |
- version: "1.10.2" | |
source: "tags" | |
python: "3.7" | |
sphinx: "4.5.0" | |
mermaid: "0.7.1" | |
jinja: "3.1.1" | |
mermaid_fix: "true" | |
- version: "master" | |
source: "heads" | |
python: "3.7" | |
sphinx: "4.5.0" | |
mermaid: "0.7.1" | |
jinja: "3.1.1" | |
mermaid_fix: "true" | |
- version: "maintenance" | |
source: "heads" | |
python: "3.7" | |
sphinx: "4.5.0" | |
mermaid: "0.7.1" | |
jinja: "3.1.1" | |
mermaid_fix: "true" | |
- version: "devel" | |
source: "heads" | |
python: "3.7" | |
sphinx: "4.5.0" | |
mermaid: "0.7.1" | |
jinja: "3.1.1" | |
mermaid_fix: "true" | |
steps: | |
- name: π§Ύ Log event & matrix | |
run: | | |
echo "Event: ${{ github.event_name }} - ${{ toJson(github.event.client_payload) }}" | |
echo "Matrix: ${{ matrix.version }}, ${{ matrix.source }}, ${{ matrix.python }}, ${{ matrix.mermaid }}, ${{ matrix.mermaid_fix }}" | |
echo "Formatted ref: ${{ format('refs/{0}/{1}', matrix.source, matrix.version) }}" | |
- name: β¬ Checkout docs.octoprint.org | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
uses: actions/checkout@v4 | |
with: | |
path: docs.octoprint.org | |
- name: π Determine latest OctoPrint release | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
run: | | |
OCTOPRINT_VERSION=$(curl -i https://github.com/OctoPrint/OctoPrint/releases/latest | grep -i location: | head -n1 | awk -F/ '{print $NF}' | tr -d '\r') | |
echo "OCTOPRINT_VERSION=$OCTOPRINT_VERSION" >> $GITHUB_ENV | |
- name: π Set up Python ${{ matrix.python }} | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: π Preinstall some dependencies | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
run: | | |
pip install sphinx==${{ matrix.sphinx }} sphinxcontrib-mermaid==${{ matrix.mermaid }} Jinja2==${{ matrix.jinja }} | |
- name: π Set up NodeJS | |
if: matrix.mermaid_fix == 'true' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version)) | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "16" | |
- name: π Install mermaid-cli | |
if: matrix.mermaid_fix == 'true' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version)) | |
run: | | |
npm install @mermaid-js/mermaid-cli | |
- name: β¬ Checkout OctoPrint | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
uses: actions/checkout@v4 | |
with: | |
repository: "OctoPrint/OctoPrint" | |
ref: ${{ matrix.version }} | |
path: OctoPrint | |
- name: π Install OctoPrint | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
run: | | |
cd ${{ github.workspace }}/OctoPrint | |
pip install .[develop,docs] | |
- name: π Generate versions.json | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
run: | | |
python ${{ github.workspace }}/docs.octoprint.org/util/versions_from_matrix.py ${{ github.workspace }}/docs.octoprint.org/.github/workflows/docs.yaml versions.json | |
- name: π Build docs | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
run: | | |
cd ${{ github.workspace }}/docs.octoprint.org/util/versionselector | |
if [[ "${{ matrix.mermaid_fix }}" == "true" ]]; then | |
python versionselector.py ${{ github.workspace }}/OctoPrint/docs/ ${{ matrix.version }} ${{ env.OCTOPRINT_VERSION }} ${{ github.workspace }}/versions.json -D mermaid_cmd=${{ github.workspace }}/node_modules/.bin/mmdc -D mermaid_output_format=svg -D mermaid_version= | |
echo ".rst-content object[type^='image/']{width: 100%;}" >> ${{ github.workspace }}/OctoPrint/docs/_build/html/${{ matrix.version }}/_static/theme_overrides.css | |
else | |
python versionselector.py ${{ github.workspace }}/OctoPrint/docs/ ${{ matrix.version }} ${{ env.OCTOPRINT_VERSION }} ${{ github.workspace }}/versions.json | |
fi | |
#- name: π Run link check | |
# id: lc | |
# uses: peter-evans/link-checker@v1 | |
# with: | |
# args: -v -r -d ./OctoPrint/docs/_build/html/${{ matrix.version }} ./OctoPrint/docs/_build/html/${{ matrix.version }} | |
#- name: π Evaluate link check | |
# run: exit ${{ steps.lc.outputs.exit_code }} | |
- name: β¬ Persist build result | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.client_payload.ref == format('refs/{0}/{1}', matrix.source, matrix.version) | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.version }} | |
path: ${{ github.workspace }}/OctoPrint/docs/_build/html/${{ matrix.version }} | |
deploy: | |
name: Deploy docs | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: β¬ Checkout docs.octoprint.org | |
uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
path: docs | |
- name: β¬ Fetch all artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: artifacts | |
- name: π§Ή Cleanup all docs | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
run: | | |
count=`ls -1 artifacts | wc -l` | |
if [ $count != '0' ]; then | |
rm -rf docs/* || true | |
touch docs/.nojekyll | |
cp -rv artifacts/* docs | |
fi | |
- name: π§Ή Cleanup regenerated docs | |
if: github.event_name == 'repository_dispatch' | |
run: | | |
version="${{ github.event.client_payload.ref }}" | |
version=${version#"refs/heads/"} | |
version=${version#"refs/tags/"} | |
echo "Version is $version" | |
if [ -d "artifacts/$version" ]; then | |
rm -rf docs/$version || true | |
cp -r artifacts/$version docs/ | |
fi | |
- name: π Commit & deploy | |
uses: EndBug/add-and-commit@v9 | |
with: | |
cwd: "docs" | |
message: "Publish new build of docs" | |
default_author: github_actions |