Skip to content

Commit 1ea8ae5

Browse files
Added tags inputs (#18)
## What * Added tags * Added tests * Update README.md and docs (#19) Co-authored-by: goruha <[email protected]> Co-authored-by: Cloud Posse Bot (CI/CD) <[email protected]> Co-authored-by: goruha <[email protected]>
1 parent 6efd220 commit 1ea8ae5

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

.github/workflows/test-docker-build-complex.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
expected: 'registry.hub.docker.com/cloudposse/github-action-docker-build-push'
4141
actual: ${{ steps.current.outputs.image }}
4242

43+
- uses: nick-fields/assert-action@v1
44+
with:
45+
expected: sha-${{ github.sha }}
46+
actual: ${{ steps.current.outputs.tag }}
47+
4348
teardown:
4449
runs-on: ubuntu-latest
4550
needs: [test]

.github/workflows/test-docker-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
expected: 'registry.hub.docker.com/cloudposse/github-action-docker-build-push'
3737
actual: ${{ steps.current.outputs.image }}
3838

39+
- uses: nick-fields/assert-action@v1
40+
with:
41+
expected: sha-${{ github.sha }}
42+
actual: ${{ steps.current.outputs.tag }}
43+
44+
3945
teardown:
4046
runs-on: ubuntu-latest
4147
needs: [test]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Build Docker image and push it.
113113
| password | Docker password | | false |
114114
| registry | Docker registry | N/A | true |
115115
| repository | Repository | N/A | true |
116+
| tags | List of tags (supports https://github.com/docker/metadata-action#tags-input) | N/A | false |
116117
| workdir | Working directory | ./ | false |
117118
118119
## Outputs

action.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,48 @@ inputs:
3333
description: 'Docker password'
3434
required: false
3535
default: ''
36+
tags:
37+
description: "List of tags (supports https://github.com/docker/metadata-action#tags-input)"
38+
required: false
3639
outputs:
3740
image:
3841
description: "Docker image name"
3942
value: ${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.repository }}
4043
tag:
4144
description: "Docker image tag"
42-
value: ${{ steps.context.outputs.tag }}
45+
value: ${{ steps.tag.outputs.output }}
46+
4347
runs:
4448
using: "composite"
4549
steps:
46-
- id: context
47-
run: echo "::set-output name=tag::sha-${{ github.sha }}"
48-
shell: bash
50+
- name: Docker meta
51+
id: meta
52+
uses: docker/metadata-action@v4
53+
with:
54+
# list of Docker images to use as base name for tags
55+
images: |
56+
${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.repository }}
57+
# generate Docker tags based on the following events/attributes
58+
tags: |
59+
type=sha
60+
type=schedule
61+
type=ref,event=branch
62+
type=ref,event=pr
63+
type=semver,pattern={{version}}
64+
type=semver,pattern={{major}}.{{minor}}
65+
type=semver,pattern={{major}}
66+
type=sha,format=long
67+
${{ inputs.tags }}
68+
labels: |
69+
org.opencontainers.image.source=https://github.com/${{ inputs.organization }}/${{ inputs.repository }}
70+
71+
- uses: edwardgeorge/jq-action@main
72+
id: tag
73+
with:
74+
compact: true
75+
raw-output: true
76+
input: ${{ steps.meta.outputs.json }}
77+
script: '.tags | map(select(test("sha-\\w{8,}"))) | first | match("sha-\\w{8,}") | .string'
4978

5079
# docker context must be created prior to setting up Docker Buildx
5180
# https://github.com/actions-runner-controller/actions-runner-controller/issues/893
@@ -78,5 +107,5 @@ runs:
78107
build-args: ${{ inputs.build-args }}
79108
cache-from: type=gha
80109
cache-to: type=gha,mode=max
81-
tags: ${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.repository }}:${{ steps.context.outputs.tag }}
82-
labels: org.opencontainers.image.source=https://github.com/${{ inputs.organization }}/${{ inputs.repository }}
110+
tags: ${{ steps.meta.outputs.tags }}
111+
labels: ${{ steps.meta.outputs.labels }}

docs/github-action.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| password | Docker password | | false |
1111
| registry | Docker registry | N/A | true |
1212
| repository | Repository | N/A | true |
13+
| tags | List of tags (supports https://github.com/docker/metadata-action#tags-input) | N/A | false |
1314
| workdir | Working directory | ./ | false |
1415

1516
## Outputs

0 commit comments

Comments
 (0)