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.
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.
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.
When defined, will skip the all
and affected
inputs.
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
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
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'
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
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'
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
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'
This project is MIT licensed.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!