Skip to content
Latchkey LogoLatchkey home

Node CI workflow (apache/echarts)

The Node CI workflow from apache/echarts, explained and optimized by Latchkey.

Source: apache/echarts.github/workflows/ci.ymlLicense Apache-2.0View source
C
CI health grade
69/100
Health score
2
Jobs per trigger
3
Fixes in the optimized version

In short

  1. CI health: C (fair)
  2. The optimized version below points runs-on at Latchkey managed runners and adds caching and job timeouts.

What it does

This is the Node CI workflow from the apache/echarts 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: Node CI

on:
  pull_request:
    types: [opened, reopened, synchronize]

concurrency:
  # Note that the `teardown-pr-preview` workflow needs the same group name
  # to cancel the running `ci` workflows
  group: ${{ github.workflow }}-${{ github.event.number }}
  cancel-in-progress: true

jobs:
  lint:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - name: Fetch commit count
        env:
          PR_COMMIT_COUNT: ${{ github.event.pull_request.commits }}
        run: |
          echo "FETCH_DEPTH=$(($PR_COMMIT_COUNT + 1))" >> $GITHUB_ENV

      - uses: actions/checkout@v6
        with:
          fetch-depth: ${{ env.FETCH_DEPTH }}

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}

      - name: Cache node modules
        id: cache-dep
        uses: actions/cache@v5
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}

      - name: Install dependencies
        if: steps.cache-dep.outputs.cache-hit != 'true'
        run: npm ci

      - name: Collect changed files
        run: |
          mkdir ~/tmp/
          git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/*.ts' '*src/**/*.ts' > ~/tmp/changed_files
          echo -e "Changed files: \n$(cat ~/tmp/changed_files)"

      - name: Lint
        run: npx eslint $(cat ~/tmp/changed_files)

      - name: Build generated types
        run: npm run build:lib

      - name: Check types
        run: npm run checktype

  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - uses: actions/checkout@v6

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}

      - name: Cache node modules
        id: cache-dep
        uses: actions/cache@v5
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}

      - name: Install dependencies
        if: steps.cache-dep.outputs.cache-hit != 'true'
        run: npm ci

      - name: Unit Test
        run: npm run test

      - name: Build release
        run: npm run release

      - name: Test generated DTS
        run: npm run test:dts

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: Node CI

on:
  pull_request:
    types: [opened, reopened, synchronize]

concurrency:
  # Note that the `teardown-pr-preview` workflow needs the same group name
  # to cancel the running `ci` workflows
  group: ${{ github.workflow }}-${{ github.event.number }}
  cancel-in-progress: true

jobs:
  lint:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    runs-on: latchkey-small

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - name: Fetch commit count
        env:
          PR_COMMIT_COUNT: ${{ github.event.pull_request.commits }}
        run: |
          echo "FETCH_DEPTH=$(($PR_COMMIT_COUNT + 1))" >> $GITHUB_ENV

      - uses: actions/checkout@v6
        with:
          fetch-depth: ${{ env.FETCH_DEPTH }}

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          cache: 'npm'
          node-version: ${{ matrix.node-version }}

      - name: Cache node modules
        id: cache-dep
        uses: actions/cache@v5
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}

      - name: Install dependencies
        if: steps.cache-dep.outputs.cache-hit != 'true'
        run: npm ci

      - name: Collect changed files
        run: |
          mkdir ~/tmp/
          git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/*.ts' '*src/**/*.ts' > ~/tmp/changed_files
          echo -e "Changed files: \n$(cat ~/tmp/changed_files)"

      - name: Lint
        run: npx eslint $(cat ~/tmp/changed_files)

      - name: Build generated types
        run: npm run build:lib

      - name: Check types
        run: npm run checktype

  build:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    runs-on: latchkey-small

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - uses: actions/checkout@v6

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          cache: 'npm'
          node-version: ${{ matrix.node-version }}

      - name: Cache node modules
        id: cache-dep
        uses: actions/cache@v5
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}

      - name: Install dependencies
        if: steps.cache-dep.outputs.cache-hit != 'true'
        run: npm ci

      - name: Unit Test
        run: npm run test

      - name: Build release
        run: npm run release

      - name: Test generated DTS
        run: npm run test:dts

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. Cache dependency installs on the setup step so they are served from cache.
  3. Add a job timeout so a hung step cannot burn hours of runner time.

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:

  • Dependency installs

This workflow runs 2 jobs per trigger. All of them run 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 they are free. Estimate the monthly difference with your own run counts.

Actions used in this workflow

  • actions/checkout
  • actions/setup-node
  • actions/cache

Frequently asked questions

What does the Node CI workflow (apache/echarts) workflow do?
This is the Node CI workflow from the apache/echarts 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 C. 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 caching and job timeouts. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

References