Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 37 additions & 31 deletions automation/utils/bin/rui-prepare-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ async function main(): Promise<void> {
try {
console.log(chalk.bold.cyan("\n🚀 RELEASE PREPARATION WIZARD 🚀\n"));

// Check for GitHub token
const githubToken = process.env.GH_PAT;
if (!githubToken) {
console.warn(chalk.yellow("⚠️ GH_PAT environment variable not set"));
console.warn(chalk.yellow(" GitHub workflow will need manual triggering"));
console.log(chalk.bold("📋 STEP 1: Initialize Jira and GitHub"));

// Check GitHub authentication
try {
await gh.ensureAuth();
console.log(chalk.green("✅ GitHub authentication verified"));
} catch (error) {
console.log(chalk.red(`❌ GitHub authentication failed: ${(error as Error).message}`));
console.log(chalk.yellow("\n💡 First, make sure GitHub CLI is installed:"));
console.log(chalk.cyan(" Download from: https://cli.github.com/"));
console.log(chalk.cyan(" Or install via brew: brew install gh"));
console.log(chalk.yellow("\n💡 Then authenticate with GitHub using one of these options:"));
console.log(chalk.yellow(" 1. Set GITHUB_TOKEN environment variable:"));
console.log(chalk.cyan(" export GITHUB_TOKEN=your_token_here"));
console.log(chalk.yellow(" 2. Set GH_PAT environment variable:"));
console.log(chalk.cyan(" export GH_PAT=your_token_here"));
console.log(chalk.yellow(" 3. Use GitHub CLI to authenticate:"));
console.log(chalk.cyan(" gh auth login"));
console.log(chalk.yellow("\n Get a token at: https://github.com/settings/tokens"));
process.exit(1);
}

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

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

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

async function triggerGitHubReleaseWorkflow(
packageName: string,
branchName: string,
githubToken?: string
): Promise<void> {
if (githubToken) {
const { triggerWorkflow } = await prompt<{ triggerWorkflow: boolean }>({
type: "confirm",
name: "triggerWorkflow",
message: "❓ Trigger GitHub release workflow now?",
initial: true
});
async function triggerGitHubReleaseWorkflow(packageName: string, branchName: string): Promise<void> {
const { triggerWorkflow } = await prompt<{ triggerWorkflow: boolean }>({
type: "confirm",
name: "triggerWorkflow",
message: "❓ Trigger GitHub release workflow now?",
initial: true
});

if (triggerWorkflow) {
console.log(chalk.blue("🔄 Triggering GitHub release workflow..."));
try {
await gh.triggerCreateReleaseWorkflow(packageName, branchName);
console.log(chalk.green("✅ GitHub Release Workflow triggered"));
} catch (error) {
console.error(chalk.red(`❌ Failed to trigger workflow: ${(error as Error).message}`));
showManualTriggerInstructions(packageName, branchName);
}
} else {
if (triggerWorkflow) {
console.log(chalk.blue("🔄 Triggering GitHub release workflow..."));
try {
await gh.triggerCreateReleaseWorkflow(packageName, branchName);
console.log(chalk.green("✅ GitHub Release Workflow triggered"));
} catch (error) {
console.error(chalk.red(`❌ Failed to trigger workflow: ${(error as Error).message}`));
showManualTriggerInstructions(packageName, branchName);
}
} else {
Expand All @@ -260,7 +266,7 @@ async function triggerGitHubReleaseWorkflow(
}

async function createReleaseBranch(packageName: string, version: string): Promise<string> {
const tmpBranchName = `tmp-release/${packageName}-v${version}`;
const tmpBranchName = `tmp/${packageName}-v${version}`;

let branchToUse = tmpBranchName;
let branchesAreReady = false;
Expand Down Expand Up @@ -347,7 +353,6 @@ async function createReleaseBranch(packageName: string, version: string): Promis
}

async function initializeJiraClient(): Promise<Jira> {
console.log(chalk.bold("🔍 Checking Jira environment variables"));
const projectKey = process.env.JIRA_PROJECT_KEY;
const baseUrl = process.env.JIRA_BASE_URL;
const apiToken = process.env.JIRA_API_TOKEN;
Expand All @@ -358,6 +363,7 @@ async function initializeJiraClient(): Promise<Jira> {
console.log(chalk.dim(" export JIRA_PROJECT_KEY=WEB"));
console.log(chalk.dim(" export JIRA_BASE_URL=https://your-company.atlassian.net"));
console.log(chalk.dim(" export JIRA_API_TOKEN=username@your-company.com:ATATT3xFfGF0..."));
console.log(chalk.dim(" Get your API token at: https://id.atlassian.com/manage-profile/security/api-tokens"));
throw new Error("Missing Jira environment variables");
}

Expand Down
44 changes: 27 additions & 17 deletions automation/utils/docker/mxbuild.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
FROM mono:6.12
FROM --platform=$BUILDPLATFORM eclipse-temurin:17-jdk-jammy

ARG MENDIX_VERSION
ARG BUILDPLATFORM

SHELL ["/bin/bash", "-c"]
RUN \
echo "Installing Java..." && \
apt-get -qq update && \
apt-get -qq install -y wget && \
wget -q https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz -O /tmp/openjdk.tar.gz && \
mkdir /usr/lib/jvm && \
tar xfz /tmp/openjdk.tar.gz --directory /usr/lib/jvm && \
rm /tmp/openjdk.tar.gz && \
\
echo "Downloading mxbuild ${MENDIX_VERSION}..." && \
wget -q https://cdn.mendix.com/runtime/mxbuild-${MENDIX_VERSION}.tar.gz -O /tmp/mxbuild.tar.gz && \
mkdir /tmp/mxbuild && \
tar xfz /tmp/mxbuild.tar.gz --directory /tmp/mxbuild && \
rm /tmp/mxbuild.tar.gz && \
echo "Downloading mxbuild ${MENDIX_VERSION} and docker building for ${BUILDPLATFORM}..." \
&& case "${BUILDPLATFORM}" in \
linux/arm64) \
BINARY_URL="https://cdn.mendix.com/runtime/arm64-mxbuild-${MENDIX_VERSION}.tar.gz"; \
;; \
linux/amd64) \
BINARY_URL="https://cdn.mendix.com/runtime/mxbuild-${MENDIX_VERSION}.tar.gz"; \
;; \
*) \
echo "Unsupported architecture: ${BUILDPLATFORM}" >&2; \
exit 1; \
;; \
esac \
&& echo "Downloading from: ${BINARY_URL}" \
&& wget -q "${BINARY_URL}" -O /tmp/mxbuild.tar.gz \
&& mkdir /tmp/mxbuild \
&& tar xfz /tmp/mxbuild.tar.gz --directory /tmp/mxbuild \
&& rm /tmp/mxbuild.tar.gz && \
\
apt-get -qq remove -y wget && \
apt-get update -qqy && \
apt-get install -qqy libicu70 libgdiplus && \
apt-get -qqy remove --auto-remove wget && \
apt-get clean && \
\
echo "#!/bin/bash -x" >/bin/mxbuild && \
echo "mono /tmp/mxbuild/modeler/mxbuild.exe --java-home=/usr/lib/jvm/jdk-11.0.2 --java-exe-path=/usr/lib/jvm/jdk-11.0.2/bin/java \$@" >>/bin/mxbuild && \
echo "/tmp/mxbuild/modeler/mxbuild --java-home=/opt/java/openjdk --java-exe-path=/opt/java/openjdk/bin/java \$@" >>/bin/mxbuild && \
chmod +x /bin/mxbuild && \
\
echo "#!/bin/bash -x" >/bin/mx && \
echo "mono /tmp/mxbuild/modeler/mx.exe \$@" >>/bin/mx && \
echo "/tmp/mxbuild/modeler/mx \$@" >>/bin/mx && \
chmod +x /bin/mx
38 changes: 0 additions & 38 deletions automation/utils/docker/mxbuildMx10.Dockerfile

This file was deleted.

28 changes: 26 additions & 2 deletions automation/utils/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,33 @@ export class GitHub {
authSet = false;
tmpPrefix = "gh-";

private async ensureAuth(): Promise<void> {
async ensureAuth(): Promise<void> {
if (!this.authSet) {
await exec(`echo "${process.env.GH_PAT}" | gh auth login --with-token`);
if (process.env.GITHUB_TOKEN) {
// when using GITHUB_TOKEN, gh will automatically use it
} else if (process.env.GH_PAT) {
await exec(`echo "${process.env.GH_PAT}" | gh auth login --with-token`);
} else {
// No environment variables set, check if already authenticated
if (!(await this.isAuthenticated())) {
throw new Error(
"GitHub CLI is not authenticated. Please set GITHUB_TOKEN or GH_PAT environment variable, or run 'gh auth login'."
);
}
}

this.authSet = true;
}
}

private async isAuthenticated(): Promise<boolean> {
try {
// Try to run 'gh auth status' to check if authenticated
await exec("gh auth status", { stdio: "pipe" });
return true;
} catch (error) {
// If the command fails, the user is not authenticated
return false;
}
}

Expand Down
12 changes: 3 additions & 9 deletions automation/utils/src/mpk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ async function ensureMxBuildDockerImageExists(mendixVersion: Version): Promise<v
const existingImages = (await exec(`docker image ls -q mxbuild:${version}`, { stdio: "pipe" })).stdout.trim();
if (!existingImages) {
console.log(`Creating new mxbuild:${version} docker image...`);
const versionMajor = mendixVersion.major;
const dockerfilePath =
versionMajor < 10
? join(__dirname, "../docker/mxbuild.Dockerfile")
: join(__dirname, "../docker/mxbuildMx10.Dockerfile");
const dockerfilePath = join(__dirname, "../docker/mxbuild.Dockerfile");
await exec(
`docker build -f ${dockerfilePath} ` +
`--build-arg MENDIX_VERSION=${version} ` +
Expand Down Expand Up @@ -45,10 +41,8 @@ export async function createModuleMpkInDocker(
"&&",

// and create module
versionMajor < 10 ? "mono" : "",
versionMajor >= 10
? "/tmp/mxbuild/modeler/mx create-module-package"
: "/tmp/mxbuild/modeler/mxutil.exe create-module-package",
versionMajor < 10 ? "/tmp/mxbuild/modeler/mxutil" : "/tmp/mxbuild/modeler/mx",
"create-module-package",
excludeFilesRegExp ? `--exclude-files='${excludeFilesRegExp}'` : "",
`/source/${projectFile}`,
moduleName
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"publish-marketplace": "turbo run publish-marketplace",
"version": "pnpm --filter @mendix/automation-utils run version",
"changelog": "pnpm --filter @mendix/automation-utils run changelog",
"prepare-release": "pnpm --filter @mendix/automation-utils run prepare-release",
"postinstall": "turbo run agent-rules"
},
"devDependencies": {
Expand Down
Loading