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

feat(release): prompt to create github release when no file changes #21819

Merged
merged 6 commits into from
Feb 21, 2024
45 changes: 44 additions & 1 deletion packages/nx/src/command-line/release/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as chalk from 'chalk';
import { prompt } from 'enquirer';
import { readFileSync, writeFileSync } from 'node:fs';
import { valid } from 'semver';
import { dirSync } from 'tmp';
Expand All @@ -15,6 +16,7 @@ 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 { isCI } from '../../utils/is-ci';
import { output } from '../../utils/output';
import { handleErrors } from '../../utils/params';
import { joinPathFragments } from '../../utils/path';
Expand Down Expand Up @@ -550,7 +552,32 @@ async function applyChangesAndExit(
`No changes were detected for any changelog files, so no changelog entries will be generated.`,
],
});
return;

if (!postGitTasks.length) {
// no GitHub releases to create so we can just exit
return;
}

if (isCI()) {
output.warn({
title: `Skipped GitHub release creation because no changes were detected for any changelog files.`,
});
return;
} else {
fahslaj marked this conversation as resolved.
Show resolved Hide resolved
// prompt the user to see if they want to create a GitHub release anyway
// we know that the user has configured GitHub releases because we have postGitTasks
const shouldCreateGitHubReleaseAnyway = await promptForGitHubRelease();

if (!shouldCreateGitHubReleaseAnyway) {
return;
}

for (const postGitTask of postGitTasks) {
await postGitTask(latestCommit);
}

return;
}
}

// Generate a new commit for the changes, if configured to do so
Expand Down Expand Up @@ -951,3 +978,19 @@ export function shouldCreateGitHubRelease(

return (changelogConfig || {}).createRelease === 'github';
}

async function promptForGitHubRelease(): Promise<boolean> {
try {
const result = await prompt<{ confirmation: boolean }>([
{
name: 'confirmation',
message: 'Do you want to create a GitHub release anyway?',
type: 'confirm',
},
]);
return result.confirmation;
} catch (e) {
// Handle the case where the user exits the prompt with ctrl+c
return false;
}
}