From dff28912bc248d6d648b5342fa889ca8c3db6cfc Mon Sep 17 00:00:00 2001 From: James-Mart Date: Thu, 15 Feb 2024 16:36:12 -0500 Subject: [PATCH] check is_pr within each workflow instead of passing in a redundant variable --- .github/workflows/_dispatcher.yml | 9 ++---- .github/workflows/builder-ubuntu.yml | 13 +++------ .github/workflows/contributor.yml | 41 ++++++++++++++++------------ .github/workflows/tool-config.yml | 18 ++++-------- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/.github/workflows/_dispatcher.yml b/.github/workflows/_dispatcher.yml index 79d537c..3a9287d 100644 --- a/.github/workflows/_dispatcher.yml +++ b/.github/workflows/_dispatcher.yml @@ -71,8 +71,6 @@ jobs: needs: determine-actions if: ${{ needs.determine-actions.outputs.run_tc == '1' }} uses: ./.github/workflows/tool-config.yml - with: - is_pr: ${{ github.event_name == 'pull_request' }} build-2004: name: "Build 20.04 builder" @@ -80,7 +78,6 @@ jobs: if: ${{ needs.determine-actions.outputs.run_2004 == '1' }} uses: ./.github/workflows/builder-ubuntu.yml with: - is_pr: ${{ github.event_name == 'pull_request' }} ubuntu_version: "2004" build-2204: @@ -89,7 +86,6 @@ jobs: if: ${{ needs.determine-actions.outputs.run_2204 == '1' }} uses: ./.github/workflows/builder-ubuntu.yml with: - is_pr: ${{ github.event_name == 'pull_request' }} ubuntu_version: "2204" build-contributor: @@ -98,6 +94,5 @@ jobs: if: ${{ needs.determine-actions.outputs.run_contrib == '1' }} uses: ./.github/workflows/contributor.yml with: - is_pr: ${{ github.event_name == 'pull_request' }} - is_local_tools: ${{ needs.build-tool-config.result == 'success' && github.event_name == 'pull_request'}} - is_local_base: ${{ needs.build-2204.result == 'success' && github.event_name == 'pull_request'}} + new_tools: ${{ needs.build-tool-config.result == 'success'}} + new_base: ${{ needs.build-2204.result == 'success'}} diff --git a/.github/workflows/builder-ubuntu.yml b/.github/workflows/builder-ubuntu.yml index 39dbd9f..6fb934b 100644 --- a/.github/workflows/builder-ubuntu.yml +++ b/.github/workflows/builder-ubuntu.yml @@ -7,11 +7,6 @@ env: on: workflow_call: inputs: - is_pr: - description: "Is 'true' if running in the context of a PR" - type: boolean - required: true - default: true ubuntu_version: description: "On what version of ubuntu should the build run?" type: string @@ -49,7 +44,7 @@ jobs: buildkitd-flags: --debug - name: Login in to registry - if: ${{ !inputs.is_pr }} + if: ${{ github.event_name != 'pull_request' }} uses: docker/login-action@v3 with: registry: ghcr.io @@ -57,7 +52,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build & Publish Image - if: ${{ !inputs.is_pr }} + if: ${{ github.event_name != 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -68,7 +63,7 @@ jobs: outputs: type=image,annotation-index.org.opencontainers.image.description=Psibase build environment based on Ubuntu ${{ inputs.ubuntu_version }} - name: (PR Only) - Build image archive - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -78,7 +73,7 @@ jobs: outputs: type=docker,dest=builder-${{ inputs.ubuntu_version }}-image.tar - name: (PR only) - Upload image archive as artifact - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: actions/upload-artifact@v4 with: name: builder-${{ inputs.ubuntu_version }}-image diff --git a/.github/workflows/contributor.yml b/.github/workflows/contributor.yml index 04810a5..0b2cfac 100644 --- a/.github/workflows/contributor.yml +++ b/.github/workflows/contributor.yml @@ -6,18 +6,13 @@ env: on: workflow_call: inputs: - is_pr: - description: "Is 'true' if running in the context of a PR" - type: boolean - required: true - default: true - is_local_tools: - description: "Is 'true' if the tools image dependency should be satisfied by a local image" + new_tools: + description: "Whether a newly generated tools image should be used for this workflow" type: boolean required: true default: false - is_local_base: - description: "Is 'true' if the base image dependency should be satisfied by a local image" + new_base: + description: "Whether a newly generated base image should be used for this workflow" type: boolean required: true default: false @@ -49,13 +44,13 @@ jobs: echo "tags=${TAGS,,}" >> $GITHUB_OUTPUT - name: Config docker buildx - if: ${{ !inputs.is_pr }} + if: ${{ github.event_name != 'pull_request' }} uses: docker/setup-buildx-action@v3 with: buildkitd-flags: --debug - name: (PR only) - Config docker buildx host network - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: docker/setup-buildx-action@v3 with: buildkitd-flags: --debug @@ -69,14 +64,17 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Download local base image - if: ${{ inputs.is_local_base }} + if: ${{ inputs.new_base && github.event_name == 'pull_request' }} uses: actions/download-artifact@v4 with: name: builder-2204-image - name: Set BASE_IMAGE id: base_img + env: + NEW_BASE: ${{ inputs.new_base }} + IS_PR: ${{ github.event_name == 'pull_request' }} run: | - if [[ "${{ inputs.is_local_base }}" == "true" ]]; then + if [[ "$NEW_BASE" == "true" && "$IS_PR" == "true" ]]; then docker load -i builder-2204-image.tar rm builder-2204-image.tar IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1) @@ -84,20 +82,25 @@ jobs: docker tag ${IMAGE} ${LOCAL_TAG} docker push ${LOCAL_TAG} echo "BASE_IMAGE=${LOCAL_TAG}" >> $GITHUB_OUTPUT + elif [[ "$NEW_BASE" == "true" ]]; then + echo "BASE_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${{ github.sha }}" >> $GITHUB_OUTPUT else latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/psibase-builder-ubuntu-2204") echo "BASE_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${latest_tag}" >> $GITHUB_OUTPUT fi - name: Download local tools image - if: ${{ inputs.is_local_tools }} + if: ${{ inputs.new_tools && github.event_name == 'pull_request' }} uses: actions/download-artifact@v4 with: name: https-tool-config-image - name: Set TOOL_CONFIG_IMAGE id: tool_cfg_img + env: + NEW_TOOLS: ${{ inputs.new_tools }} + IS_PR: ${{ github.event_name == 'pull_request' }} run: | - if [[ "${{ inputs.is_local_tools }}" == "true" ]]; then + if [[ "$NEW_TOOLS" == "true" && "$IS_PR" == "true" ]]; then docker load -i https-tool-config-image.tar rm https-tool-config-image.tar IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1) @@ -105,13 +108,15 @@ jobs: docker tag ${IMAGE} ${LOCAL_TAG} docker push ${LOCAL_TAG} echo "TOOL_CONFIG_IMAGE=${LOCAL_TAG}" >> $GITHUB_OUTPUT + elif [[ "$NEW_TOOLS" == "true" ]]; then + echo "TOOL_CONFIG_IMAGE=ghcr.io/gofractally/https-tool-config:${{ github.sha }}" >> $GITHUB_OUTPUT else latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/https-tool-config") echo "TOOL_CONFIG_IMAGE=ghcr.io/gofractally/https-tool-config:${latest_tag}" >> $GITHUB_OUTPUT fi - name: Build & publish ${{ steps.prep.outputs.tags }} - if: ${{ !inputs.is_pr }} + if: ${{ github.event_name != 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -125,7 +130,7 @@ jobs: outputs: type=image,annotation-index.org.opencontainers.image.description=Psibase development environment - name: (PR Only) - Build image archive - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -138,7 +143,7 @@ jobs: outputs: type=docker,dest=psibase_contributor.tar - name: (PR only) - Upload image archive as artifact - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: actions/upload-artifact@v4 with: name: psibase_contributor diff --git a/.github/workflows/tool-config.yml b/.github/workflows/tool-config.yml index 518c800..5dd49d8 100644 --- a/.github/workflows/tool-config.yml +++ b/.github/workflows/tool-config.yml @@ -5,12 +5,6 @@ env: on: workflow_call: - inputs: - is_pr: - description: "Is 'true' if running in the context of a PR" - type: boolean - required: true - default: true jobs: tool-config: @@ -51,7 +45,7 @@ jobs: buildkitd-flags: --debug - name: Login in to registry - if: ${{ !inputs.is_pr }} + if: ${{ github.event_name != 'pull_request' }} uses: docker/login-action@v3 with: registry: ghcr.io @@ -59,7 +53,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build & Publish Image - if: ${{ !inputs.is_pr }} + if: ${{ github.event_name != 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -72,7 +66,7 @@ jobs: outputs: type=image,annotation-index.org.opencontainers.image.description=Config files for admin-sys dashboard tools connecting to psinode over ${{ matrix.protocol }} on 8080 - name: (PR Only) - Build image archive - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -84,7 +78,7 @@ jobs: outputs: type=docker,dest=${{ matrix.protocol }}-tool-config-image.tar - name: (PR Only) - Build separate arm image archive - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: docker/build-push-action@v4 with: context: . @@ -96,7 +90,7 @@ jobs: outputs: type=docker,dest=${{ matrix.protocol }}-tool-config-arm-image.tar - name: (PR only) - Upload image archive as artifact - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: actions/upload-artifact@v4 with: name: ${{ matrix.protocol }}-tool-config-image @@ -104,7 +98,7 @@ jobs: retention-days: 1 - name: (PR only) - Upload arm image archive as artifact - if: ${{ inputs.is_pr }} + if: ${{ github.event_name == 'pull_request' }} uses: actions/upload-artifact@v4 with: name: ${{ matrix.protocol }}-tool-config-arm-image