Skip to content

Commit

Permalink
feat(release): support groupPreVersionCommand for release groups (#27474
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jogelin authored Sep 17, 2024
1 parent 786537e commit 71fe65f
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 9 deletions.
19 changes: 19 additions & 0 deletions docs/shared/recipes/nx-release/build-before-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,22 @@ In order to ensure that projects are built before the new version is applied to
```

This command will run the `build` target for all projects before the version step of Nx Release. Any command can be specified, including non-nx commands. This step is often required when [publishing from a custom dist directory](/recipes/nx-release/publish-custom-dist-directory), as the dist directory must be built before the version is applied to the dist directory's package manifest.

When using release groups in which the member projects are versioned together, you can use `groupPreVersionCommand` and it will be executed before the versioning step for that release group.

```json {% fileName="nx.json" %}
{
"release": {
"groups": {
"my-group": {
"projects": ["my-lib-one", "my-lib-two"],
"version": {
"groupPreVersionCommand": "npx nx run-many -t build -p my-lib-one,my-lib-two"
}
}
}
}
}
```

The `groupPreVersionCommand` will run in addition to the global `preVersionCommand`.
32 changes: 26 additions & 6 deletions e2e/release/src/pre-version-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ describe('nx release pre-version command', () => {
expect(result3).toContain('nx run-many -t build');
expect(result3).toContain(`NX Running target build for project ${pkg1}:`);

const groupName = uniq('group-1');
updateJson(`nx.json`, (json) => {
json.release = {
groups: {
[groupName]: {
projects: [pkg1],
version: {
groupPreVersionCommand: `nx run-many -t build -p ${pkg1}`,
},
},
},
};
return json;
});

// command should succeed because the pre-version command will build the package
const result4 = runCLI(`release patch -d -g ${groupName} --first-release`);

expect(result4).toContain('NX Executing pre-version command');

updateJson(`nx.json`, (json) => {
json.release = {
version: {
Expand All @@ -98,20 +118,20 @@ describe('nx release pre-version command', () => {
});

// command should fail because the pre-version command will fail
const result4 = runCLI('release patch -d --first-release', {
const result5 = runCLI('release patch -d --first-release', {
silenceError: true,
});
expect(result4).toContain(
expect(result5).toContain(
'NX The pre-version command failed. Retry with --verbose to see the full output of the pre-version command.'
);
expect(result4).toContain('echo "error" && exit 1');
expect(result5).toContain('echo "error" && exit 1');

const result5 = runCLI('release patch -d --first-release --verbose', {
const result6 = runCLI('release patch -d --first-release --verbose', {
silenceError: true,
});
expect(result5).toContain(
expect(result6).toContain(
'NX The pre-version command failed. See the full output above.'
);
expect(result4).toContain('echo "error" && exit 1');
expect(result6).toContain('echo "error" && exit 1');
});
});
Loading

0 comments on commit 71fe65f

Please sign in to comment.