From 21c031b8df0bf6e01b6451550f013ab3fbcd2d37 Mon Sep 17 00:00:00 2001 From: seallard Date: Mon, 23 Oct 2023 13:36:41 +0200 Subject: [PATCH] Trigger workflow on release --- .github/workflows/build_cli_image_on_push.yml | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_cli_image_on_push.yml b/.github/workflows/build_cli_image_on_push.yml index 443cade8ca..52ee1e5a11 100644 --- a/.github/workflows/build_cli_image_on_push.yml +++ b/.github/workflows/build_cli_image_on_push.yml @@ -1,6 +1,10 @@ -name: Build and publish cli image on push +name: Build and publish cli image on push or new release event -on: [push] +on: + push: + release: + types: + - created jobs: docker-image-push: @@ -12,7 +16,10 @@ jobs: - name: Extract branch name and remove illegal chars id: get_branch_name shell: bash - run: echo "branch=$(tr "/" "-" <<<${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV + run: | + if [[ "${{ github.event_name }}" == "push" ]]; then + echo "branch=$(tr "/" "-" <<<${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV + fi - name: Login to Docker Hub uses: docker/login-action@v2 @@ -20,6 +27,26 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Get the release version + id: get_version + shell: bash + run: | + if [[ "${{ github.event_name }}" == "release" ]]; then + VERSION=${{ github.event.release.tag_name }} + echo "::set-output name=version::$VERSION" + fi + + - name: Set tag names + id: set_tag + shell: bash + run: | + if [[ "${{ github.event_name }}" == "release" ]]; then + echo "::set-output name=tags::clinicalgenomics/cg-cli:${{ steps.get_version.outputs.version }},clinicalgenomics/cg-cli:latest" + else + BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr "/" "-") + echo "::set-output name=tags::clinicalgenomics/cg-cli:$BRANCH_NAME" + fi + - name: Build and push id: docker_cli_build uses: docker/build-push-action@v3 @@ -27,4 +54,4 @@ jobs: context: ./ file: ./Dockerfile.cli push: true - tags: "clinicalgenomics/cg-cli:${{ env.branch }}" + tags: ${{ steps.set_tag.outputs.tags }} \ No newline at end of file