Skip to content

Commit

Permalink
check is_pr within each workflow instead of passing in a redundant va…
Browse files Browse the repository at this point in the history
…riable
  • Loading branch information
James-Mart committed Feb 15, 2024
1 parent f75341d commit dff2891
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 46 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/_dispatcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,13 @@ 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"
needs: determine-actions
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:
Expand All @@ -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:
Expand All @@ -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'}}
13 changes: 4 additions & 9 deletions .github/workflows/builder-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,15 +44,15 @@ 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
username: ${{ github.repository_owner }}
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: .
Expand All @@ -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: .
Expand All @@ -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
Expand Down
41 changes: 23 additions & 18 deletions .github/workflows/contributor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -69,49 +64,59 @@ 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)
LOCAL_TAG=localhost:5000/local_base_image:latest
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)
LOCAL_TAG=localhost:5000/local_tools_image:latest
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: .
Expand All @@ -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: .
Expand All @@ -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
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/tool-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -51,15 +45,15 @@ 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
username: ${{ github.repository_owner }}
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: .
Expand All @@ -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: .
Expand All @@ -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: .
Expand All @@ -96,15 +90,15 @@ 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
path: ${{ matrix.protocol }}-tool-config-image.tar
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
Expand Down

0 comments on commit dff2891

Please sign in to comment.