From e95166809089d4f69a91787b812e2ddbf45fad66 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Fri, 17 Nov 2023 17:52:46 -0800 Subject: [PATCH] feat: allow skipping publishing when pushing to default (#97) --- .github/workflows/ci.yml | 10 +++++++++- .github/workflows/publish.yml | 11 +++++++++-- actions/push/README.md | 2 ++ actions/push/dist/index.js | 3 +++ actions/push/src/push.test.ts | 2 +- actions/push/src/push.ts | 4 ++++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 610d01017..79d38a38b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: aws_ecr_registry: description: | The AWS ECR registry that will be used to publish images - required: true + required: false type: string aws_role_arn: description: | @@ -45,6 +45,13 @@ on: required: false type: boolean default: false + skip_publish_on_default: + description: | + If set to true, images will not be published when the workflow is + triggered by a push to the default branch. + required: false + type: boolean + default: false tags: description: | A line separated list of additional tags that will be applied to @@ -154,6 +161,7 @@ jobs: aws_region: ${{ inputs.aws_region }} ci_cli_version: ${{ inputs.ci_cli_version }} earthly_version: ${{ inputs.earthly_version }} + skip_publish_on_default: ${{ inputs.skip_publish_on_default }} tags: ${{ inputs.tags }} secrets: dockerhub_token: ${{ secrets.dockerhub_token }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a1bcfdbb9..d893ac894 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ on: aws_ecr_registry: description: | The AWS ECR registry that will be used to publish images - required: true + required: false type: string aws_role_arn: description: | @@ -40,6 +40,13 @@ on: required: false type: string default: latest + skip_publish_on_default: + description: | + If set to true, images will not be published when the workflow is + triggered by a push to the default branch. + required: false + type: boolean + default: false tags: description: | A line separated list of additional tags that will be applied to @@ -127,7 +134,7 @@ jobs: runner_address: ${{ secrets.earthly_runner_address }} - name: Push image uses: input-output-hk/catalyst-ci/actions/push@master - if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) + if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !inputs.skip_publish_on_default with: image: ${{ steps.build.outputs.image }} registries: | diff --git a/actions/push/README.md b/actions/push/README.md index 30ab71424..3c77b0e2b 100644 --- a/actions/push/README.md +++ b/actions/push/README.md @@ -4,6 +4,8 @@ This Github Action will attach a variable number of tags to a given image and then push all variants to a list of image registries. This is often useful when a single image needs to be tagged multiple times and pushed to multiple registries. +Note that for the `registries` input, empty lines will be ignored. +As a result, you can pass template variables that may or may not be empty (useful for handling optional registries). To see a full demonstration of this action, see the [publish workflow](../../.github/workflows/publish.yml). diff --git a/actions/push/dist/index.js b/actions/push/dist/index.js index 92ca6664b..53eede49d 100644 --- a/actions/push/dist/index.js +++ b/actions/push/dist/index.js @@ -4135,6 +4135,9 @@ async function run() { const tags = core.getInput('tags').split('\n'); const imageName = image.split(':')[0]; for (const registry of registries) { + if (registry === '') { + continue; + } for (const tag of tags) { const fullImage = `${registry}/${imageName}:${tag}`; core.info(`Tagging ${image} as ${fullImage}`); diff --git a/actions/push/src/push.test.ts b/actions/push/src/push.test.ts index 94105775d..308f0d61a 100644 --- a/actions/push/src/push.test.ts +++ b/actions/push/src/push.test.ts @@ -24,7 +24,7 @@ describe('Discover Action', () => { case 'image': return 'image:latest' case 'registries': - return 'registry1\nregistry2' + return '\nregistry1\nregistry2' case 'tags': return 'tag1\ntag2' default: diff --git a/actions/push/src/push.ts b/actions/push/src/push.ts index 6575b76a3..6a92fd097 100644 --- a/actions/push/src/push.ts +++ b/actions/push/src/push.ts @@ -10,6 +10,10 @@ export async function run(): Promise { const imageName = image.split(':')[0] for (const registry of registries) { + if (registry === '') { + continue + } + for (const tag of tags) { const fullImage = `${registry}/${imageName}:${tag}`