Skip to content

Commit c6b8342

Browse files
committed
chore: improve release script
1 parent 4fd2e30 commit c6b8342

File tree

4 files changed

+64
-35
lines changed

4 files changed

+64
-35
lines changed

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ async function main(): Promise<void> {
1010
try {
1111
console.log(chalk.bold.cyan("\n🚀 RELEASE PREPARATION WIZARD 🚀\n"));
1212

13-
// Check for GitHub token
14-
const githubToken = process.env.GH_PAT;
15-
if (!githubToken) {
16-
console.warn(chalk.yellow("⚠️ GH_PAT environment variable not set"));
17-
console.warn(chalk.yellow(" GitHub workflow will need manual triggering"));
13+
console.log(chalk.bold("📋 STEP 1: Initialize Jira and GitHub"));
14+
15+
// Check GitHub authentication
16+
try {
17+
await gh.ensureAuth();
18+
console.log(chalk.green("✅ GitHub authentication verified"));
19+
} 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"));
32+
process.exit(1);
1833
}
1934

2035
// Step 1: Initialize Jira client
21-
console.log(chalk.bold("📋 STEP 1: Initialize Jira"));
2236
let jira: Jira;
2337
try {
2438
jira = await initializeJiraClient();
@@ -87,7 +101,7 @@ async function main(): Promise<void> {
87101
console.log(chalk.green("✅ Branch pushed to GitHub"));
88102

89103
console.log(chalk.bold("\n📋 STEP 5: GitHub Release Workflow"));
90-
await triggerGitHubReleaseWorkflow(pkg.name, tmpBranchName, githubToken);
104+
await triggerGitHubReleaseWorkflow(pkg.name, tmpBranchName);
91105

92106
console.log(chalk.bold("\n📋 STEP 6: Jira Issue Management"));
93107
await manageIssuesForVersion(jira, jiraVersion.id, jiraVersionName);
@@ -229,29 +243,21 @@ async function manageIssuesForVersion(jira: Jira, versionId: string, versionName
229243
}
230244
}
231245

232-
async function triggerGitHubReleaseWorkflow(
233-
packageName: string,
234-
branchName: string,
235-
githubToken?: string
236-
): Promise<void> {
237-
if (githubToken) {
238-
const { triggerWorkflow } = await prompt<{ triggerWorkflow: boolean }>({
239-
type: "confirm",
240-
name: "triggerWorkflow",
241-
message: "❓ Trigger GitHub release workflow now?",
242-
initial: true
243-
});
246+
async function triggerGitHubReleaseWorkflow(packageName: string, branchName: string): Promise<void> {
247+
const { triggerWorkflow } = await prompt<{ triggerWorkflow: boolean }>({
248+
type: "confirm",
249+
name: "triggerWorkflow",
250+
message: "❓ Trigger GitHub release workflow now?",
251+
initial: true
252+
});
244253

245-
if (triggerWorkflow) {
246-
console.log(chalk.blue("🔄 Triggering GitHub release workflow..."));
247-
try {
248-
await gh.triggerCreateReleaseWorkflow(packageName, branchName);
249-
console.log(chalk.green("✅ GitHub Release Workflow triggered"));
250-
} catch (error) {
251-
console.error(chalk.red(`❌ Failed to trigger workflow: ${(error as Error).message}`));
252-
showManualTriggerInstructions(packageName, branchName);
253-
}
254-
} else {
254+
if (triggerWorkflow) {
255+
console.log(chalk.blue("🔄 Triggering GitHub release workflow..."));
256+
try {
257+
await gh.triggerCreateReleaseWorkflow(packageName, branchName);
258+
console.log(chalk.green("✅ GitHub Release Workflow triggered"));
259+
} catch (error) {
260+
console.error(chalk.red(`❌ Failed to trigger workflow: ${(error as Error).message}`));
255261
showManualTriggerInstructions(packageName, branchName);
256262
}
257263
} else {
@@ -347,7 +353,6 @@ async function createReleaseBranch(packageName: string, version: string): Promis
347353
}
348354

349355
async function initializeJiraClient(): Promise<Jira> {
350-
console.log(chalk.bold("🔍 Checking Jira environment variables"));
351356
const projectKey = process.env.JIRA_PROJECT_KEY;
352357
const baseUrl = process.env.JIRA_BASE_URL;
353358
const apiToken = process.env.JIRA_API_TOKEN;
@@ -358,6 +363,7 @@ async function initializeJiraClient(): Promise<Jira> {
358363
console.log(chalk.dim(" export JIRA_PROJECT_KEY=WEB"));
359364
console.log(chalk.dim(" export JIRA_BASE_URL=https://your-company.atlassian.net"));
360365
console.log(chalk.dim(" export [email protected]:ATATT3xFfGF0..."));
366+
console.log(chalk.dim(" Get your API token at: https://id.atlassian.com/manage-profile/security/api-tokens"));
361367
throw new Error("Missing Jira environment variables");
362368
}
363369

automation/utils/src/github.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,33 @@ export class GitHub {
3030
authSet = false;
3131
tmpPrefix = "gh-";
3232

33-
private async ensureAuth(): Promise<void> {
33+
async ensureAuth(): Promise<void> {
3434
if (!this.authSet) {
35-
await exec(`echo "${process.env.GH_PAT}" | gh auth login --with-token`);
35+
if (process.env.GITHUB_TOKEN) {
36+
// when using GITHUB_TOKEN, gh will automatically use it
37+
} else if (process.env.GH_PAT) {
38+
await exec(`echo "${process.env.GH_PAT}" | gh auth login --with-token`);
39+
} else {
40+
// No environment variables set, check if already authenticated
41+
if (!(await this.isAuthenticated())) {
42+
throw new Error(
43+
"GitHub CLI is not authenticated. Please set GITHUB_TOKEN or GH_PAT environment variable, or run 'gh auth login'."
44+
);
45+
}
46+
}
47+
48+
this.authSet = true;
49+
}
50+
}
51+
52+
private async isAuthenticated(): Promise<boolean> {
53+
try {
54+
// Try to run 'gh auth status' to check if authenticated
55+
await exec("gh auth status", { stdio: "pipe" });
56+
return true;
57+
} catch (error) {
58+
// If the command fails, the user is not authenticated
59+
return false;
3660
}
3761
}
3862

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"create-translation": "turbo run create-translation",
1717
"publish-marketplace": "turbo run publish-marketplace",
1818
"version": "pnpm --filter @mendix/automation-utils run version",
19-
"changelog": "pnpm --filter @mendix/automation-utils run changelog"
19+
"changelog": "pnpm --filter @mendix/automation-utils run changelog",
20+
"prepare-release": "pnpm --filter @mendix/automation-utils run prepare-release"
2021
},
2122
"devDependencies": {
2223
"husky": "^8.0.3",
@@ -53,7 +54,6 @@
5354
"jest-environment-jsdom": "^29.7.0",
5455
"[email protected]": ">=1.0.2",
5556
"[email protected]": ">=1.0.2",
56-
"@codemirror/view": "^6.34.2",
5757
"enzyme>cheerio": "1.0.0-rc.10",
5858
"ts-node": "10.9.2",
5959
"mendix": "^10.16"

pnpm-lock.yaml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)