Skip to content

A GitHub Action to wrap Nrwl Nx commands in your workflows.

License

Notifications You must be signed in to change notification settings

obha/nrwl-nx-action

 
 

Repository files navigation

Banner

Nrwl Nx Action

License GitHub Issues GitHub Stars

The action wraps the usage of the Nrwl Nx monorepo development toolkit.

Nx manages multiple projects linked each other with a dependecy graph. One of its key features is to permit to run one or more tasks only on the projects affected by our changes (by checking the difference between two Git references).

GitHub Action's workflows provide some information about the Git references concerned by the workflow, in a pull request context, we have the current commit and the last one from the base branch. Combined with Nx, we can determine the projects affected by the whole pull request.

It's more than useful in a CI/CD context: we are able to lint, build and deploy only the projects affected by a pull request for instance.

Copy-pasting the bash code to compute the reference bounds for Nx is not that maintenable. That's why we are open-sourcing this action to do the trick for you.

Usage

By default, the action will try to run the provided tasks only on the affected projects. This behavior can be modified using the different inputs (see below).

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: lint,build,deploy

This simple step will run three targets: lint, build and deploy, sequentially only on the affected projects. Nothing more. Simple. More examples below.

Inputs

This GitHub action can take several inputs to configure its behaviors:

Name Type Default Example Description
targets Comma-separated list ø lint,test,build List of targets to execute
projects Comma-separated list ø frontend,backend List of projects to use (more below)
all Boolean false true Run the targets on all the projects of the Nx workspace
affected Boolean true true Run the targets on the affected projects since the last modifications (more below)
parallel Boolean false true Run the tasks in parallel (can be expensive)
maxParallel Number 3 3 Number of tasks to execute in parallel (can be expensive)
args String ø --key="value" Optional args to append to the Nx commands
nxCloud Boolean false true Enable support of Nx Cloud
workingDirectory String ø myNxFolder Path to the Nx workspace, needed if not the repository root

Note: all and affected are mutually exclusive.

projects

When defined, will skip the all and affected inputs.

affected

When set to true, the affected detection will depend on the event type of the workflow:

  • Inside a pull request context, the action will use the base and head Git references
  • Otherwise, will compute the difference between the HEAD and the last commit

Examples

Run one target on all the affected projects (default)

This will run the build target on all the affected projects. This is the default behavior.

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: build
    affected: 'true' # Defaults to true, therefore optional

Run multiple targets to all projects

This will run three targets: lint, test and build to all the projects of the workspace.

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: lint,test,build
    all: 'true'

Run one target on some projects

This will run the build target on the frontend and backend projects only.

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: build
    projects: frontend,backend

Run one target on all the projects in parallel

This will run the lint target on all the projects of the workspace in parallel.

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: lint
    all: 'true'
    parallel: 'true'

Run one target on a Nx workspace located in another folder

This will run the build target on all the affected projects of a Nx workspace located in another folder than the repository root.

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: build
    workingDirectory: my-nx-subfolder

Run one target with Nx Cloud enabled

This will run the build target on all the affected projects with Nx Cloud enabled (by adding the --scan command option and both NX_BRANCH and NX_RUN_GROUP environment variables).

workflow.yml

---
- uses: mansagroup/nrwl-nx-action@v2
  with:
    targets: build
    nxCloud: 'true'

License

This project is MIT licensed.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

About

A GitHub Action to wrap Nrwl Nx commands in your workflows.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 96.9%
  • JavaScript 3.1%