Skip to content

os: Remove documentation from OS (#960) #2172

os: Remove documentation from OS (#960)

os: Remove documentation from OS (#960) #2172

name: build-documentation
on:
push:
branches:
- 'main'
- 'documentation/beta'
- 'documentation/stable'
- 'software/beta'
- 'software/stable'
tags:
- 'documentation/v*'
pull_request:
paths:
- 'documentation/**'
- 'hardware/**'
- '.github/workflows/documentation-build.yml'
merge_group:
workflow_dispatch:
inputs:
git-ref:
description: 'Git ref (optional)'
required: false
env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_NAME: 'project-docs'
MAIN_BRANCH: 'main' # pushing to the main branch will update the "edge" tag on the image
BETA_BRANCH: 'documentation/beta' # pushing to this branch will update the "beta" tag on the image
STABLE_BRANCH: 'documentation/stable' # pushing to this branch will update the "stable" tag on the image
TAG_PREFIX: 'documentation/v' # pushing tags with this prefix will add a version tag to the image and update the "latest" tag on the image
PUSH_IMAGE: ${{ (github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork) || github.event_name == 'push' || github.event_name == 'push tag' }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
variant:
- default
- minimal # (without hardware setup guides, to save space)
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- name: Set up Python
run: uv python install
- name: Install dependencies
working-directory: ./documentation
run: |
uv sync --locked
- name: Make documentation ${{ matrix.variant }}
if: matrix.variant != 'default'
working-directory: documentation
run: uv run poe make-${{ matrix.variant }}
- name: Check documentation
working-directory: documentation
run: uv run poe check
- name: Build documentation
working-directory: documentation
run: uv run poe build
# Work around a bug where capital letters in the GitHub username (e.g. "PlanktoScope") make it
# impossible to push to GHCR. See https://github.com/macbre/push-to-ghcr/issues/12
- name: Lowercase image registry and owner
id: image_registry_case
uses: ASzc/change-string-case-action@v6
with:
string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Get actual commit SHA
# Get the SHA of the actual commit (not the fake merge commit) on PR-triggered runs
# (refer to https://stackoverflow.com/a/68068674/23202949):
run: |
if [[ -n "${{ github.event.pull_request.head.sha }}" ]]; then
printf "ACTUAL_SHA=%.7s" "${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
elif [[ ${{ env.PUSH_IMAGE }} = "true" ]]; then
printf "ACTUAL_SHA=%.7s" "${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Set documentation variant suffix
run: |
if [[ '${{ matrix.variant }}' != 'default' ]]; then
echo 'VARIANT_SUFFIX=-${{ matrix.variant}}' >> $GITHUB_ENV
fi
# Build and publish Docker container image
- name: Get Docker metadata
id: meta
uses: docker/metadata-action@v5
env:
IS_MAIN_BRANCH: ${{ github.ref == format('refs/heads/{0}', env.MAIN_BRANCH) }}
IS_BETA_BRANCH: ${{ github.ref == format('refs/heads/{0}', env.BETA_BRANCH) }}
IS_STABLE_BRANCH: ${{ github.ref == format('refs/heads/{0}', env.STABLE_BRANCH) }}
with:
images: ${{ steps.image_registry_case.outputs.lowercase }}
flavor: |
suffix=${{ env.VARIANT_SUFFIX }}
tags: |
type=match,pattern=${{ env.TAG_PREFIX }}(.*),group=1 # this implicitly updates latest
type=raw,value=stable,enable=${{ env.IS_STABLE_BRANCH }},priority=702
type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701
type=edge,branch=${{ env.MAIN_BRANCH }}
type=ref,event=pr
type=raw,value=sha-${{ env.ACTUAL_SHA }},enable=${{ env.ACTUAL_SHA != '' }},priority=100
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: env.PUSH_IMAGE == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./documentation
pull: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ env.PUSH_IMAGE }}
# Upload documentation website as archive
- name: Upload website archive
uses: actions/upload-artifact@v4
with:
name: documentation-website${{ env.VARIANT_SUFFIX }}
path: documentation/site