From d12c4760c3ca5aae3309227363b6e22f213f51ab Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 13:23:53 -0700 Subject: [PATCH 01/15] Try to fix `docker/build-push-action` in PRs from external forks --- .github/workflows/documentation-build.yml | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index ca4a6ad07..d9b55e8ee 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -22,6 +22,10 @@ on: description: 'Git ref (optional)' required: false +env: + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} + IMAGE_NAME: project-docs + jobs: build: runs-on: ubuntu-latest @@ -56,12 +60,20 @@ jobs: - name: Build documentation run: poetry -C ./documentation/ run poe --root ./documentation/ build + # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. + # https://github.com/macbre/push-to-ghcr/issues/12 + - name: Lowercase Registry + id: registry_case + uses: ASzc/change-string-case-action@v6 + with: + string: ${{ env.IMAGE_REGISTRY }} + # Build and publish Docker container image - name: Get Docker metadata id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/planktoscope/project-docs + images: ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} tags: | type=match,pattern=documentation/v(.*),group=1 type=edge,branch=master @@ -136,12 +148,20 @@ jobs: - name: Build documentation run: poetry -C ./documentation/ run poe --root ./documentation/ build + # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. + # https://github.com/macbre/push-to-ghcr/issues/12 + - name: Lowercase Registry + id: registry_case + uses: ASzc/change-string-case-action@v6 + with: + string: ${{ env.IMAGE_REGISTRY }} + # Build and publish Docker container image - name: Get Docker metadata id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/planktoscope/project-docs + images: ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} flavor: | suffix=-minimal tags: | From 09df012d631d1fd4c6e30625a50cea2befa39b4d Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 14:07:25 -0700 Subject: [PATCH 02/15] Try again to use the owner of the head branch in PRs from external forks --- .github/workflows/documentation-build.yml | 28 +++++++++++++------ .../workflows/documentation-deploy-beta.yml | 5 +++- .../workflows/documentation-deploy-stable.yml | 5 +++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index d9b55e8ee..a290f6662 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -23,8 +23,14 @@ on: required: false env: - IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} + IMAGE_REGISTRY: ghcr.io + IMAGE_OWNER: ${{ github.repository_owner }} IMAGE_NAME: project-docs + # Note: the image will be published to IMAGE_REGISTRY/IMAGE_OWNER/IMAGE_NAME, + # which defaults to ghcr.io/PlanktoScope/project-docs. But in PRs from external forks by other + # people we will try to publish the image under that person instead, because we can't publish + # to ghcr.io/PlanktoScope in GitHub Actions workflow runs triggered by PRs from external forks + # (see https://github.com/PlanktoScope/device-backend/pull/30 for details). jobs: build: @@ -60,20 +66,24 @@ jobs: - name: Build documentation run: poetry -C ./documentation/ run poe --root ./documentation/ build - # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. - # https://github.com/macbre/push-to-ghcr/issues/12 - - name: Lowercase Registry - id: registry_case + - name: Change image owner on pull requests from external forks + if: ${{ github.event_name == 'pull_request' }} + run: echo "IMAGE_OWNER=${{ github.event.pull_request.head.repo.owner.login }}" >> $GITHUB_ENV + + # 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: registry_owner_case uses: ASzc/change-string-case-action@v6 with: - string: ${{ env.IMAGE_REGISTRY }} + string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_OWNER }} # Build and publish Docker container image - name: Get Docker metadata id: meta uses: docker/metadata-action@v5 with: - images: ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} + images: ${{ steps.registry_owner_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} tags: | type=match,pattern=documentation/v(.*),group=1 type=edge,branch=master @@ -151,7 +161,7 @@ jobs: # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. # https://github.com/macbre/push-to-ghcr/issues/12 - name: Lowercase Registry - id: registry_case + id: registry_owner_case uses: ASzc/change-string-case-action@v6 with: string: ${{ env.IMAGE_REGISTRY }} @@ -161,7 +171,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} + images: ${{ steps.registry_owner_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} flavor: | suffix=-minimal tags: | 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-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] From 40598a899ce199e049e342a3812601d9751e0981 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 16:30:09 -0700 Subject: [PATCH 03/15] Refactor the CI workflows, don't push on PRs from external forks --- .github/workflows/documentation-build.yml | 157 +++++------------- .../workflows/documentation-deploy-edge.yml | 2 - 2 files changed, 43 insertions(+), 116 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index a290f6662..7a72d4e81 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*' @@ -23,14 +19,13 @@ on: required: false env: - IMAGE_REGISTRY: ghcr.io - IMAGE_OWNER: ${{ github.repository_owner }} - IMAGE_NAME: project-docs - # Note: the image will be published to IMAGE_REGISTRY/IMAGE_OWNER/IMAGE_NAME, - # which defaults to ghcr.io/PlanktoScope/project-docs. But in PRs from external forks by other - # people we will try to publish the image under that person instead, because we can't publish - # to ghcr.io/PlanktoScope in GitHub Actions workflow runs triggered by PRs from external forks - # (see https://github.com/PlanktoScope/device-backend/pull/30 for details). + 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: @@ -38,6 +33,12 @@ jobs: 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 @@ -48,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 @@ -60,127 +61,54 @@ 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 - - name: Change image owner on pull requests from external forks - if: ${{ github.event_name == 'pull_request' }} - run: echo "IMAGE_OWNER=${{ github.event.pull_request.head.repo.owner.login }}" >> $GITHUB_ENV - # 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: registry_owner_case + id: image_registry_case uses: ASzc/change-string-case-action@v6 with: - string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_OWNER }} + string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - # Build and publish Docker container image - - name: Get Docker metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ steps.registry_owner_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} - 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 + - name: Abbreviate git SHA + run: echo 'ABBREVIATED_SHA=${GITHUB_SHA::7}' >> $GITHUB_ENV - - 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: Set documentation variant suffix run: | - poetry -C ./documentation/ install - - - 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 - - # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. - # https://github.com/macbre/push-to-ghcr/issues/12 - - name: Lowercase Registry - id: registry_owner_case - uses: ASzc/change-string-case-action@v6 - with: - string: ${{ env.IMAGE_REGISTRY }} + 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.registry_owner_case.outputs.lowercase }}/${{ env.IMAGE_NAME }} + 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=ref,event=pr,suffix=-git-${{ env.ABBREVIATED_SHA }},priority=599 + type=raw,value=git-${{ env.ABBREVIATED_SHA }} + type=sha # this sha doesn't appear to correspond to the git sha - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -189,6 +117,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry + if: ${{ env.PUSH_IMAGE }} uses: docker/login-action@v3 with: registry: ghcr.io @@ -200,14 +129,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-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/**' From 713fa859f893b2f53a6c65daa279d6e94667a73b Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 16:42:34 -0700 Subject: [PATCH 04/15] Try to fix syntax error --- .github/workflows/documentation-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 7a72d4e81..46b19ac10 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -80,7 +80,7 @@ jobs: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - name: Abbreviate git SHA - run: echo 'ABBREVIATED_SHA=${GITHUB_SHA::7}' >> $GITHUB_ENV + run: echo 'ABBREVIATED_SHA=${${{ github.sha }}::7}' >> $GITHUB_ENV - name: Set documentation variant suffix run: | From ba56231947c4f2e476904e4940a9800521c01a20 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 16:45:08 -0700 Subject: [PATCH 05/15] Fix incorrect quotes --- .github/workflows/documentation-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 46b19ac10..c00af43fd 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -80,12 +80,12 @@ jobs: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - name: Abbreviate git SHA - run: echo 'ABBREVIATED_SHA=${${{ github.sha }}::7}' >> $GITHUB_ENV + run: echo "ABBREVIATED_SHA=${${{ github.sha }}::7}" >> $GITHUB_ENV - name: Set documentation variant suffix run: | if [[ '${{ matrix.variant }}' != 'default' ]]; then - echo 'VARIANT_SUFFIX'='-${{ matrix.variant}}' >> $GITHUB_ENV + echo 'VARIANT_SUFFIX=-${{ matrix.variant}}' >> $GITHUB_ENV fi # Build and publish Docker container image From a1c8188c3dff48bd9c191568b5a4e3076871f8c1 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 16:48:08 -0700 Subject: [PATCH 06/15] Continue trying to fix git sha abbreviation step --- .github/workflows/documentation-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index c00af43fd..27b4f0b5e 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -80,7 +80,7 @@ jobs: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - name: Abbreviate git SHA - run: echo "ABBREVIATED_SHA=${${{ github.sha }}::7}" >> $GITHUB_ENV + run: printf "ABBREVIATED_SHA=%.7s" "${{ github.sha }}" >> $GITHUB_ENV - name: Set documentation variant suffix run: | From c56224837bb5a867fb1576f41f6824e12081f735 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 16:57:04 -0700 Subject: [PATCH 07/15] Continue trying to fix... --- .github/workflows/documentation-build.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 27b4f0b5e..0ff88a1f8 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -79,8 +79,12 @@ jobs: with: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Abbreviate git SHA - run: printf "ABBREVIATED_SHA=%.7s" "${{ github.sha }}" >> $GITHUB_ENV + - name: Get SHA of commit on PR + if: ${{ github.event_name == 'pull_request' }} + # 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: | + printf "PR_SHA=%.7s" "${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV - name: Set documentation variant suffix run: | @@ -106,9 +110,8 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-git-${{ env.ABBREVIATED_SHA }},priority=599 - type=raw,value=git-${{ env.ABBREVIATED_SHA }} - type=sha # this sha doesn't appear to correspond to the git sha + type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ env.PR_SHA != "" }},priority=599 + type=sha - name: Set up QEMU uses: docker/setup-qemu-action@v3 From e2944344782e8fbee9843ef8b125728f5bb7e7fc Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 16:58:20 -0700 Subject: [PATCH 08/15] Continue trying to fix... --- .github/workflows/documentation-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 0ff88a1f8..fc07a3c13 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -80,7 +80,7 @@ jobs: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - name: Get SHA of commit on PR - if: ${{ github.event_name == 'pull_request' }} + if: github.event_name == 'pull_request' # 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: | From e0cd9f59bd68ad0f0a0a7c145645e4410afe86ed Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 17:02:14 -0700 Subject: [PATCH 09/15] Continue trying to fix... --- .github/workflows/documentation-build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index fc07a3c13..1541384a0 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -62,7 +62,7 @@ jobs: run: poetry -C ./documentation/ run poe --root ./documentation/ import-external-assets - name: Make documentation ${{ matrix.variant }} - if: ${{ matrix.variant != 'default' }} + if: matrix.variant != 'default' run: poetry -C ./documentation/ run poe --root ./documentation/ make-${{ matrix.variant }} - name: Check documentation @@ -80,7 +80,7 @@ jobs: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - name: Get SHA of commit on PR - if: github.event_name == 'pull_request' + if: github.event.pull_request # 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: | @@ -110,7 +110,7 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ env.PR_SHA != "" }},priority=599 + type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ github.event.pull_request }},priority=599 type=sha - name: Set up QEMU @@ -120,7 +120,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry - if: ${{ env.PUSH_IMAGE }} + if: env.PUSH_IMAGE uses: docker/login-action@v3 with: registry: ghcr.io From c727f119f9c1ccbf899272edd24cf031e982d861 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 17:03:43 -0700 Subject: [PATCH 10/15] Continue trying to fix... --- .github/workflows/documentation-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 1541384a0..62f161c92 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -110,7 +110,7 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ github.event.pull_request }},priority=599 + type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ env.PR_SHA != "" }},priority=599 type=sha - name: Set up QEMU From af47797b596439690dab563fc0d6f8d08323bb28 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 17:05:50 -0700 Subject: [PATCH 11/15] Continue trying to fix... --- .github/workflows/documentation-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 62f161c92..6ef41025f 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -80,7 +80,7 @@ jobs: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - name: Get SHA of commit on PR - if: github.event.pull_request + if: github.event.pull_request.head.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: | @@ -110,7 +110,7 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ env.PR_SHA != "" }},priority=599 + type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ github.event.pull_request.head.sha != '' }},priority=599 type=sha - name: Set up QEMU From 7254ea2a101b464dab600368525c2dd47295427b Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 17:08:22 -0700 Subject: [PATCH 12/15] Change sha suffix for PR image tags --- .github/workflows/documentation-build.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 6ef41025f..34aeac287 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -83,8 +83,7 @@ jobs: if: github.event.pull_request.head.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: | - printf "PR_SHA=%.7s" "${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV + run: printf "PR_SHA=%.7s" "${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV - name: Set documentation variant suffix run: | @@ -110,7 +109,7 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-git-${{ env.PR_SHA }},enable=${{ github.event.pull_request.head.sha != '' }},priority=599 + type=ref,event=pr,suffix=-sha-${{ env.PR_SHA }},enable=${{ github.event.pull_request.head.sha != '' }},priority=599 type=sha - name: Set up QEMU From d58cbf553294f8ff9f34b47c4f2a05505c341df3 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 17:13:08 -0700 Subject: [PATCH 13/15] Make the regular sha suffix consistent for PRs --- .github/workflows/documentation-build.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 34aeac287..cc581340e 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -99,6 +99,7 @@ jobs: 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) }} + HAS_PR_SHA: ${{ github.event.pull_request.head.sha != '' }} with: images: ${{ steps.image_registry_case.outputs.lowercase }} flavor: | @@ -109,8 +110,9 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-sha-${{ env.PR_SHA }},enable=${{ github.event.pull_request.head.sha != '' }},priority=599 - type=sha + type=ref,event=pr,suffix=-sha-${{ env.PR_SHA }},enable=${{ env.HAS_PR_SHA }},priority=599 + type=raw,value=sha-${{ env.PR_SHA }},enable=${{ env.HAS_PR_SHA }},priority=100 + type=sha,enable=${{ !env.HAS_PR_SHA }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 From d5a30ac1b91c8341e0528d3f9682a57c9f439ad1 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 17:34:55 -0700 Subject: [PATCH 14/15] Remove image tag with pr and sha suffix --- .github/workflows/documentation-build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index cc581340e..071b51bec 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -110,7 +110,6 @@ jobs: type=raw,value=beta,enable=${{ env.IS_BETA_BRANCH }},priority=701 type=edge,branch=${{ env.MAIN_BRANCH }} type=ref,event=pr - type=ref,event=pr,suffix=-sha-${{ env.PR_SHA }},enable=${{ env.HAS_PR_SHA }},priority=599 type=raw,value=sha-${{ env.PR_SHA }},enable=${{ env.HAS_PR_SHA }},priority=100 type=sha,enable=${{ !env.HAS_PR_SHA }} From 88de63dff52617080b6c982c2c87b89832248d15 Mon Sep 17 00:00:00 2001 From: Ethan Li Date: Thu, 16 May 2024 19:52:14 -0700 Subject: [PATCH 15/15] Fix various problems --- .github/workflows/documentation-build.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml index 071b51bec..201f05a91 100644 --- a/.github/workflows/documentation-build.yml +++ b/.github/workflows/documentation-build.yml @@ -79,11 +79,15 @@ jobs: with: string: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Get SHA of commit on PR - if: github.event.pull_request.head.sha + - 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: printf "PR_SHA=%.7s" "${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV + 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: | @@ -99,7 +103,6 @@ jobs: 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) }} - HAS_PR_SHA: ${{ github.event.pull_request.head.sha != '' }} with: images: ${{ steps.image_registry_case.outputs.lowercase }} flavor: | @@ -110,8 +113,7 @@ jobs: 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.PR_SHA }},enable=${{ env.HAS_PR_SHA }},priority=100 - type=sha,enable=${{ !env.HAS_PR_SHA }} + type=raw,value=sha-${{ env.ACTUAL_SHA }},enable=${{ env.ACTUAL_SHA != '' }},priority=100 - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -120,7 +122,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry - if: env.PUSH_IMAGE + if: env.PUSH_IMAGE == 'true' uses: docker/login-action@v3 with: registry: ghcr.io