Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 54 additions & 90 deletions .github/workflows/documentation-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ on:
push:
branches:
- 'master'
- 'main'
- 'edge'
- 'beta'
- 'documentation/beta'
- 'software/beta'
- 'stable'
- 'documentation/stable'
- 'software/beta'
- 'software/stable'
tags:
- 'documentation/v*'
Expand All @@ -22,12 +18,27 @@ on:
description: 'Git ref (optional)'
required: false

env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_NAME: 'project-docs'
MAIN_BRANCH: 'master' # 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@v4

Expand All @@ -38,7 +49,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.11'
cache: 'poetry'
cache-dependency-path: |
documentation/poetry.lock
Expand All @@ -50,107 +61,59 @@ jobs:
- name: Import external assets
run: poetry -C ./documentation/ run poe --root ./documentation/ import-external-assets

- name: Make documentation ${{ matrix.variant }}
if: matrix.variant != 'default'
run: poetry -C ./documentation/ run poe --root ./documentation/ make-${{ matrix.variant }}

- name: Check documentation
run: poetry -C ./documentation/ run poe --root ./documentation/ check

- name: Build documentation
run: poetry -C ./documentation/ run poe --root ./documentation/ build

# Build and publish Docker container image
- name: Get Docker metadata
id: meta
uses: docker/metadata-action@v5
# 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:
images: ghcr.io/planktoscope/project-docs
tags: |
type=match,pattern=documentation/v(.*),group=1
type=edge,branch=master
type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', 'master') && github.ref != format('refs/heads/{0}', 'main') }}
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
type=sha

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
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@v5
with:
context: ./documentation
pull: true
push: ${{ github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'push tag' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# Upload documentation website as archive
- name: Upload website archive
uses: actions/upload-artifact@v4
with:
name: documentation-website
path: documentation/site

build-minimal:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

# Build minimal documentation website (without hardware setup guides, to save space)
- name: Install poetry
run: pipx install poetry==1.7.1

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'poetry'
cache-dependency-path: |
documentation/poetry.lock

- name: Install build dependencies
- 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: |
poetry -C ./documentation/ install
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: Import external assets
run: poetry -C ./documentation/ run poe --root ./documentation/ import-external-assets

- name: Make documentation minimal
run: poetry -C ./documentation/ run poe --root ./documentation/ make-minimal

- name: Check documentation
run: poetry -C ./documentation/ run poe --root ./documentation/ check

- name: Build documentation
run: poetry -C ./documentation/ run poe --root ./documentation/ build
- 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: ghcr.io/planktoscope/project-docs
images: ${{ steps.image_registry_case.outputs.lowercase }}
flavor: |
suffix=-minimal
suffix=${{ env.VARIANT_SUFFIX }}
tags: |
type=match,pattern=documentation/v(.*),group=1
type=edge,branch=master
type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', 'master') && github.ref != format('refs/heads/{0}', 'main') }}
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=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
type=sha
type=raw,value=sha-${{ env.ACTUAL_SHA }},enable=${{ env.ACTUAL_SHA != '' }},priority=100

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -159,6 +122,7 @@ jobs:
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
Expand All @@ -170,14 +134,14 @@ jobs:
with:
context: ./documentation
pull: true
push: ${{ github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'push tag' }}
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-minimal
name: documentation-website${{ env.VARIANT_SUFFIX }}
path: documentation/site
5 changes: 4 additions & 1 deletion .github/workflows/documentation-deploy-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ concurrency:
group: "docs-beta-deploy"
cancel-in-progress: false

env:
DESTINATION_OWNER: ${{ github.repository_owner }}

defaults:
run:
shell: bash
Expand Down Expand Up @@ -63,7 +66,7 @@ jobs:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
source-directory: documentation/site/
destination-github-username: PlanktoScope
destination-github-username: ${{ env.DESTINATION_OWNER }}
destination-repository-name: ${{ vars.REPOSITORY_NAME }}
user-email: github-actions[bot]@users.noreply.github.com
user-name: github-actions[bot]
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/documentation-deploy-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- 'master'
- 'main'
- 'edge'
paths:
- 'documentation/**'
- 'hardware/**'
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/documentation-deploy-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ concurrency:
group: "docs-stable-deploy"
cancel-in-progress: false

env:
DESTINATION_OWNER: ${{ github.repository_owner }}

defaults:
run:
shell: bash
Expand Down Expand Up @@ -60,7 +63,7 @@ jobs:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
source-directory: documentation/site/
destination-github-username: PlanktoScope
destination-github-username: ${{ env.DESTINATION_OWNER }}
destination-repository-name: ${{ vars.REPOSITORY_NAME }}
user-email: github-actions[bot]@users.noreply.github.com
user-name: github-actions[bot]
Expand Down