Skip to content

Commit

Permalink
feat(release): Allow preVersionCommand By Group
Browse files Browse the repository at this point in the history
  • Loading branch information
jogelin committed Sep 8, 2024
1 parent 0b99d1d commit d254b0d
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 7 deletions.
2 changes: 2 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,5 @@ 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 also leverage `preVersionCommand` and it will be executed before the versioning step for that release group.
77 changes: 77 additions & 0 deletions e2e/release/src/pre-version-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,81 @@ describe('nx release pre-version command', () => {
);
expect(result4).toContain('echo "error" && exit 1');
});

it('should run pre-version command before group versioning step', async () => {
updateJson(`nx.json`, (json) => {
delete json.release;
return json;
});
const result1 = runCLI('release patch -d --first-release', {
silenceError: true,
});

// command should fail because @nx/js:library configures the packageRoot to be dist/{project-name}, which doesn't exist yet
expect(result1).toContain(
`NX The project "${pkg1}" does not have a package.json available at dist/${pkg1}/package.json.`
);

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

// command should succeed because the pre-version command will build the package
const result2 = runCLI('release patch -d -g group-1 --first-release');

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

const result3 = runCLI(
'release patch -d -g group-1 --first-release --verbose'
);

expect(result3).toContain('NX Executing pre-version command');
expect(result3).toContain('Executing the following pre-version command:');
expect(result3).toContain(`nx run-many -t build -p ${pkg1}`);
expect(result3).toContain(`NX Running target build for project ${pkg1}:`);

updateJson(`nx.json`, (json) => {
json.release = {
groups: {
'group-1': {
projects: [pkg1],
version: {
preVersionCommand: `echo "error" && exit 1`,
},
},
},
};
return json;
});

// command should fail because the pre-version command will fail
const result4 = runCLI('release patch -d -g group-1 --first-release', {
silenceError: true,
});
expect(result4).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');

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

0 comments on commit d254b0d

Please sign in to comment.