diff --git a/.github/workflows/update_container_image.yaml b/.github/workflows/update_container_image.yaml index df3021b56..3b851e09e 100644 --- a/.github/workflows/update_container_image.yaml +++ b/.github/workflows/update_container_image.yaml @@ -2,20 +2,13 @@ name: Build and Push Container Image on: workflow_dispatch: - inputs: - dry_run: - description: "Skip pushing container image" - required: true - default: "true" - type: choice - options: ["true", "false"] - - repository_dispatch: - types: [publish-conda-succeeded] + workflow_run: + workflows: ["publish_conda"] + types: [completed] env: REGISTRY: ghcr.io - IMAGE_NAME: "noaa-gfdl/ubuntu-20-fre-cli-2025" + IMAGE_NAME: "noaa-gfdl/fre-cli" jobs: build-and-push: @@ -30,32 +23,35 @@ jobs: with: fetch-depth: 0 - - name: Determine image tag + - name: Fetch all tags + run: git fetch --tags + + - name: Determine latest tag id: set_tag run: | - # Use the pushed tag if this is a tag ref; otherwise fall back. - if [[ "$GITHUB_REF" == refs/tags/* ]]; then - TAG="${GITHUB_REF#refs/tags/}" - elif [[ "${GITHUB_REF_NAME}" == "main" ]]; then - TAG="latest" - else - TAG="${GITHUB_SHA::7}" - fi - echo "docker_tag=$TAG" >> "$GITHUB_OUTPUT" + echo "docker_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT" + + - name: Show image tag + run: echo "Docker tag is ${{ steps.set_tag.outputs.docker_tag }}" + + - name: Update fre-cli version in cylc-flow-tools.yaml + run: | + sed -i 's/^[[:space:]]*-[[:space:]]*noaa-gfdl::fre-cli==.*/ - noaa-gfdl::fre-cli==${{ steps.set_tag.outputs.docker_tag }}/' ./container-files/cylc-flow-tools.yaml - name: Log in to the Container registry + if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' }} uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push Docker image - if: ${{ inputs.dry_run != 'true' }} + - name: Build Docker image + if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') }} uses: docker/build-push-action@v5 with: context: . file: ./container-files/Dockerfile-fre-cli - push: true + push: ${{ github.event_name == 'workflow_run' }} tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set_tag.outputs.docker_tag }}