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

fix(release): add groupPreVersionCommand to schema, improve logging #28087

Merged
merged 3 commits into from
Sep 25, 2024
Merged
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
4 changes: 3 additions & 1 deletion e2e/release/src/pre-version-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ describe('nx release pre-version command', () => {
// 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');
expect(result4).toContain(
`NX Executing release group pre-version command for "${groupName}"`
);

updateJson(`nx.json`, (json) => {
json.release = {
Expand Down
47 changes: 26 additions & 21 deletions packages/nx/schemas/nx-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,7 @@
]
},
"version": {
"allOf": [
{
"$ref": "#/definitions/NxReleaseVersionConfiguration"
},
{
"allOf": [
{
"not": {
"required": ["git"]
}
},
{
"not": {
"required": ["preVersionCommand"]
}
}
]
}
]
"$ref": "#/definitions/NxReleaseGroupVersionConfiguration"
},
"changelog": {
"oneOf": [
Expand Down Expand Up @@ -675,9 +657,32 @@
},
"preVersionCommand": {
"type": "string",
"description": "A command to run after validation of nx release configuration, but before versioning begins. Used for preparing build artifacts. If --dry-run is passed, the command is still executed, but with the NX_DRY_RUN environment variable set to 'true'."
"description": "A command to run after validation of nx release configuration, but before versioning begins. Useful for preparing build artifacts. If --dry-run is passed, the command is still executed, but with the NX_DRY_RUN environment variable set to 'true'."
}
}
},
"additionalProperties": false
},
"NxReleaseGroupVersionConfiguration": {
"type": "object",
"properties": {
"conventionalCommits": {
"type": "boolean",
"description": "Shorthand for enabling the current version of projects to be resolved from git tags, and the next version to be determined by analyzing commit messages according to the Conventional Commits specification.",
"default": false
},
"generator": {
"type": "string"
},
"generatorOptions": {
"type": "object",
"additionalProperties": true
},
"groupPreVersionCommand": {
"type": "string",
"description": "A command to run after validation of nx release configuration AND after the release.version.preVersionCommand (if any), but before versioning begins for this specific group. Useful for preparing build artifacts for the group. If --dry-run is passed, the command is still executed, but with the NX_DRY_RUN environment variable set to 'true'."
}
},
"additionalProperties": false
},
"NxReleaseChangelogConfiguration": {
"type": "object",
Expand Down
21 changes: 15 additions & 6 deletions packages/nx/src/command-line/release/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,14 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
for (const releaseGroup of releaseGroups) {
const releaseGroupName = releaseGroup.name;

runPreVersionCommand(releaseGroup.version.groupPreVersionCommand, {
dryRun: args.dryRun,
verbose: args.verbose,
});
runPreVersionCommand(
releaseGroup.version.groupPreVersionCommand,
{
dryRun: args.dryRun,
verbose: args.verbose,
},
releaseGroup
);

const projectBatches = batchProjectsByGeneratorConfig(
projectGraph,
Expand Down Expand Up @@ -727,13 +731,18 @@ function resolveGeneratorData({
}
function runPreVersionCommand(
preVersionCommand: string,
{ dryRun, verbose }: { dryRun: boolean; verbose: boolean }
{ dryRun, verbose }: { dryRun: boolean; verbose: boolean },
releaseGroup?: ReleaseGroupWithName
) {
if (!preVersionCommand) {
return;
}

output.logSingleLine(`Executing pre-version command`);
output.logSingleLine(
releaseGroup
? `Executing release group pre-version command for "${releaseGroup.name}"`
: `Executing pre-version command`
);
if (verbose) {
console.log(`Executing the following pre-version command:`);
console.log(preVersionCommand);
Expand Down