Skip to content
Latchkey

Publish workflow (allegro/ralph)

The Publish workflow from allegro/ralph, explained and optimized by Latchkey.

A

CI health: A - excellent

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

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

What it does

This is the Publish workflow from the allegro/ralph 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

on:
  release:
    types: [ created ]

jobs:
  publish:

    runs-on: ubuntu-latest
    environment: ci

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Verify github ref
        run: |
          TAG=$(echo "$GITHUB_REF" | grep -E -o '^refs\/tags\/[0-9]{8}\.[0-9]+$' || true)
          if [[ -z "$TAG" ]]; then
              >&2 echo "The \$GITHUB_REF does not point to a properly named tag."
              exit 1
          fi
      - name: Build
        run: make build-package
      - name: Install packagecloud CLI
        run: sudo gem install package_cloud
      - name: Publish deb
        env:
          PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
        run: package_cloud push allegro/ralph/ubuntu/jammy build/*.deb
      - name: Publish docker
        env:
          WAIT_FOR_PACKAGECLOUD_DELAY: 10
          RETRY_COUNT: 3
        run: |
          docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_PASSWORD }}
          export RALPH_VERSION=${GITHUB_REF#refs/*/}
          until [ "$RETRY_COUNT" -le 0 ]
            do
              sleep $WAIT_FOR_PACKAGECLOUD_DELAY
              make publish-docker-image && break
              RETRY_COUNT=$((RETRY_COUNT-1))
              echo "==== Publish docker failed. Remaining retries: $RETRY_COUNT ===="
            done
          docker logout

The same workflow, on Latchkey

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

name: Publish
 
on:
  release:
    types: [ created ]
 
jobs:
  publish:
    timeout-minutes: 30
 
    runs-on: latchkey-small
    environment: ci
 
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Verify github ref
        run: |
          TAG=$(echo "$GITHUB_REF" | grep -E -o '^refs\/tags\/[0-9]{8}\.[0-9]+$' || true)
          if [[ -z "$TAG" ]]; then
              >&2 echo "The \$GITHUB_REF does not point to a properly named tag."
              exit 1
          fi
      - name: Build
        run: make build-package
      - name: Install packagecloud CLI
        run: sudo gem install package_cloud
      - name: Publish deb
        env:
          PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
        run: package_cloud push allegro/ralph/ubuntu/jammy build/*.deb
      - name: Publish docker
        env:
          WAIT_FOR_PACKAGECLOUD_DELAY: 10
          RETRY_COUNT: 3
        run: |
          docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_PASSWORD }}
          export RALPH_VERSION=${GITHUB_REF#refs/*/}
          until [ "$RETRY_COUNT" -le 0 ]
            do
              sleep $WAIT_FOR_PACKAGECLOUD_DELAY
              make publish-docker-image && break
              RETRY_COUNT=$((RETRY_COUNT-1))
              echo "==== Publish docker failed. Remaining retries: $RETRY_COUNT ===="
            done
          docker logout
 

What changed

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

Actions used in this workflow