Skip to content

Commit

Permalink
fix(release): logging improvements (#21692)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Feb 8, 2024
1 parent ab9c579 commit 49bba42
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 87 deletions.
7 changes: 0 additions & 7 deletions packages/nx/src/command-line/release/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { FsTree, Tree } from '../../generators/tree';
import { registerTsProject } from '../../plugins/js/utils/register';
import { createProjectGraphAsync } from '../../project-graph/project-graph';
import { interpolate } from '../../tasks-runner/utils';
import { logger } from '../../utils/logger';
import { output } from '../../utils/output';
import { handleErrors } from '../../utils/params';
import { joinPathFragments } from '../../utils/path';
Expand Down Expand Up @@ -476,12 +475,6 @@ async function applyChangesAndExit(
await postGitTask(latestCommit);
}

if (args.dryRun) {
logger.warn(
`\nNOTE: The "dryRun" flag means no changelogs were actually created.`
);
}

return 0;
}

Expand Down
61 changes: 39 additions & 22 deletions packages/nx/src/command-line/release/command-object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Argv, CommandModule, showHelp } from 'yargs';
import { readNxJson } from '../../project-graph/file-utils';
import { logger } from '../../utils/logger';
import {
OutputStyle,
RunManyOptions,
Expand Down Expand Up @@ -159,15 +160,18 @@ const releaseCommand: CommandModule<NxReleaseArgs, ReleaseOptions> = {
}
return true;
}),
handler: (args) =>
import('./release')
.then((m) => m.releaseCLIHandler(args))
.then((versionDataOrExitCode) => {
if (typeof versionDataOrExitCode === 'number') {
return process.exit(versionDataOrExitCode);
}
process.exit(0);
}),
handler: async (args) => {
const release = await import('./release');
const result = await release.releaseCLIHandler(args);
if (args.dryRun) {
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
}

if (typeof result === 'number') {
process.exit(result);
}
process.exit(0);
},
};

const versionCommand: CommandModule<NxReleaseArgs, VersionOptions> = {
Expand Down Expand Up @@ -195,15 +199,18 @@ const versionCommand: CommandModule<NxReleaseArgs, VersionOptions> = {
'Whether or not to stage the changes made by this command. Useful when combining this command with changelog generation.',
})
),
handler: (args) =>
import('./version')
.then((m) => m.releaseVersionCLIHandler(args))
.then((versionDataOrExitCode) => {
if (typeof versionDataOrExitCode === 'number') {
return process.exit(versionDataOrExitCode);
}
process.exit(0);
}),
handler: async (args) => {
const release = await import('./version');
const result = await release.releaseVersionCLIHandler(args);
if (args.dryRun) {
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
}

if (typeof result === 'number') {
process.exit(result);
}
process.exit(0);
},
};

const changelogCommand: CommandModule<NxReleaseArgs, ChangelogOptions> = {
Expand Down Expand Up @@ -254,10 +261,16 @@ const changelogCommand: CommandModule<NxReleaseArgs, ChangelogOptions> = {
})
),
handler: async (args) => {
const status = await (
await import('./changelog')
).releaseChangelogCLIHandler(args);
process.exit(status);
const release = await import('./changelog');
const result = await release.releaseChangelogCLIHandler(args);
if (args.dryRun) {
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
}

if (typeof result === 'number') {
process.exit(result);
}
process.exit(0);
},
};

Expand All @@ -284,6 +297,10 @@ const publishCommand: CommandModule<NxReleaseArgs, PublishOptions> = {
const status = await (
await import('./publish')
).releasePublishCLIHandler(coerceParallelOption(withOverrides(args, 2)));
if (args.dryRun) {
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
}

process.exit(status);
},
};
Expand Down
7 changes: 0 additions & 7 deletions packages/nx/src/command-line/release/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
createOverrides,
readGraphFileFromGraphArg,
} from '../../utils/command-line-utils';
import { logger } from '../../utils/logger';
import { handleErrors } from '../../utils/params';
import { projectHasTarget } from '../../utils/project-graph-utils';
import { generateGraph } from '../graph/graph';
Expand Down Expand Up @@ -120,12 +119,6 @@ export async function releasePublish(
}
}

if (_args.dryRun) {
logger.warn(
`\nNOTE: The "dryRun" flag means no projects were actually published.`
);
}

return overallExitStatus;
}

Expand Down
5 changes: 1 addition & 4 deletions packages/nx/src/command-line/release/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,13 @@ export async function release(
if (shouldPublish) {
await releasePublish(args);
} else {
console.log('Skipped publishing packages.');
output.logSingleLine('Skipped publishing packages.');
}

return versionResult;
}

async function promptForPublish(): Promise<boolean> {
console.log('\n');

try {
const reply = await prompt<{ confirmation: boolean }>([
{
Expand All @@ -169,7 +167,6 @@ async function promptForPublish(): Promise<boolean> {
]);
return reply.confirmation;
} catch (e) {
console.log('\n');
// Handle the case where the user exits the prompt with ctrl+c
return false;
}
Expand Down
85 changes: 47 additions & 38 deletions packages/nx/src/command-line/release/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,45 +103,27 @@ export async function createOrUpdateGithubRelease(
}
}

const reply = await prompt<{ open: 'Yes' | 'No' }>([
{
name: 'open',
message:
'Do you want to finish creating the release manually in your browser?',
type: 'autocomplete',
choices: [
{
name: 'Yes',
hint: 'It will pre-populate the form for you',
},
{
name: 'No',
},
],
initial: 0,
},
]).catch(() => {
return { open: 'No' };
});

if (reply.open === 'Yes') {
const open = require('open');
await open(result.url)
.then(() => {
console.info(
`\nFollow up in the browser to manually create the release:\n\n` +
chalk.underline(chalk.cyan(result.url)) +
`\n`
);
})
.catch(() => {
console.info(
`Open this link to manually create a release: \n` +
chalk.underline(chalk.cyan(result.url)) +
'\n'
);
});
const shouldContinueInGitHub = await promptForContinueInGitHub();
if (!shouldContinueInGitHub) {
return;
}

const open = require('open');
await open(result.url)
.then(() => {
console.info(
`\nFollow up in the browser to manually create the release:\n\n` +
chalk.underline(chalk.cyan(result.url)) +
`\n`
);
})
.catch(() => {
console.info(
`Open this link to manually create a release: \n` +
chalk.underline(chalk.cyan(result.url)) +
'\n'
);
});
}

/**
Expand Down Expand Up @@ -170,6 +152,33 @@ export async function createOrUpdateGithubRelease(
}
}

async function promptForContinueInGitHub(): Promise<boolean> {
try {
const reply = await prompt<{ open: 'Yes' | 'No' }>([
{
name: 'open',
message:
'Do you want to finish creating the release manually in your browser?',
type: 'autocomplete',
choices: [
{
name: 'Yes',
hint: 'It will pre-populate the form for you',
},
{
name: 'No',
},
],
initial: 0,
},
]);
return reply.open === 'Yes';
} catch (e) {
// Handle the case where the user exits the prompt with ctrl+c
process.exit(1);
}
}

async function syncGithubRelease(
githubRequestConfig: GithubRequestConfig,
release: GithubReleaseOptions,
Expand Down
9 changes: 0 additions & 9 deletions packages/nx/src/command-line/release/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import {
NxJsonConfiguration,
joinPathFragments,
logger,
output,
workspaceRoot,
} from '../../devkit-exports';
Expand Down Expand Up @@ -281,10 +280,6 @@ export async function releaseVersion(
}
}

if (args.dryRun) {
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
}

return {
// An overall workspace version cannot be relevant when filtering to independent projects
workspaceVersion: undefined,
Expand Down Expand Up @@ -422,10 +417,6 @@ export async function releaseVersion(
}
}

if (args.dryRun) {
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
}

return {
workspaceVersion,
projectsVersionData: versionData,
Expand Down

0 comments on commit 49bba42

Please sign in to comment.