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) }}