diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index ca4a6ad07..201f05a91 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -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*' @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/documentation-deploy-beta.yml b/.github/workflows/documentation-deploy-beta.yml index b630ddd24..14eb9e585 100644 --- a/.github/workflows/documentation-deploy-beta.yml +++ b/.github/workflows/documentation-deploy-beta.yml @@ -12,6 +12,9 @@ concurrency: group: "docs-beta-deploy" cancel-in-progress: false +env: + DESTINATION_OWNER: ${{ github.repository_owner }} + defaults: run: shell: bash @@ -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] diff --git a/.github/workflows/documentation-deploy-edge.yml b/.github/workflows/documentation-deploy-edge.yml index c4c116c7c..e31f283e5 100644 --- a/.github/workflows/documentation-deploy-edge.yml +++ b/.github/workflows/documentation-deploy-edge.yml @@ -4,8 +4,6 @@ on: push: branches: - 'master' - - 'main' - - 'edge' paths: - 'documentation/**' - 'hardware/**' diff --git a/.github/workflows/documentation-deploy-stable.yml b/.github/workflows/documentation-deploy-stable.yml index 6df75510c..c6575ff72 100644 --- a/.github/workflows/documentation-deploy-stable.yml +++ b/.github/workflows/documentation-deploy-stable.yml @@ -12,6 +12,9 @@ concurrency: group: "docs-stable-deploy" cancel-in-progress: false +env: + DESTINATION_OWNER: ${{ github.repository_owner }} + defaults: run: shell: bash @@ -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]