Use docker/metadata-action@v3 (#616)

This commit is contained in:
Hidetake Iwata
2021-08-28 22:10:41 +09:00
committed by GitHub
parent 50bc986085
commit 077d9ab90c
2 changed files with 7 additions and 32 deletions

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env bash
set -o pipefail
set -eux
# only build on pull request
if [[ $GITHUB_EVENT_NAME == pull_request ]]; then
# e.g. refs/pulls/1/merge -> refs-pulls-1-merge
echo "::set-output name=tag::${GITHUB_REF//\//-}"
echo "::set-output name=push::false"
exit 0
fi
# push latest tag on master branch
if [[ $GITHUB_REF == refs/heads/master ]]; then
echo "::set-output name=tag::latest"
echo "::set-output name=push::true"
exit 0
fi
# push the corresponding tag on tag push
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "::set-output name=tag::${GITHUB_REF##*/}"
echo "::set-output name=push::true"
exit 0
fi
: unknown trigger
exit 1

View File

@@ -27,8 +27,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: .github/docker-build-config.sh
id: docker-build-config
- uses: docker/metadata-action@v3
id: metadata
with:
images: ghcr.io/${{ github.repository }}
- uses: docker/login-action@v1
with:
registry: ghcr.io
@@ -38,8 +40,9 @@ jobs:
- uses: docker/setup-buildx-action@v1
- uses: docker/build-push-action@v2
with:
push: ${{ steps.docker-build-config.outputs.push }}
tags: ghcr.io/${{ github.repository }}:${{ steps.docker-build-config.outputs.tag }}
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildkit-cache
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildkit-cache,mode=max
platforms: linux/amd64,linux/arm64