Skip to content

Commit

Permalink
feat: allow skipping publishing when pushing to default (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman authored Nov 18, 2023
1 parent 9e633ce commit e951668
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 2 additions & 0 deletions actions/push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
3 changes: 3 additions & 0 deletions actions/push/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion actions/push/src/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions actions/push/src/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export async function run(): Promise<void> {
const imageName = image.split(':')[0]

for (const registry of registries) {
if (registry === '') {
continue
}

for (const tag of tags) {
const fullImage = `${registry}/${imageName}:${tag}`

Expand Down

0 comments on commit e951668

Please sign in to comment.