From 7c9f872d5b9c9636d2a4343946795f4f54c382d7 Mon Sep 17 00:00:00 2001 From: lidor ettinger Date: Fri, 3 Jul 2020 00:35:26 +0300 Subject: [PATCH] Push to Docker Hub only in presence of Release Tag Signed-off-by: Lidor Ettinger --- .github/workflows/ci.yml | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a62da7e..62c5e92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,33 +108,32 @@ jobs: # needs: [build, build_release] steps: - name: Check out code - if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() + if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() uses: actions/checkout@master with: fetch-depth: 1 - name: Docker login - if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() + if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() uses: azure/container-actions/docker-login@master with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Docker build & push - if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() + - name: Docker build & tag + if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() run: | - DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }} . - docker tag ${{ secrets.IMAGE_NAME }}:latest ${{ secrets.IMAGE_NAME }}:$GITHUB_SHA - docker push ${{ secrets.IMAGE_NAME }}:$GITHUB_SHA - docker push ${{ secrets.IMAGE_NAME }}:latest - - name: Docker tag release & push + DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:stable-latest . + docker tag ${{ secrets.IMAGE_NAME }}:stable-latest ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//} + docker tag ${{ secrets.IMAGE_NAME }}:stable-latest ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7} + - name: Docker push if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() run: | - docker tag ${{ secrets.IMAGE_NAME }}:latest ${{ secrets.IMAGE_NAME }}:${GITHUB_REF:10} # stripping refs/tags/ - docker push ${{ secrets.IMAGE_NAME }}:${GITHUB_REF:10} + docker push ${{ secrets.IMAGE_NAME }}:stable-latest + docker push ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//} + docker push ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7} - name: Docker Hub Description - if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() + if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() uses: peter-evans/dockerhub-description@v2.0.0 env: DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKERHUB_REPOSITORY: ${{ secrets.IMAGE_NAME }} - + DOCKERHUB_REPOSITORY: ${{ secrets.IMAGE_NAME }} \ No newline at end of file