From 1f38125e85d3de3039a1bc1a8316ba688e02ddb9 Mon Sep 17 00:00:00 2001 From: nitezs Date: Fri, 15 Sep 2023 09:59:21 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BF=AE=E6=94=B9=20docker.yml=20?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E6=9E=84=E5=BB=BA=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker.yml | 62 +++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 278d03b..5dcd8de 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,6 +4,8 @@ on: push: branches: - dev + tags: + - '*' workflow_dispatch: jobs: @@ -11,21 +13,51 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check out code - uses: actions/checkout@v3 + - name: Check out code + uses: actions/checkout@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - push: true - tags: ghcr.io/${{ github.repository }}:dev + - name: Set tag name + id: set_tag + run: | + if [[ $GITHUB_REF == refs/heads/* ]]; then + echo "::set-output name=tag::$(echo $GITHUB_REF | cut -d'/' -f3)" + else + echo "::set-output name=tag::${{ github.ref_name }}" + fi + + - name: Check if triggered by tag + id: check_tag + run: | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + echo "::set-output name=triggered_by_tag::true" + else + echo "::set-output name=triggered_by_tag::false" + fi + + - name: Build and push Docker image for dev branch + if: steps.check_tag.outputs.triggered_by_tag == 'false' + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository }}:${{ steps.set_tag.outputs.tag }} + + - name: Build and push Docker image for tags + if: steps.check_tag.outputs.triggered_by_tag == 'true' + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ steps.set_tag.outputs.tag }} + ghcr.io/${{ github.repository }}:latest