Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .github/workflows/reusable-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Reusable workflow for running tests in pnpm based Node.js projects.

The workflow checks out the repository, installs dependencies with pnpm, and runs the configured test command.
The workflow checks out the repository, installs dependencies with pnpm, optionally runs pre-test and post-test pnpm commands, and runs the configured test command.

## Usage

Expand Down Expand Up @@ -43,6 +43,22 @@ jobs:
install-args: "--prefer-offline"
```

## With Pre/Post Test Commands

Run `pnpm build` before tests, `pnpm coverage` after tests, or provide any other pnpm arguments that should run before or after the test step.

```yaml
jobs:
test:
permissions:
contents: read
uses: luxass/shared-workflows/.github/workflows/reusable-test.yaml@v0.8.2
with:
pre-test-script: "build"
test-script: "test:ci"
post-test-script: "coverage"
```

## Inputs

| Name | Type | Default | Description |
Expand All @@ -55,7 +71,9 @@ jobs:
| `registry-url` | `string` | `""` | Registry URL to configure for authentication. |
| `scope` | `string` | `""` | Scope for authenticating against scoped registries. |
| `install-args` | `string` | `""` | Additional arguments passed to `pnpm install`. |
| `pre-test-script` | `string` | `""` | Optional arguments passed to `pnpm` before the test step. Skipped when empty. |
| `test-script` | `string` | `test` | Arguments passed to `pnpm` for the test step. |
| `post-test-script` | `string` | `""` | Optional arguments passed to `pnpm` after the test step. Skipped when empty. |

## Secrets

Expand All @@ -77,6 +95,6 @@ The caller job should grant `contents: read` because the reusable workflow check

| Job | Description |
| --- | --- |
| `test` | Runs setup, then runs the configured `pnpm` test command. |
| `test` | Runs setup, optionally runs the configured pre-test command, runs the configured `pnpm` test command, then optionally runs the configured post-test command. |

The test script input is passed to `pnpm` through `actions/run-pnpm` without shell re-interpretation.
The pre-test, test, and post-test script inputs are passed to `pnpm` through `actions/run-pnpm` without shell re-interpretation.
22 changes: 22 additions & 0 deletions .github/workflows/reusable-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ on:
type: string
default: ""
required: false
pre-test-script:
description: "Arguments passed to pnpm before the test step"
type: string
default: ""
required: false
test-script:
description: "Arguments passed to pnpm for the test step"
type: string
default: "test"
required: false
post-test-script:
description: "Arguments passed to pnpm after the test step"
type: string
default: ""
required: false
secrets:
token:
description: "GitHub token to use for checkout (defaults to GITHUB_TOKEN)"
Expand All @@ -74,7 +84,19 @@ jobs:
submodules: ${{ inputs.submodules }}
install-args: ${{ inputs.install-args }}

- name: pre-test
if: ${{ inputs.pre-test-script != '' }}
uses: luxass/shared-workflows/actions/run-pnpm@82c9e3625f7959ea6b3ddd2014a8a095a269e8f7 # actions/run-pnpm/v0.2.1
with:
args: ${{ inputs.pre-test-script }}

- name: test
uses: luxass/shared-workflows/actions/run-pnpm@82c9e3625f7959ea6b3ddd2014a8a095a269e8f7 # actions/run-pnpm/v0.2.1
with:
args: ${{ inputs.test-script }}

- name: post-test
if: ${{ inputs.post-test-script != '' }}
uses: luxass/shared-workflows/actions/run-pnpm@82c9e3625f7959ea6b3ddd2014a8a095a269e8f7 # actions/run-pnpm/v0.2.1
with:
args: ${{ inputs.post-test-script }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This repository contains reusable GitHub Actions workflows and composite actions
| Workflow | Description | Docs | Example |
| :------- | :---------- | :--- | :------ |
| [reusable-ci.yaml](.github/workflows/reusable-ci.yaml) | Runs build, lint, format, and typecheck steps. Each step is configurable. | [Docs](.github/workflows/reusable-ci.md) | [Example](examples/ci.yaml) |
| [reusable-test.yaml](.github/workflows/reusable-test.yaml) | Installs dependencies and runs the configured pnpm test command. | [Docs](.github/workflows/reusable-test.md) | [Example](examples/test.yaml) |
| [reusable-test.yaml](.github/workflows/reusable-test.yaml) | Installs dependencies and runs optional pre/post-test commands around the configured pnpm test command. | [Docs](.github/workflows/reusable-test.md) | [Example](examples/test.yaml) |
| [reusable-test-build-tools.yaml](.github/workflows/reusable-test-build-tools.yaml) | Tests build, test, and typecheck commands against a build tool package matrix. | [Docs](.github/workflows/reusable-test-build-tools.md) | [Example](examples/test-build-tools.yaml) |
| [reusable-ci-security.yaml](.github/workflows/reusable-ci-security.yaml) | Runs zizmor security analysis for GitHub Actions and uploads SARIF results. | [Docs](.github/workflows/reusable-ci-security.md) | [Example](examples/ci-security.yaml) |
| [reusable-release-npm.yaml](.github/workflows/reusable-release-npm.yaml) | Publishes packages to npm with OIDC provenance. | [Docs](.github/workflows/reusable-release-npm.md) | [Example](examples/release-npm.yaml) |
Expand Down