From 081b2d257ba853c1d31d35ebfeae1cb92a641746 Mon Sep 17 00:00:00 2001 From: orhun Date: Sat, 25 Sep 2021 23:06:40 +0300 Subject: [PATCH] chore(docker): use docker meta for tagging for GHCR --- .github/workflows/docker.yml | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4fb165316d..662c4832fb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,15 +4,31 @@ on: push: branches: - main + pull_request: + branches: + - main jobs: - docker-hub: - name: Docker Hub + docker: + name: Docker Build and Push runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v2 + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ${{ secrets.DOCKER_HUB_USERNAME }}/git-cliff:latest + ghcr.io/${{ github.repository_owner }}/git-cliff:latest + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=sha + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 @@ -26,11 +42,20 @@ jobs: ${{ runner.os }}-buildx- - name: Login to Docker Hub + if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push id: docker_build uses: docker/build-push-action@v2 @@ -38,8 +63,9 @@ jobs: context: ./ file: ./Dockerfile builder: ${{ steps.buildx.outputs.name }} - push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/git-cliff:latest + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache