Skip to content

Latest commit

 

History

History
129 lines (100 loc) · 3.31 KB

lib-ci.md

File metadata and controls

129 lines (100 loc) · 3.31 KB

Lib CI

Wrapper to run NPM scripts in CI. Supports providing a Node.js version and multiple commands. Automatically includes Yarn/NPM module cache and Next.js build caching.

Not suitable for:

  • Commands with secrets. Reusable workflows have specific handling around secrets. This workflow doesn't support any workaround for this.

Usage

Basic

# .github/workflows/ci.yml
on:
  push:
    branches:
      - main
  pull_request:

jobs:
  ci:
    uses: lightbasenl/platforms/.github/workflows/lib-ci.yml@main
    with:
      command: |
        npm run lint
        npm run build

Define a Matrix

# .github/workflows/ci.yml
on:
  push:
    branches:
      - main
  pull_request:

jobs:
  ci:
    uses: lightbasenl/platforms/.github/workflows/lib-ci.yml@main
    strategy:
      matrix:
        runs:
          - node-version: 18
            command: |
              npm run lint
          - node-version: 20
            command: |
              npm run build
    with:
      node-version: ${{ matrix.runs.node-version }}
      command: ${{ matrix.runs.command }}

Only execute a command on main:

# .github/workflows/ci.yml
on:
  push:
    branches:
      - main
  pull_request:

jobs:
  update-localazy:
    uses: lightbasenl/platforms/.github/workflows/lib-ci.yml@main
    with:
      node-version: 18
      main-command: |
        npx @localazy/cli upload  # ...

Preventing concurrent runs:

# .github/workflows/ci.yml
on:
  push:
    branches:
      - main
  pull_request:

concurrency:
  group: |
    ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  ci:
    uses: lightbasenl/platforms/.github/workflows/lib-ci.yml@main
    with:
      node-version: 20
      main-command: |
        npm run build

Inputs

INPUT TYPE REQUIRED DEFAULT DESCRIPTION
command string false Command to run. Supports multi-line
strings.
main-command string false Command to run when on
the main branch. Supports multi-line
strings.
node-version string false "20" Node.js version to run CI
against.
runner string false "ubuntu-latest" Specify the runner to use.
This shouldn't be necessary for
most jobs.

Outputs

No outputs.

Secrets

No secrets.