@@ -101,25 +101,17 @@ steps:
101101 name : Checkout
102102 uses : actions/checkout@v2
103103 -
104- name : Prepare
105- id : prep
106- run : |
107- DOCKER_IMAGE=myorg/myrepository
108- VERSION=edge
109- if [[ $GITHUB_REF == refs/tags/* ]]; then
110- VERSION=${GITHUB_REF#refs/tags/}
111- elif [[ $GITHUB_REF == refs/heads/* ]]; then
112- VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
113- elif [[ $GITHUB_REF == refs/pull/* ]]; then
114- VERSION=pr-${{ github.event.number }}
115- fi
116- TAGS="${DOCKER_IMAGE}:${VERSION}"
117- if [ "${{ github.event_name }}" = "push" ]; then
118- TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
119- fi
120- echo ::set-output name=version::${VERSION}
121- echo ::set-output name=tags::${TAGS}
122- echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
104+ name : Docker meta
105+ id : meta
106+ uses : docker/metadata-action@v3
107+ with :
108+ images : |
109+ myorg/myrepository
110+ tags : |
111+ type=ref,event=branch
112+ type=ref,event=pr
113+ type=semver,pattern={{version}}
114+ type=sha
123115 -
124116 name : Set up Docker Buildx
125117 uses : docker/setup-buildx-action@v1
@@ -136,12 +128,6 @@ steps:
136128 with :
137129 context : .
138130 push : ${{ github.event_name != 'pull_request' }}
139- tags : ${{ steps.prep.outputs.tags }}
140- labels : |
141- org.opencontainers.image.source=${{ github.event.repository.html_url }}
142- org.opencontainers.image.created=${{ steps.prep.outputs.created }}
143- org.opencontainers.image.revision=${{ github.sha }}
131+ tags : ${{ steps.meta.outputs.tags }}
132+ labels : ${{ steps.meta.outputs.labels }}
144133` ` `
145-
146- > You can also use the [Docker meta action to handle tags and labels](docs/advanced/tags-labels.md) based on GitHub
147- > actions events and Git metadata.
0 commit comments