Skip to content

Commit 730781e

Browse files
authored
Rework package selector, bump versions for subcomponents (#2013)
2 parents 9db0961 + 265e02b commit 730781e

File tree

4 files changed

+266
-62
lines changed

4 files changed

+266
-62
lines changed

automation/utils/bin/rui-prepare-release.ts

Lines changed: 81 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Jira } from "../src/jira";
2-
import { PackageListing, selectPackage } from "../src/monorepo";
1+
import { Jira, JiraVersion } from "../src/jira";
32
import chalk from "chalk";
43
import { prompt } from "enquirer";
5-
import { getNextVersion, writeVersion } from "../src/bump-version";
4+
import { bumpPackageJson, bumpXml, getNextVersion } from "../src/bump-version";
65
import { exec } from "../src/shell";
76
import { gh } from "../src/github";
7+
import { printGithubAuthHelp } from "../src/cli-utils";
8+
import { printPkgInformation, selectPackageV2 } from "../src/prepare-release-helpers";
89

910
async function main(): Promise<void> {
1011
try {
@@ -17,33 +18,32 @@ async function main(): Promise<void> {
1718
await gh.ensureAuth();
1819
console.log(chalk.green("✅ GitHub authentication verified"));
1920
} catch (error) {
20-
console.log(chalk.red(`❌ GitHub authentication failed: ${(error as Error).message}`));
21-
console.log(chalk.yellow("\n💡 First, make sure GitHub CLI is installed:"));
22-
console.log(chalk.cyan(" Download from: https://cli.github.com/"));
23-
console.log(chalk.cyan(" Or install via brew: brew install gh"));
24-
console.log(chalk.yellow("\n💡 Then authenticate with GitHub using one of these options:"));
25-
console.log(chalk.yellow(" 1. Set GITHUB_TOKEN environment variable:"));
26-
console.log(chalk.cyan(" export GITHUB_TOKEN=your_token_here"));
27-
console.log(chalk.yellow(" 2. Set GH_PAT environment variable:"));
28-
console.log(chalk.cyan(" export GH_PAT=your_token_here"));
29-
console.log(chalk.yellow(" 3. Use GitHub CLI to authenticate:"));
30-
console.log(chalk.cyan(" gh auth login"));
31-
console.log(chalk.yellow("\n Get a token at: https://github.com/settings/tokens"));
21+
printGithubAuthHelp((error as Error).message);
3222
process.exit(1);
3323
}
3424

3525
// Step 1: Initialize Jira client
36-
let jira: Jira;
26+
let jira: Jira | undefined;
3727
try {
3828
jira = await initializeJiraClient();
39-
} catch (error) {
40-
console.log(chalk.red(`❌ ${(error as Error).message}`));
41-
process.exit(1);
29+
} catch (_e) {
30+
// Ask user if they want to continue without it
31+
const { confirmSkipJira } = await prompt<{ confirmSkipJira: boolean }>({
32+
type: "confirm",
33+
name: "confirmSkipJira",
34+
message: `❓ Do you want to skip Jira? You won't be able to create Jira version automatically.`,
35+
initial: true
36+
});
37+
38+
if (!confirmSkipJira) {
39+
process.exit(1);
40+
}
4241
}
4342

4443
// Step 2: Select package and determine version
4544
console.log(chalk.bold("\n📋 STEP 2: Package Selection"));
46-
const { pkg, baseName, nextVersion, jiraVersionName, isVersionBumped } = await selectPackageAndVersion();
45+
const { selectedPackage, baseName, nextVersion, jiraVersionName, isVersionBumped } =
46+
await selectPackageAndVersion();
4747

4848
// Step 3: Check if Jira version exists
4949
console.log(chalk.bold("\n📋 STEP 3: Jira Version Setup"));
@@ -58,11 +58,28 @@ async function main(): Promise<void> {
5858

5959
// Step 4.1: Write versions to the files (if user chose to bump version)
6060
if (isVersionBumped) {
61-
await writeVersion(pkg, nextVersion);
62-
console.log(chalk.green(`✅ Updated ${baseName} to ${nextVersion}`));
61+
if (selectedPackage.type === "module") {
62+
bumpPackageJson(selectedPackage.path, nextVersion);
63+
console.log(chalk.green(`✅ Bumped ${chalk.bold(selectedPackage.info.name)} to ${nextVersion}`));
64+
for (const widget of selectedPackage.widgets) {
65+
await bumpXml(widget.path, nextVersion);
66+
bumpPackageJson(widget.path, nextVersion);
67+
console.log(chalk.green(`✅ Bumped ${chalk.bold(widget.info.name)} to ${nextVersion}`));
68+
}
69+
} else {
70+
bumpPackageJson(selectedPackage.path, nextVersion);
71+
await bumpXml(selectedPackage.path, nextVersion);
72+
console.log(chalk.green(`✅ Bumped ${chalk.bold(baseName)} to ${nextVersion}`));
73+
}
6374

6475
await exec(`git reset`, { stdio: "pipe" }); // Unstage all files
65-
await exec(`git add ${pkg.path}`, { stdio: "pipe" }); // Stage only the package
76+
await exec(`git add ${selectedPackage.path}`, { stdio: "pipe" }); // Stage only the package
77+
if (selectedPackage.type === "module") {
78+
// stage widgets as well
79+
for (const widget of selectedPackage.widgets) {
80+
await exec(`git add ${widget.path}`, { stdio: "pipe" }); // Stage only the package
81+
}
82+
}
6683

6784
// Step 4.2: Commit changes
6885
const { confirmCommit } = await prompt<{ confirmCommit: boolean }>({
@@ -101,10 +118,12 @@ async function main(): Promise<void> {
101118
console.log(chalk.green("✅ Branch pushed to GitHub"));
102119

103120
console.log(chalk.bold("\n📋 STEP 5: GitHub Release Workflow"));
104-
await triggerGitHubReleaseWorkflow(pkg.name, tmpBranchName);
121+
await triggerGitHubReleaseWorkflow(selectedPackage.info.name, tmpBranchName);
105122

106-
console.log(chalk.bold("\n📋 STEP 6: Jira Issue Management"));
107-
await manageIssuesForVersion(jira, jiraVersion.id, jiraVersionName);
123+
if (jira && jiraVersion) {
124+
console.log(chalk.bold("\n📋 STEP 6: Jira Issue Management"));
125+
await manageIssuesForVersion(jira, jiraVersion.id, jiraVersionName);
126+
}
108127

109128
console.log(chalk.cyan("\n🎉 Release preparation completed! 🎉"));
110129
console.log(chalk.cyan(` Package: ${baseName} v${nextVersion}`));
@@ -368,68 +387,69 @@ async function initializeJiraClient(): Promise<Jira> {
368387
// Initialize Jira client
369388
const jira = new Jira(projectKey, baseUrl, apiToken);
370389

371-
// Initialize Jira project data with retry mechanism
372-
let initialized = false;
373-
while (!initialized) {
374-
try {
375-
console.log("🔄 Initializing Jira project data...");
376-
await jira.initializeProjectData();
377-
console.log(chalk.green("✅ Jira project data initialized"));
378-
initialized = true;
379-
} catch (error) {
380-
console.error(chalk.red(`❌ Jira init failed: ${(error as Error).message}`));
381-
382-
const { retry } = await prompt<{ retry: boolean }>({
383-
type: "confirm",
384-
name: "retry",
385-
message: "❓ Retry Jira initialization?",
386-
initial: true
387-
});
388-
389-
if (!retry) {
390-
throw new Error("Cannot proceed without Jira initialization");
391-
}
392-
}
390+
try {
391+
console.log("🔄 Initializing Jira project data...");
392+
await jira.initializeProjectData();
393+
console.log(chalk.green("✅ Jira project data initialized"));
394+
} catch (error) {
395+
console.error(chalk.red(`❌ Jira init failed: ${(error as Error).message}`));
396+
throw new Error("Jira initialization failed");
393397
}
394398

395399
return jira;
396400
}
397401

398402
async function selectPackageAndVersion(): Promise<{
399-
pkg: PackageListing;
403+
selectedPackage: Awaited<ReturnType<typeof selectPackageV2>>;
400404
baseName: string;
401405
nextVersion: string;
402406
jiraVersionName: string;
403407
isVersionBumped: boolean;
404408
}> {
405-
const pkg = await selectPackage();
406-
const baseName = pkg.name.split("/").pop()!;
409+
const selectedPackage = await selectPackageV2();
407410

408-
console.log(`📦 Selected: ${chalk.blue(baseName)} (current: ${chalk.green(pkg.version)})`);
411+
if (selectedPackage.type === "widget") {
412+
console.log(`📦 Selected widget:`);
413+
} else {
414+
console.log(`📦 Selected module:`);
415+
}
416+
printPkgInformation(selectedPackage);
409417

410418
// Ask user if they want to bump the version before showing version selection dialog
411419
const { confirmBumpVersion } = await prompt<{ confirmBumpVersion: boolean }>({
412420
type: "confirm",
413421
name: "confirmBumpVersion",
414-
message: `❓ Do you want to bump ${baseName} from version ${chalk.green(pkg.version)}?`,
422+
message: `❓ Do you want to bump version for ${chalk.bold(selectedPackage.info.name)}?`,
415423
initial: true
416424
});
417425

418426
// Only call getNextVersion if user wants to bump version
419-
let nextVersion = pkg.version;
427+
let nextVersion = selectedPackage.info.version.format();
420428
if (confirmBumpVersion) {
421-
nextVersion = await getNextVersion(pkg.version);
429+
nextVersion = await getNextVersion(selectedPackage.info.version.format());
422430
console.log(`🔼 Next version: ${chalk.green(nextVersion)}`);
423431
} else {
424-
console.log(chalk.yellow(`⚠️ Version bump skipped. Keeping version ${chalk.green(pkg.version)}`));
432+
console.log(
433+
chalk.yellow(
434+
`⚠️ Version bump skipped. Keeping version ${chalk.green(selectedPackage.info.version.format())}`
435+
)
436+
);
425437
}
426438

427-
const jiraVersionName = `${baseName}-v${nextVersion}`;
439+
const jiraName = selectedPackage.info.name.split("/")[1]!;
440+
const jiraVersionName = `${jiraName}-v${nextVersion}`;
428441

429-
return { pkg, baseName, nextVersion, jiraVersionName, isVersionBumped: confirmBumpVersion };
442+
return { selectedPackage, baseName: jiraName, nextVersion, jiraVersionName, isVersionBumped: confirmBumpVersion };
430443
}
431444

432-
async function checkAndCreateJiraVersion(jira: Jira, jiraVersionName: string): Promise<any> {
445+
async function checkAndCreateJiraVersion(
446+
jira: Jira | undefined,
447+
jiraVersionName: string
448+
): Promise<JiraVersion | undefined> {
449+
if (!jira) {
450+
console.log(chalk.yellow(" ⚠️ Skipping jira version creation"));
451+
return undefined;
452+
}
433453
let jiraVersion = jira.findVersion(jiraVersionName);
434454
if (jiraVersion) {
435455
console.log(chalk.yellow(`⚠️ Jira version ${chalk.blue(jiraVersionName)} already exists`));
@@ -443,8 +463,8 @@ async function checkAndCreateJiraVersion(jira: Jira, jiraVersionName: string): P
443463
});
444464

445465
if (!createVersion) {
446-
console.log(chalk.red("❌ Process canceled"));
447-
process.exit(1);
466+
console.log(chalk.yellow(" ⚠️ Skipping jira version creation"));
467+
return undefined;
448468
}
449469

450470
// Create Jira version

automation/utils/src/cli-utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ora from "ora";
2+
import chalk from "chalk";
23

34
export async function oraPromise<T>(task: Promise<T>, msg: string): Promise<T> {
45
const spinner = ora(msg);
@@ -7,3 +8,18 @@ export async function oraPromise<T>(task: Promise<T>, msg: string): Promise<T> {
78
spinner.stop();
89
return r;
910
}
11+
12+
export function printGithubAuthHelp(error: string): void {
13+
console.log(chalk.red(`❌ GitHub authentication failed: ${error}`));
14+
console.log(chalk.yellow("\n💡 First, make sure GitHub CLI is installed:"));
15+
console.log(chalk.cyan(" Download from: https://cli.github.com/"));
16+
console.log(chalk.cyan(" Or install via brew: brew install gh"));
17+
console.log(chalk.yellow("\n💡 Then authenticate with GitHub using one of these options:"));
18+
console.log(chalk.yellow(" 1. Set GITHUB_TOKEN environment variable:"));
19+
console.log(chalk.cyan(" export GITHUB_TOKEN=your_token_here"));
20+
console.log(chalk.yellow(" 2. Set GH_PAT environment variable:"));
21+
console.log(chalk.cyan(" export GH_PAT=your_token_here"));
22+
console.log(chalk.yellow(" 3. Use GitHub CLI to authenticate:"));
23+
console.log(chalk.cyan(" gh auth login"));
24+
console.log(chalk.yellow("\n Get a token at: https://github.com/settings/tokens"));
25+
}

automation/utils/src/jira.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nodefetch, { RequestInit } from "node-fetch";
22

3-
interface JiraVersion {
3+
export interface JiraVersion {
44
id: string;
55
name: string;
66
archived: boolean;

0 commit comments

Comments
 (0)