|
| 1 | +name: build-docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'master' |
| 7 | + - 'main' |
| 8 | + tags: |
| 9 | + - 'v*' |
| 10 | + pull_request: |
| 11 | + merge_group: |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + git-ref: |
| 15 | + description: 'Git ref (optional)' |
| 16 | + required: false |
| 17 | + |
| 18 | +env: |
| 19 | + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} |
| 20 | + IMAGE_NAME: 'project-docs' |
| 21 | + MAIN_BRANCH: 'master' # pushing to the main branch will update the "edge" tag on the image |
| 22 | + BETA_BRANCH: 'beta' # pushing to this branch will update the "beta" tag on the image |
| 23 | + STABLE_BRANCH: 'stable' # pushing to this branch will update the "stable" tag on the image |
| 24 | + TAG_PREFIX: 'v' # pushing tags with this prefix will add a version tag to the image and update the "latest" tag on the image |
| 25 | + PUSH_IMAGE: ${{ (github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork) || github.event_name == 'push' || github.event_name == 'push tag' }} |
| 26 | + |
| 27 | +jobs: |
| 28 | + build: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + packages: write |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + variant: |
| 37 | + - default |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + # Only fetch files we actually need: |
| 42 | + fetch-depth: 0 |
| 43 | + filter: 'blob:none' |
| 44 | + |
| 45 | + # Build documentation website |
| 46 | + - name: Install poetry |
| 47 | + run: pipx install poetry==2.1.3 |
| 48 | + |
| 49 | + - name: Set up Node |
| 50 | + uses: actions/setup-node@v2 |
| 51 | + with: |
| 52 | + node-version: "19" # FIXME: this is very old and out-of-date. Bump the version! |
| 53 | + |
| 54 | + - name: Install build dependencies |
| 55 | + run: | |
| 56 | + npm install |
| 57 | +
|
| 58 | + - name: Make documentation ${{ matrix.variant }} |
| 59 | + if: matrix.variant != 'default' |
| 60 | + working-directory: documentation |
| 61 | + run: npm run make-${{ matrix.variant }} |
| 62 | + |
| 63 | + - name: Build documentation |
| 64 | + run: npm run build |
| 65 | + |
| 66 | + # Work around a bug where capital letters in the GitHub username (e.g. "PlanktoScope") make it |
| 67 | + # impossible to push to GHCR. See https://github.com/macbre/push-to-ghcr/issues/12 |
| 68 | + - name: Lowercase image registry and owner |
| 69 | + id: image_registry_case |
| 70 | + uses: ASzc/change-string-case-action@v6 |
| 71 | + with: |
| 72 | + string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} |
| 73 | + |
| 74 | + - name: Set documentation variant suffix |
| 75 | + run: | |
| 76 | + if [[ '${{ matrix.variant }}' != 'default' ]]; then |
| 77 | + echo 'VARIANT_SUFFIX=-${{ matrix.variant}}' >> $GITHUB_ENV |
| 78 | + fi |
| 79 | +
|
| 80 | + # Build and publish Docker container image |
| 81 | + - name: Get Docker metadata |
| 82 | + id: meta |
| 83 | + uses: docker/metadata-action@v5 |
| 84 | + env: |
| 85 | + DOCKER_METADATA_PR_HEAD_SHA: true |
| 86 | + IS_MAIN_BRANCH: ${{ github.ref == format('refs/heads/{0}', env.MAIN_BRANCH) }} |
| 87 | + IS_BETA_BRANCH: ${{ github.ref == format('refs/heads/{0}', env.BETA_BRANCH) }} |
| 88 | + IS_STABLE_BRANCH: ${{ github.ref == format('refs/heads/{0}', env.STABLE_BRANCH) }} |
| 89 | + with: |
| 90 | + images: ${{ steps.image_registry_case.outputs.lowercase }} |
| 91 | + flavor: | |
| 92 | + suffix=${{ env.VARIANT_SUFFIX }} |
| 93 | + tags: | |
| 94 | + type=match,pattern=${{ env.TAG_PREFIX }}(.*),group=1 # this implicitly updates latest |
| 95 | + type=raw,value=stable,enable=${{ env.IS_STABLE_BRANCH }},priority=702 |
| 96 | + type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 |
| 97 | + type=edge,branch=${{ env.MAIN_BRANCH }} |
| 98 | + type=ref,event=pr |
| 99 | + type=sha,priority=100 |
| 100 | +
|
| 101 | + - name: Set up QEMU |
| 102 | + uses: docker/setup-qemu-action@v3 |
| 103 | + |
| 104 | + - name: Set up Docker Buildx |
| 105 | + uses: docker/setup-buildx-action@v3 |
| 106 | + |
| 107 | + - name: Log in to GitHub Container Registry |
| 108 | + if: env.PUSH_IMAGE == 'true' |
| 109 | + uses: docker/login-action@v3 |
| 110 | + with: |
| 111 | + registry: ghcr.io |
| 112 | + username: ${{ github.repository_owner }} |
| 113 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + |
| 115 | + - name: Build and push |
| 116 | + uses: docker/build-push-action@v6 |
| 117 | + with: |
| 118 | + context: ./documentation |
| 119 | + pull: true |
| 120 | + platforms: linux/amd64,linux/arm64 |
| 121 | + tags: ${{ steps.meta.outputs.tags }} |
| 122 | + labels: ${{ steps.meta.outputs.labels }} |
| 123 | + push: ${{ env.PUSH_IMAGE }} |
| 124 | + |
| 125 | + # Upload documentation website as archive |
| 126 | + - name: Upload website archive |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: documentation-website${{ env.VARIANT_SUFFIX }} |
| 130 | + path: documentation/site |
0 commit comments