Skip to content
Latchkey

Publish to GHCR workflow (jhj0517/Whisper-WebUI)

The Publish to GHCR workflow from jhj0517/Whisper-WebUI, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: jhj0517/Whisper-WebUI.github/workflows/publish-ghcr.ymlLicense Apache-2.0View source

What it does

This is the Publish to GHCR workflow from the jhj0517/Whisper-WebUI repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Publish to GHCR

on:
  # Triggers minor version ( vX.Y.Z-ShortHash )
  push:
    branches:
      - master
  # Triggers major version ( vX.Y.Z )
  release:
    types: [created]

  workflow_dispatch:

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    permissions:
      packages: write

    strategy:
      matrix:
        name: [whisper-webui, whisper-webui-backend]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Extract metadata
        id: meta
        run: |
          SHORT_SHA=$(git rev-parse --short HEAD)
          echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV

          # Triggered by a release event - versioning as major ( vX.Y.Z )
          if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
            TAG_NAME="${{ github.event.release.tag_name }}"
            echo "GIT_TAG=$TAG_NAME" >> $GITHUB_ENV
            echo "IS_RELEASE=true" >> $GITHUB_ENV

          # Triggered by a general push event - versioning as minor ( vX.Y.Z-ShortHash )
          else
            git fetch --tags
            LATEST_TAG=$(git tag --list 'v*.*.*' | sort -V | tail -n1)
            FALLBACK_TAG="${LATEST_TAG:-v0.0.0}"
            echo "GIT_TAG=${FALLBACK_TAG}-${SHORT_SHA}" >> $GITHUB_ENV
            echo "IS_RELEASE=false" >> $GITHUB_ENV
          fi
          
          echo "REPO_OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV

      - name: Set Dockerfile path
        id: dockerfile
        run: |
          if [ "${{ matrix.name }}" = "whisper-webui" ]; then
            echo "DOCKERFILE=./Dockerfile" >> $GITHUB_ENV
          elif [ "${{ matrix.name }}" = "whisper-webui-backend" ]; then
            echo "DOCKERFILE=./backend/Dockerfile" >> $GITHUB_ENV
          else
            echo "Unknown component: ${{ matrix.name }}"
            exit 1
          fi

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image (version tag)
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ${{ env.DOCKERFILE }}
          push: true
          tags: |
            ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }}

      - name: Tag and push as latest (if release)
        if: env.IS_RELEASE == 'true'
        run: |
          docker pull ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }}
          docker tag ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }} \
                     ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:latest
          docker push ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:latest

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Publish to GHCR
 
on:
  # Triggers minor version ( vX.Y.Z-ShortHash )
  push:
    branches:
      - master
  # Triggers major version ( vX.Y.Z )
  release:
    types: [created]
 
  workflow_dispatch:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build-and-push:
    timeout-minutes: 30
    runs-on: latchkey-small
    permissions:
      packages: write
 
    strategy:
      matrix:
        name: [whisper-webui, whisper-webui-backend]
 
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
 
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
 
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
 
      - name: Extract metadata
        id: meta
        run: |
          SHORT_SHA=$(git rev-parse --short HEAD)
          echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
 
          # Triggered by a release event - versioning as major ( vX.Y.Z )
          if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
            TAG_NAME="${{ github.event.release.tag_name }}"
            echo "GIT_TAG=$TAG_NAME" >> $GITHUB_ENV
            echo "IS_RELEASE=true" >> $GITHUB_ENV
 
          # Triggered by a general push event - versioning as minor ( vX.Y.Z-ShortHash )
          else
            git fetch --tags
            LATEST_TAG=$(git tag --list 'v*.*.*' | sort -V | tail -n1)
            FALLBACK_TAG="${LATEST_TAG:-v0.0.0}"
            echo "GIT_TAG=${FALLBACK_TAG}-${SHORT_SHA}" >> $GITHUB_ENV
            echo "IS_RELEASE=false" >> $GITHUB_ENV
          fi
          
          echo "REPO_OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
 
      - name: Set Dockerfile path
        id: dockerfile
        run: |
          if [ "${{ matrix.name }}" = "whisper-webui" ]; then
            echo "DOCKERFILE=./Dockerfile" >> $GITHUB_ENV
          elif [ "${{ matrix.name }}" = "whisper-webui-backend" ]; then
            echo "DOCKERFILE=./backend/Dockerfile" >> $GITHUB_ENV
          else
            echo "Unknown component: ${{ matrix.name }}"
            exit 1
          fi
 
      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
 
      - name: Build and push Docker image (version tag)
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ${{ env.DOCKERFILE }}
          push: true
          tags: |
            ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }}
 
      - name: Tag and push as latest (if release)
        if: env.IS_RELEASE == 'true'
        run: |
          docker pull ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }}
          docker tag ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }} \
                     ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:latest
          docker push ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:latest
 

What changed

4 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job (2 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow