From f93648a5dfdf2a5ae335281ca91bdb41d403e37e Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 17 Aug 2023 14:42:20 -0300 Subject: [PATCH] chore(release): add engine versions to release (#30021) --- .changeset/moody-comics-cheat.md | 5 +++ .../release-action/src/bumpNextVersion.ts | 4 +- packages/release-action/src/getMetadata.ts | 41 +++++++++++++++++++ packages/release-action/src/publishRelease.ts | 4 +- packages/release-action/src/utils.ts | 16 ++++++++ 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 .changeset/moody-comics-cheat.md create mode 100644 packages/release-action/src/getMetadata.ts diff --git a/.changeset/moody-comics-cheat.md b/.changeset/moody-comics-cheat.md new file mode 100644 index 000000000000..b8b372306d0e --- /dev/null +++ b/.changeset/moody-comics-cheat.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/release-action': minor +--- + +Add back "Engine Versions" to the release notes diff --git a/packages/release-action/src/bumpNextVersion.ts b/packages/release-action/src/bumpNextVersion.ts index fb4e535c4a48..88c6df8d8d24 100644 --- a/packages/release-action/src/bumpNextVersion.ts +++ b/packages/release-action/src/bumpNextVersion.ts @@ -9,7 +9,7 @@ import { createNpmFile } from './createNpmFile'; import { fixWorkspaceVersionsBeforePublish } from './fixWorkspaceVersionsBeforePublish'; import { commitChanges, createBranch, createTag, pushNewBranch } from './gitUtils'; import { setupOctokit } from './setupOctokit'; -import { getChangelogEntry, bumpFileVersions, readPackageJson } from './utils'; +import { getChangelogEntry, bumpFileVersions, readPackageJson, getEngineVersionsMd } from './utils'; export async function bumpNextVersion({ githubToken, @@ -49,7 +49,7 @@ export async function bumpNextVersion({ throw new Error('Could not find changelog entry for version newVersion'); } - const prBody = changelogEntry.content; + const prBody = (await getEngineVersionsMd(cwd)) + changelogEntry.content; const finalVersion = newVersion.split('-')[0]; diff --git a/packages/release-action/src/getMetadata.ts b/packages/release-action/src/getMetadata.ts new file mode 100644 index 000000000000..3c677b8e7774 --- /dev/null +++ b/packages/release-action/src/getMetadata.ts @@ -0,0 +1,41 @@ +import { readFile } from 'fs/promises'; +import path from 'path'; + +import { getExecOutput } from '@actions/exec'; + +import { readPackageJson } from './utils'; + +export async function getMongoVersion(cwd: string) { + try { + const workflows = await readFile(path.join(cwd, '.github/workflows/ci.yml'), 'utf8'); + + const mongoMatch = workflows.match(/compatibleMongoVersions\\": \[([^\]]+)\]/); + if (!mongoMatch) { + return []; + } + + return mongoMatch[1].replace(/["'\\ ]/g, '').split(','); + } catch (e) { + console.error(e); + } + return []; +} + +export async function getNodeNpmVersions(cwd: string): Promise<{ node: string; yarn: string; npm: string }> { + const packageJson = await readPackageJson(cwd); + + return packageJson.engines; +} + +export async function getAppsEngineVersion() { + try { + const result = await getExecOutput('yarn why @rocket.chat/apps-engine --json'); + + const match = result.stdout.match(/"@rocket\.chat\/meteor@workspace:apps\/meteor".*"@rocket\.chat\/apps\-engine@[^#]+#npm:([^"]+)"/); + if (match) { + return match[1]; + } + } catch (e) { + console.error(e); + } +} diff --git a/packages/release-action/src/publishRelease.ts b/packages/release-action/src/publishRelease.ts index bcfb7ee95781..08791bbfeff9 100644 --- a/packages/release-action/src/publishRelease.ts +++ b/packages/release-action/src/publishRelease.ts @@ -9,7 +9,7 @@ import { createNpmFile } from './createNpmFile'; import { fixWorkspaceVersionsBeforePublish } from './fixWorkspaceVersionsBeforePublish'; import { checkoutBranch, commitChanges, createTag, getCurrentBranch, mergeBranch, pushChanges } from './gitUtils'; import { setupOctokit } from './setupOctokit'; -import { bumpFileVersions, createBumpFile, getChangelogEntry, readPackageJson } from './utils'; +import { bumpFileVersions, createBumpFile, getChangelogEntry, getEngineVersionsMd, readPackageJson } from './utils'; export async function publishRelease({ githubToken, @@ -73,7 +73,7 @@ export async function publishRelease({ throw new Error('Could not find changelog entry for version newVersion'); } - const releaseBody = changelogEntry.content; + const releaseBody = (await getEngineVersionsMd(cwd)) + changelogEntry.content; core.info('update version in all files to new'); await bumpFileVersions(cwd, currentVersion, newVersion); diff --git a/packages/release-action/src/utils.ts b/packages/release-action/src/utils.ts index 6ca9486e0b6b..2501ae859339 100644 --- a/packages/release-action/src/utils.ts +++ b/packages/release-action/src/utils.ts @@ -6,6 +6,8 @@ import remarkParse from 'remark-parse'; import remarkStringify from 'remark-stringify'; import unified from 'unified'; +import { getAppsEngineVersion, getMongoVersion, getNodeNpmVersions } from './getMetadata'; + export const BumpLevels = { dep: 0, patch: 1, @@ -103,3 +105,17 @@ Bump ${pkgName} version. await writeFile(filePath, data, 'utf8'); } + +export async function getEngineVersionsMd(cwd: string) { + const { node } = await getNodeNpmVersions(cwd); + const appsEngine = await getAppsEngineVersion(); + const mongo = await getMongoVersion(cwd); + + return `### Engine versions + +- Node: \`${node}\` +- MongoDB: \`${mongo.join(', ')}\` +- Apps-Engine: \`${appsEngine}\` + +`; +}