Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parameters to override base/head commits #314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This behavior can be modified using the different inputs (see below).
with:
fetch-depth: 0

- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: lint,build,deploy
```
Expand All @@ -53,16 +53,18 @@ 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 | 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 |
| 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 | 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 |
| baseBoundaryOverride | String | | | Parameter to use for overriding nx base commit |
| headBoundaryOverride | String | | | Parameter to use for overriding nx head commit |

**Note:** `all` and `affected` are mutually exclusive.

Expand All @@ -78,7 +80,7 @@ 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
commit; unless base/head overrides provided

## Examples

Expand All @@ -91,7 +93,7 @@ This will run the `build` target on all the affected projects.

```yaml
---
- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: build
affected: 'true' # Defaults to true, therefore optional
Expand All @@ -106,7 +108,7 @@ projects of the workspace.

```yaml
---
- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: lint,test,build
all: 'true'
Expand All @@ -121,7 +123,7 @@ only.

```yaml
---
- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: build
projects: frontend,backend
Expand All @@ -136,7 +138,7 @@ sequentially.

```yaml
---
- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: lint
all: 'true'
Expand All @@ -152,7 +154,7 @@ Nx workspace located in another folder than the repository root.

```yaml
---
- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: build
workingDirectory: my-nx-subfolder
Expand All @@ -168,7 +170,7 @@ Nx Cloud enabled (by adding the `--scan` command option and both

```yaml
---
- uses: mansagroup/nrwl-nx-action@v2
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: build
nxCloud: 'true'
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ inputs:
workingDirectory:
description: 'Path to the Nx workspace, needed if not the repository root'
required: false
baseBoundaryOverride:
description: 'Parameter to use for overriding nx base commit'
required: false
headBoundaryOverride:
description: 'Parameter to use for overriding nx head commit'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

114 changes: 112 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"jest-circus": "29.2.1",
"lint-staged": "13.0.3",
"prettier": "2.7.1",
"ts-jest": "^29.0.3",
"typescript": "4.8.4"
},
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type Inputs = {
args: string[];
nxCloud: boolean;
workingDirectory: string;
baseBoundaryOverride: string;
headBoundaryOverride: string;
};

const ARGS_REGEX = /\w+|"(?:\\"|[^"])+"/g;
Expand Down Expand Up @@ -39,5 +41,7 @@ export function parseInputs(): Inputs {
args: parseArgs(core.getInput('args')),
nxCloud: core.getInput('nxCloud') === 'true',
workingDirectory: core.getInput('workingDirectory'),
baseBoundaryOverride: core.getInput('baseBoundaryOverride'),
headBoundaryOverride: core.getInput('headBoundaryOverride'),
};
}
39 changes: 26 additions & 13 deletions src/run-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,40 @@ import type { PullRequest, PushEvent } from '@octokit/webhooks-types';
import type { CommandWrapper } from './command-builder';
import type { Inputs } from './inputs';

async function retrieveGitBoundaries(): Promise<[base: string, head: string]> {
async function retrieveGitBoundaries(
inputs: Inputs,
): Promise<[base: string, head: string]> {
if (github.context.eventName === 'pull_request') {
const prPayload = github.context.payload.pull_request as PullRequest;
return [prPayload.base.sha, prPayload.head.sha];
} else if (github.context.eventName === 'push') {
const pushPayload = github.context.payload as PushEvent;
return [pushPayload.before, pushPayload.after];
return [
inputs.baseBoundaryOverride || pushPayload.before,
inputs.headBoundaryOverride || pushPayload.after,
];
} else {
let base = '';
await exec.exec('git', ['rev-parse', 'HEAD~1'], {
listeners: {
stdout: (data: Buffer) => (base += data.toString()),
},
});
if (inputs.baseBoundaryOverride) {
base = inputs.baseBoundaryOverride;
} else {
await exec.exec('git', ['rev-parse', 'HEAD~1'], {
listeners: {
stdout: (data: Buffer) => (base += data.toString()),
},
});
}

let head = '';
await exec.exec('git', ['rev-parse', 'HEAD'], {
listeners: {
stdout: (data: Buffer) => (head += data.toString()),
},
});
if (inputs.headBoundaryOverride) {
head = inputs.headBoundaryOverride;
} else {
await exec.exec('git', ['rev-parse', 'HEAD'], {
listeners: {
stdout: (data: Buffer) => (head += data.toString()),
},
});
}

return [
base.replace(/(\r\n|\n|\r)/gm, ''),
Expand Down Expand Up @@ -65,7 +78,7 @@ async function runNxAffected(
const boundaries = await core.group(
'🏷 Retrieving Git boundaries (affected command)',
() =>
retrieveGitBoundaries().then((boundaries) => {
retrieveGitBoundaries(inputs).then((boundaries) => {
core.info(`Base boundary: ${boundaries[0]}`);
core.info(`Head boundary: ${boundaries[1]}`);
return boundaries;
Expand Down