Skip to content
Latchkey LogoLatchkey home

Cross-Platform Builds workflow (ampproject/amphtml)

The Cross-Platform Builds workflow from ampproject/amphtml, explained and optimized by Latchkey.

Source: ampproject/amphtml.github/workflows/cross-platform-builds.ymlLicense Apache-2.0View source
D
CI health grade
53/100
Health score
2
Jobs per trigger
4
Fixes in the optimized version

In short

  1. CI health: D (needs work)
  2. The optimized version below points runs-on at Latchkey managed runners and adds run de-duplication, caching, and job timeouts.

What it does

This is the Cross-Platform Builds workflow from the ampproject/amphtml 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: Cross-Platform Builds

on:
  push:
    branches:
      - main

permissions:
  contents: read

jobs:
  compile:
    if: github.repository == 'ampproject/amphtml'
    strategy:
      matrix:
        platform: [ubuntu, macos, windows]
        flavor: [Build, Dist]
      fail-fast: false
    runs-on: ${{ matrix.platform }}-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
        with:
          egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

      - name: Checkout Repo
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
      - name: Set Up Node
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          node-version: lts/*
      - name: Install Dependencies
        run: bash ./.github/workflows/install_dependencies.sh
      - name: ${{ matrix.flavor }}
        run: node build-system/pr-check/cross-platform-builds.js --flavor=${{ matrix.flavor }}

  create-issue-on-error:
    if: failure()
    needs: compile
    permissions:
      contents: read
      issues: write
    runs-on: ubuntu-latest
    environment: create_issue_on_error
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
        with:
          egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

      - name: Create issue on error
        uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
        with:
          filename: .github/create_issue_on_error.md
        env:
          GITHUB_TOKEN: ${{ secrets.AMPPROJECTBOT }}
          WORKFLOW_NAME: ${{ github.workflow }}
          MENTION: '@ampproject/release-on-duty'
          REPO_SLUG: ${{ github.repository }}
          RUN_ID: ${{ github.run_id }}

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

workflow (.yml), optimized
name: Cross-Platform Builds

on:
  push:
    branches:
      - main

permissions:
  contents: read

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

jobs:
  compile:
    timeout-minutes: 30
    if: github.repository == 'ampproject/amphtml'
    strategy:
      matrix:
        platform: [ubuntu, macos, windows]
        flavor: [Build, Dist]
      fail-fast: false
    runs-on: ${{ matrix.platform }}-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
        with:
          egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

      - name: Checkout Repo
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
      - name: Set Up Node
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          cache: 'npm'
          node-version: lts/*
      - name: Install Dependencies
        run: bash ./.github/workflows/install_dependencies.sh
      - name: ${{ matrix.flavor }}
        run: node build-system/pr-check/cross-platform-builds.js --flavor=${{ matrix.flavor }}

  create-issue-on-error:
    timeout-minutes: 30
    if: failure()
    needs: compile
    permissions:
      contents: read
      issues: write
    runs-on: ubuntu-latest
    runs-on: latchkey-small
    environment: create_issue_on_error
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
        with:
          egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

      - name: Create issue on error
        uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
        with:
          filename: .github/create_issue_on_error.md
        env:
          GITHUB_TOKEN: ${{ secrets.AMPPROJECTBOT }}
          WORKFLOW_NAME: ${{ github.workflow }}
          MENTION: '@ampproject/release-on-duty'
          REPO_SLUG: ${{ github.repository }}
          RUN_ID: ${{ github.run_id }}

What changed

  1. Run on Latchkey managed runners with one line (runs-on), which apply the fixes below automatically and self-heal transient failures. Each Linux x64 job moves to the Latchkey size matching its vCPU count, latchkey-small for a standard 2 vCPU runner; macOS, Windows and arm64 jobs stay as written.
  2. Cancel superseded runs when a branch or PR gets a newer push.
  3. Cache dependency installs on the setup step so they are served from cache.
  4. Add a job timeout so a hung step cannot burn hours of runner time.

This workflow runs 2 jobs (7 with the matrix expanded) per trigger. 1 of the 7 runs on a standard GitHub-hosted Linux x64 runner, which in a private repository bills $0.006 a minute against $0.0025 on latchkey-small, 58% lower; in a public repository like this one it is free. Estimate the monthly difference with your own run counts.

Actions used in this workflow

  • step-security/harden-runner
  • actions/checkout
  • actions/setup-node
  • JasonEtco/create-an-issue

Frequently asked questions

What does the Cross-Platform Builds workflow (ampproject/amphtml) workflow do?
This is the Cross-Platform Builds workflow from the ampproject/amphtml repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
What CI health grade does this workflow get?
This Node.js workflow grades D. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.
How can I improve this Node.js workflow?
Add run de-duplication, caching, and job timeouts. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

References