Skip to content
Latchkey

Build and Deploy pages to GitHub Pages workflow (zloirock/core-js)

The Build and Deploy pages to GitHub Pages workflow from zloirock/core-js, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, 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: zloirock/core-js.github/workflows/build-and-deploy-pages.ymlLicense MITView source

What it does

This is the Build and Deploy pages to GitHub Pages workflow from the zloirock/core-js 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: Build and Deploy pages to GitHub Pages
on: [push, workflow_dispatch]

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  list-branches:
    runs-on: ubuntu-latest
    outputs:
      branches: ${{ steps.set-branches.outputs.branches }}
    steps:
      - name: Checkout repo
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Get branch list and set output
        id: set-branches
        run: |
          BRANCHES=$(
            git branch -r |
            grep -Ev 'HEAD|v1|v2' |
            sed 's/^[ *]*//' |
            sed 's/^origin\///' |
            jq -R . |
            jq -cs
          )
          echo "branches=$BRANCHES" >> "$GITHUB_OUTPUT"

  build-compat-pages:
    needs: list-branches
    runs-on: ubuntu-latest
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        branch: ${{ fromJson(needs.list-branches.outputs.branches) }}
    name: Build for ${{ matrix.branch }}
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ matrix.branch }}
      - name: Build cache key
        id: cache-key
        env:
          BRANCH: ${{ matrix.branch }}
        run: |
          HASH=$(git rev-parse --short HEAD)
          SAFE_BRANCH="${BRANCH//\//-}"
          echo "SAFE_BRANCH=$SAFE_BRANCH" >> "$GITHUB_ENV"
          echo "CACHE_KEY=$SAFE_BRANCH-$HASH" >> "$GITHUB_ENV"
      - name: Restore cached artifacts
        id: artifacts-restore
        uses: actions/cache/restore@v6
        with:
          path: ${{ env.SAFE_BRANCH }}
          key: ${{ env.CACHE_KEY }}
      - uses: actions/setup-node@v6
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        with:
          node-version: 26
          cache: npm
      - name: Build
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        run: |
          npm run prepare-monorepo
          npm run build-compat
          npm run bundle
      - name: Prepare build artifacts
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        run: |
          mkdir -p ${{ env.SAFE_BRANCH }}/compat
          cp tests/compat/index.html tests/compat/compat-data.js tests/compat/tests.js tests/compat/browsers-runner.js ${{ env.SAFE_BRANCH }}/compat
          mkdir -p ${{ env.SAFE_BRANCH }}/bundles
          cp tests/bundles/* ${{ env.SAFE_BRANCH }}/bundles
          mkdir -p ${{ env.SAFE_BRANCH }}/unit-browser
          cp tests/unit-browser/* ${{ env.SAFE_BRANCH }}/unit-browser
      - name: Save cached artifacts
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        uses: actions/cache/save@v6
        with:
          path: ${{ env.SAFE_BRANCH }}
          key: ${{ env.CACHE_KEY }}
      - name: Upload artifacts for branch ${{ matrix.branch }}
        uses: actions/upload-artifact@v7
        with:
          name: ${{ env.SAFE_BRANCH }}
          path: ${{ env.SAFE_BRANCH }}

  combine-pages-and-deploy:
    needs: build-compat-pages
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/checkout@v7
      - name: Download artifacts
        uses: actions/download-artifact@v8
        with:
          path: pages
      - name: Setup Pages
        uses: actions/configure-pages@v6
      - name: Upload GitHub Pages artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: pages
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5

The same workflow, on Latchkey

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

name: Build and Deploy pages to GitHub Pages
on: [push, workflow_dispatch]
 
permissions:
  contents: read
  pages: write
  id-token: write
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  list-branches:
    timeout-minutes: 30
    runs-on: latchkey-small
    outputs:
      branches: ${{ steps.set-branches.outputs.branches }}
    steps:
      - name: Checkout repo
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Get branch list and set output
        id: set-branches
        run: |
          BRANCHES=$(
            git branch -r |
            grep -Ev 'HEAD|v1|v2' |
            sed 's/^[ *]*//' |
            sed 's/^origin\///' |
            jq -R . |
            jq -cs
          )
          echo "branches=$BRANCHES" >> "$GITHUB_OUTPUT"
 
  build-compat-pages:
    timeout-minutes: 30
    needs: list-branches
    runs-on: latchkey-small
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        branch: ${{ fromJson(needs.list-branches.outputs.branches) }}
    name: Build for ${{ matrix.branch }}
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ matrix.branch }}
      - name: Build cache key
        id: cache-key
        env:
          BRANCH: ${{ matrix.branch }}
        run: |
          HASH=$(git rev-parse --short HEAD)
          SAFE_BRANCH="${BRANCH//\//-}"
          echo "SAFE_BRANCH=$SAFE_BRANCH" >> "$GITHUB_ENV"
          echo "CACHE_KEY=$SAFE_BRANCH-$HASH" >> "$GITHUB_ENV"
      - name: Restore cached artifacts
        id: artifacts-restore
        uses: actions/cache/restore@v6
        with:
          path: ${{ env.SAFE_BRANCH }}
          key: ${{ env.CACHE_KEY }}
      - uses: actions/setup-node@v6
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        with:
          node-version: 26
          cache: npm
      - name: Build
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        run: |
          npm run prepare-monorepo
          npm run build-compat
          npm run bundle
      - name: Prepare build artifacts
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        run: |
          mkdir -p ${{ env.SAFE_BRANCH }}/compat
          cp tests/compat/index.html tests/compat/compat-data.js tests/compat/tests.js tests/compat/browsers-runner.js ${{ env.SAFE_BRANCH }}/compat
          mkdir -p ${{ env.SAFE_BRANCH }}/bundles
          cp tests/bundles/* ${{ env.SAFE_BRANCH }}/bundles
          mkdir -p ${{ env.SAFE_BRANCH }}/unit-browser
          cp tests/unit-browser/* ${{ env.SAFE_BRANCH }}/unit-browser
      - name: Save cached artifacts
        if: steps.artifacts-restore.outputs.cache-hit != 'true'
        uses: actions/cache/save@v6
        with:
          path: ${{ env.SAFE_BRANCH }}
          key: ${{ env.CACHE_KEY }}
      - name: Upload artifacts for branch ${{ matrix.branch }}
        uses: actions/upload-artifact@v7
        with:
          name: ${{ env.SAFE_BRANCH }}
          path: ${{ env.SAFE_BRANCH }}
 
  combine-pages-and-deploy:
    timeout-minutes: 30
    needs: build-compat-pages
    runs-on: latchkey-small
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/checkout@v7
      - name: Download artifacts
        uses: actions/download-artifact@v8
        with:
          path: pages
      - name: Setup Pages
        uses: actions/configure-pages@v6
      - name: Upload GitHub Pages artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: pages
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5
 

What changed

This workflow runs 3 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