From 7a34f86ab98707a2f9ed4ab217b9f436eaab94a6 Mon Sep 17 00:00:00 2001 From: Andrew Savage Date: Fri, 15 Dec 2023 09:10:41 -0800 Subject: [PATCH] Set docker tag in consistent manner (#2096) b/316402019 --- .github/actions/docker/action.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 3b53e8cc9f37..3f2fbda75cda 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -43,12 +43,22 @@ runs: # We need to set docker tag properly for pull requests. In those scenarios where no docker related files # were changed we need to use an existing image (e.g. main). In cases where docker image is rebuilt we have # to use tag generated by the image build. + - name: Retrieve Docker metadata for PR + id: pr-meta + uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 + with: + images: ${{env.REGISTRY}}/${{github.repository}}/${{inputs.docker_image}} + tags: type=raw,value=${{ github.base_ref }} - name: Set Docker Tag id: set-docker-tag-presubmit-non-fork env: REPO: ${{ github.repository }} if: ${{ (steps.changed-files.outputs.any_changed == 'false') && (github.event_name == 'pull_request') }} - run: echo "DOCKER_TAG=ghcr.io/${REPO}/${{inputs.docker_image}}:${GITHUB_BASE_REF%.1+}" >> $GITHUB_ENV + run: | + set -x + docker_tag="${{ steps.pr-meta.outputs.tags }}" + docker_tag="${docker_tag%.1[+,-]}" + echo "DOCKER_TAG=${docker_tag}" >> $GITHUB_ENV shell: bash - name: Set up Cloud SDK if: ${{ (steps.changed-files.outputs.any_changed == 'true') && (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.fork) }}