Skip to content

Commit eec5abe

Browse files
committed
"publish: stash of uncommitted changes by release script"
1 parent f005faf commit eec5abe

File tree

8 files changed

+85
-139
lines changed

8 files changed

+85
-139
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"test-external:ember-data-relationship-tracker": "node ./scripts/test-external-partner-project.js ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git"
3939
},
4040
"devDependencies": {
41-
"@octokit/rest": "^20.0.2",
4241
"bun-types": "^1.0.25",
4342
"@types/semver": "^7.5.6",
4443
"chalk": "^4.1.2",

pnpm-lock.yaml

-118
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/core/publish/steps/confirm-strategy.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@ import chalk from 'chalk';
22
import * as readline from 'readline/promises';
33

44
export async function confirmStrategy() {
5+
return confirm({
6+
prompt: chalk.white(`\nDo you want to continue with this strategy?`),
7+
cancelled: chalk.red('🚫 Strategy not confirmed. Exiting...'),
8+
});
9+
}
10+
11+
/**
12+
* Prompt user to continue, exit if not confirmed.
13+
*
14+
* In CI environments, this function will return immediately without prompting.
15+
*
16+
* config.prompt - The prompt to display to the user
17+
* config.cancelled - The message to display if the user cancels
18+
*
19+
* yes/no prompt will be added to the end of the prompt text automatically.
20+
*
21+
* @internal
22+
*/
23+
export async function confirm(config: { prompt: string; cancelled: string }): Promise<void> {
524
if (process.env.CI) {
625
return;
726
}
8-
const confirm = await question(
9-
chalk.white(`\nDo you want to continue with this strategy? ${chalk.yellow(`[y/n]`)}: `)
10-
);
27+
const confirm = await question(`${config.prompt} ${chalk.yellow(`[y/n]`)}: `);
1128
const input = confirm.trim().toLowerCase();
1229
if (input !== 'y' && input !== 'yes') {
13-
console.log(chalk.red('🚫 Strategy not confirmed. Exiting...'));
30+
console.log(config.cancelled);
1431
process.exit(1);
1532
}
1633
}

release/core/release-notes/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { release_notes_flags_config } from '../../utils/flags-config';
99
import { SEMVER_VERSION } from '../../utils/channel';
1010
import { updateChangelogs } from './steps/update-changelogs';
1111
import { getChanges } from './steps/get-changes';
12+
import { confirmCommitChangelogs } from './steps/confirm-changelogs';
1213

1314
export async function executeReleaseNoteGeneration(args: string[]) {
1415
// remove the command itself from the list
@@ -50,5 +51,7 @@ export async function executeReleaseNoteGeneration(args: string[]) {
5051
// update all changelogs, including the primary changelog
5152
// and the changelogs for each package in changelogRoots
5253
// this will not commit the changes
53-
await updateChangelogs(fromTag, newChanges, config.full, strategy, packages, applied);
54+
const changedFiles = await updateChangelogs(fromTag, newChanges, config.full, strategy, packages, applied);
55+
56+
await confirmCommitChangelogs(changedFiles, config.full, packages);
5457
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { BunFile } from 'bun';
2+
import { confirm } from '../../publish/steps/confirm-strategy';
3+
import { exec } from '../../../utils/cmd';
4+
import { Package } from '../../../utils/package';
5+
import { SEMVER_VERSION } from '../../../utils/channel';
6+
import chalk from 'chalk';
7+
8+
export async function confirmCommitChangelogs(
9+
_changedFiles: BunFile[],
10+
config: Map<string, string | number | boolean | null>,
11+
packages: Map<string, Package>
12+
) {
13+
const dryRun = config.get('dry_run') as boolean;
14+
15+
if (config.get('commit') === false) {
16+
console.log(chalk.grey(`\t➠ Skipped commit of changelogs.`));
17+
return;
18+
}
19+
20+
try {
21+
await confirm({
22+
prompt: `Do you want to commit the changelogs?`,
23+
cancelled: `🚫 Commit of changelogs cancelled. Exiting...`,
24+
});
25+
} finally {
26+
if (dryRun) {
27+
// cleanup files because we're not actually committing
28+
await exec(['sh', '-c', `git add -A && git reset --hard HEAD`]);
29+
}
30+
}
31+
32+
if (!dryRun) {
33+
const newVersion = packages.get('root')!.pkgData.version as SEMVER_VERSION;
34+
await exec(['sh', '-c', `git add -A && git commit -m "chore: update changelogs for v${newVersion}"`]);
35+
36+
if (config.get('upstream')) {
37+
await exec(['sh', '-c', `git push`]);
38+
console.log(chalk.grey(`\t✅ pushed changelog commit to upstream.`));
39+
} else {
40+
console.log(chalk.grey(`\t➠ Skipped push of changelogs.`));
41+
}
42+
}
43+
}

release/core/release-notes/steps/update-changelogs.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppliedStrategy } from '../../publish/steps/generate-strategy';
33
import { Committers, Entry, LernaChangeset } from './get-changes';
44
import path from 'path';
55
import chalk from 'chalk';
6+
import { BunFile } from 'bun';
67

78
function findInsertionPoint(lines: string[], version: string) {
89
for (let i = 0; i < lines.length; i++) {
@@ -72,7 +73,7 @@ export async function updateChangelogs(
7273
strategy: STRATEGY,
7374
packages: Map<string, Package>,
7475
applied: AppliedStrategy
75-
) {
76+
): Promise<BunFile[]> {
7677
const file = Bun.file('./CHANGELOG.md');
7778
const mainChangelog = await file.text();
7879
const lines = mainChangelog.split('\n');
@@ -83,6 +84,7 @@ export async function updateChangelogs(
8384
lines.splice(insertionPoint, 0, ...newLines);
8485
await Bun.write(file, lines.join('\n'));
8586
console.log(`\t✅ Updated Primary Changelog`);
87+
const changedFiles = [file];
8688

8789
for (const [pkgName, changes] of Object.entries(newChanges.byPackage)) {
8890
if (pkgName === 'root') {
@@ -100,6 +102,7 @@ export async function updateChangelogs(
100102
const fromVersion = applied.all.get(pkgName)!.fromVersion;
101103
const fromTag = `v${fromVersion}`;
102104
const newLines = buildText(toTag, strategy, changes, newChanges.data[Committers]);
105+
changedFiles.push(changelogFile);
103106

104107
let changelogLines: string[] = [];
105108
if (!exists) {
@@ -124,4 +127,6 @@ export async function updateChangelogs(
124127
: `\t✅ Created ${chalk.cyan(pkg.pkgData.name)} Changelog`
125128
);
126129
}
130+
131+
return changedFiles;
127132
}

release/utils/flags-config.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,18 @@ export function merge<T>(...args: T[]): T {
185185
}
186186

187187
export const release_notes_flags_config: FlagConfig = merge(
188-
pick(publish_flags_config, ['help', 'increment', 'dry_run', 'dangerously_force', 'tag', 'channel']),
188+
pick(publish_flags_config, ['help', 'increment', 'dry_run', 'dangerously_force', 'tag', 'channel', 'upstream']),
189189
{
190+
commit: {
191+
name: 'Commit',
192+
flag: 'commit',
193+
flag_aliases: ['c'],
194+
flag_mispellings: ['cm', 'comit'],
195+
description: 'Whether to commit the changes to the changelogs',
196+
type: Boolean,
197+
examples: [],
198+
default_value: true,
199+
},
190200
from: {
191201
name: 'From Version',
192202
flag: 'from',
@@ -214,16 +224,6 @@ export const release_notes_flags_config: FlagConfig = merge(
214224
}
215225
},
216226
},
217-
pr: {
218-
name: 'Open a Pull Request',
219-
flag: 'pr',
220-
flag_aliases: ['p'],
221-
flag_mispellings: ['pullrequest', 'pull-request', 'issue', 'upstream', 'up', 'open'],
222-
description: 'Whether to open a pull request with the release notes',
223-
type: Boolean,
224-
examples: [],
225-
default_value: true,
226-
},
227227
}
228228
);
229229

release/utils/github.ts

-3
This file was deleted.

0 commit comments

Comments
 (0)