Skip to content

Build & deploy Manual to GitHub Pages #145

Build & deploy Manual to GitHub Pages

Build & deploy Manual to GitHub Pages #145

name: Build & deploy Manual to GitHub Pages
on:
workflow_dispatch:
push:
branches:
- main
env:
nf-archives: '["UbuntuSans", "SpaceMono"]'
nf-version: v3.2.1
nf-default: UbuntuSans
jobs:
# Generate NerdFont fonts matrix ##
nf-gen-matrix:
name: Generate NerdFont matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.nf-gen-matrix.outputs.matrix }}
steps:
- name: Set matrix
id: nf-gen-matrix
run: |
echo matrix=${{ toJSON('["SpaceMono", "UbuntuSans"]') }} >> $GITHUB_OUTPUT
## Ensure the nf-web artifact exists or the font jobs fail ##
nf-create-artifact:
name: Create NerdFonts artifact
runs-on: ubuntu-latest
permissions: write-all
needs:
- nf-gen-matrix
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
docs/assets/fonts/
- name: Create Fonts artifact
run: echo "Creating nf-web artifact"
- name: Add placeholder so artifact exists
run: |
cd docs/assets/fonts/
echo "tmp" > .exists
- uses: actions/upload-artifact@v4
id: nf-create-artifact
with:
name: nf-web
path: docs/assets/fonts/
retention-days: 1
## Fetch/process/cache fonts ##
get_fonts:
name: Fetch & Process NerdFonts
needs:
- nf-gen-matrix
- nf-create-artifact
runs-on: ubuntu-latest
strategy:
matrix:
archive: ${{ fromJSON(needs.nf-gen-matrix.outputs.matrix) }}
max-parallel: 1
steps:
- name: debug output matrix.archive
run: |
echo " -- Matrix archive:"
echo ${{ matrix.archive }}
- uses: actions/download-artifact@v4
with:
name: nf-web
path: docs/assets/fonts/
continue-on-error: true
merge-multiple: true
- uses: actions/cache@v4
id: cache
with:
font-path: data/fonts/${{ matrix.archive }}NerdFont
path: |
"data/assets/fonts/${{ matrix.archive }}NerdFont"
${{ matrix.archive == env.nf-default && 'docs/assets/fonts/default-font.css' || '/dev/null' }}
key: "${{ matrix.archive }}-${{ env.nf-version }}"
- name: Checkout processing script
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
sparse-checkout: |
docs/scripts/nerdfontweb.py
docs/assets/fonts/
- name: Setup Python
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/[email protected]
with:
python-version: '3.12'
cache: 'pip'
- name: Download, unpack, and process NerdFonts
if: steps.cache.outputs.cache-hit != 'true'
id: process_fonts
#with:
#env:
#archive: ${{ matrix.archive }} == ${{ env.nf-default }} && '--gen-default' || '' }}
#env:
# ${{ if eq(archive, env.nf-default) }}:font: default
run: |
default="${{ env.nf-archive == matrix.archive && '--gen-default' || '' }}"
python docs/scripts/nerdfontweb.py --version ${{ env.nf-version}} ${default} --mkdocs ${{ matrix.archive }}
- uses: actions/upload-artifact@v4
with:
name: nf-web
path: docs/assets/fonts/
overwrite: true
retention-days: 1
## Compile SASS ##
compile_sass:
name: Compile SASS
runs-on: ubuntu-latest
steps:
- name: Checkout SASS files
uses: actions/checkout@v4
with:
sparse-checkout: |
docs/assets/stylesheets/
- name: Install sassc
run: sudo apt-get install -y sassc
- name: Compile SASS
run: |
for file in docs/assets/stylesheets/*.sass; do
sassc --sass $file ${file%.sass}.compiled.css
done
- name: Upload compiled CSS
uses: actions/upload-artifact@v4
with:
name: compiled-css
path: docs/assets/stylesheets/*.compiled.css
retention-days: 1
## Build job ##
build:
name: Build manual pages
needs:
- get_fonts
- compile_sass
runs-on: ubuntu-latest
steps:
- name: Configure GitHub Pages
uses: actions/configure-pages@v5
- name: Checkout main
uses: actions/checkout@v4
with:
sparse-checkout: |
.github
docs
#- uses: actions/cache/restore@v4
# with:
# path: |
# docs/assets/fonts/${{env.font}}NerdFont
# docs/assets/fonts/default-font.css
# key: "${{ env.font }}-${{ env.version }}"
# fail-on-cache-miss: true
- uses: actions/download-artifact@v4
with:
name: nf-web
path: docs/assets/fonts/
- uses: actions/download-artifact@v4
with:
name: compiled-css
path: docs/assets/stylesheets/
- name: Setup Python
uses: actions/[email protected]
with:
python-version: '3.12'
cache: 'pip'
- name: Install python modules
run: pip install -r docs/requirements.txt
- name: Generate site files
run: mkdocs build
- name: Upload GitHub Pages artifact
uses: actions/[email protected]
with:
path: "site/"
## Deploy job ##
deploy:
name: Deploy manual pages
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected]
## Clear artifact as necessary
nf-clear-artifact:
name: Clear NerdFonts artifact
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Clear Fonts artifact
run: echo "Clearing nf-web artifact in case it exists from previous run"
- uses: geekyeggo/delete-artifact@v5
with:
name: nf-web
- name: Clear CSS artifact
run: echo "Clearing compiled-css artifact in case it exists from previous run"
- uses: geekyeggo/delete-artifact@v5
with:
name: compiled-css