Skip to content
Latchkey

on push workflow (module-federation/module-federation-examples)

The on push workflow from module-federation/module-federation-examples, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get 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: module-federation/module-federation-examples.github/workflows/on-push.ymlLicense MITView source

What it does

This is the on push workflow from the module-federation/module-federation-examples repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

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

The workflow

workflow (.yml)
name: on push
on:
  push:
    branches:
      - master

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  # Stop previous runs
  stop-previous-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.12.1
        with:
          access_token: ${{ secrets.GITHUB_TOKEN }}

  # Create cache for all samples
  cache:
    runs-on: ubuntu-22.04
    needs: stop-previous-run
    outputs:
      yarnHash: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Get Playwright version
        id: playwright-version
        shell: bash
        run: |
          version="$(node -p "String(require('./package.json').devDependencies['@playwright/test']||'').replace(/^[^0-9]*/, '')")"
          echo "version=$version" >> "$GITHUB_OUTPUT"

        # Hash pnpm-lock.yaml files to use it as a cache key, if pnpm-lock.yaml files are changed, the cache will be invalidated
      - name: Check pnpm hash
        id: yarn-hash
        run: |
          yarnHash="$(npx hash-files -f '["**/pnpm-lock.yaml"]' -a sha256)"
          echo "yarnHash=$yarnHash" >> $GITHUB_OUTPUT

      - name: Enable corepack
        run: corepack enable

      - name: Setup Node.js with caching
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'
          cache-dependency-path: '**/pnpm-lock.yaml'

      - name: Re-enable corepack after setup-node
        run: corepack enable

      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

      - name: Setup pnpm cache
        uses: actions/cache@v4
        id: pnpm-store-cache
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: pnpm-store-${{ runner.os }}-${{ steps.yarn-hash.outputs.yarnHash }}
          restore-keys: |
            pnpm-store-${{ runner.os }}-

      - name: Cache Playwright browsers
        uses: actions/cache@v4
        id: playwright-cache
        with:
          path: ~/.cache/ms-playwright
          key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}-headless-shell

      - name: Set Playwright cache status
        run: echo "PLAYWRIGHT_CACHE_HIT=${{ steps.playwright-cache.outputs.cache-hit }}" >> $GITHUB_ENV

      - name: Install deps
        env:
          NODE_OPTIONS: '--max_old_space_size=6144'
          FORCE_COLOR: 3
        run: |
          echo "Installing dependencies from pnpm store..."
          PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile --prefer-offline

      - name: Install Playwright browsers
        run: |
          # Populate the shared browser cache (no system deps here).
          pnpm exec playwright install chromium chromium-headless-shell

The same workflow, on Latchkey

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

name: on push
on:
  push:
    branches:
      - master
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  # Stop previous runs
  stop-previous-run:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - name: Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.12.1
        with:
          access_token: ${{ secrets.GITHUB_TOKEN }}
 
  # Create cache for all samples
  cache:
    timeout-minutes: 30
    runs-on: latchkey-small
    needs: stop-previous-run
    outputs:
      yarnHash: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
 
      - name: Get Playwright version
        id: playwright-version
        shell: bash
        run: |
          version="$(node -p "String(require('./package.json').devDependencies['@playwright/test']||'').replace(/^[^0-9]*/, '')")"
          echo "version=$version" >> "$GITHUB_OUTPUT"
 
        # Hash pnpm-lock.yaml files to use it as a cache key, if pnpm-lock.yaml files are changed, the cache will be invalidated
      - name: Check pnpm hash
        id: yarn-hash
        run: |
          yarnHash="$(npx hash-files -f '["**/pnpm-lock.yaml"]' -a sha256)"
          echo "yarnHash=$yarnHash" >> $GITHUB_OUTPUT
 
      - name: Enable corepack
        run: corepack enable
 
      - name: Setup Node.js with caching
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'
          cache-dependency-path: '**/pnpm-lock.yaml'
 
      - name: Re-enable corepack after setup-node
        run: corepack enable
 
      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
 
      - name: Setup pnpm cache
        uses: actions/cache@v4
        id: pnpm-store-cache
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: pnpm-store-${{ runner.os }}-${{ steps.yarn-hash.outputs.yarnHash }}
          restore-keys: |
            pnpm-store-${{ runner.os }}-
 
      - name: Cache Playwright browsers
        uses: actions/cache@v4
        id: playwright-cache
        with:
          path: ~/.cache/ms-playwright
          key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}-headless-shell
 
      - name: Set Playwright cache status
        run: echo "PLAYWRIGHT_CACHE_HIT=${{ steps.playwright-cache.outputs.cache-hit }}" >> $GITHUB_ENV
 
      - name: Install deps
        env:
          NODE_OPTIONS: '--max_old_space_size=6144'
          FORCE_COLOR: 3
        run: |
          echo "Installing dependencies from pnpm store..."
          PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile --prefer-offline
 
      - name: Install Playwright browsers
        run: |
          # Populate the shared browser cache (no system deps here).
          pnpm exec playwright install chromium chromium-headless-shell
 

What changed

1 third-party action is referenced by a movable tag. Pin it 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 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow