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 }} diff --git a/container-files/README.md b/container-files/README.md index 666d00e14..abe3b8c52 100644 --- a/container-files/README.md +++ b/container-files/README.md @@ -29,6 +29,9 @@ git clone https://github.com/NOAA-GFDL/fre-cli.git ## Navigate into fre-cli/container-files cd fre-cli/container-files +## Add the desired frecli version number in cylc-flow-tools.yaml +ex: noaa-gfdl::fre-cli==2026.01 + ## Build a container image podman build -f Dockerfile-fre-cli -t latest diff --git a/container-files/cylc-flow-tools.yaml b/container-files/cylc-flow-tools.yaml index a394c4e83..8eef30023 100644 --- a/container-files/cylc-flow-tools.yaml +++ b/container-files/cylc-flow-tools.yaml @@ -4,7 +4,7 @@ channels: - NOAA-GFDL dependencies: - noaa-gfdl::hsm - - noaa-gfdl::fre-cli==2025.04 + - noaa-gfdl::fre-cli==XXXX.XX #Add version number manually - conda-forge::nco - conda-forge::rsync - conda-forge::make