Skip to content

Commit

Permalink
chore(release-manager): get package name for workspace commands (#5562)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Sep 23, 2022
1 parent 578ed5e commit 00a3693
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions scripts/release-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

const { Octokit } = require('@octokit/rest')
const semver = require('semver')
const mapWorkspaces = require('@npmcli/map-workspaces')
const { join } = require('path')

const ROOT = process.cwd()
const pkg = require(join(ROOT, 'package.json'))

const log = (...logs) => console.error('LOG', ...logs)

Expand Down Expand Up @@ -33,7 +38,7 @@ const getReleaseProcess = async () => {
[Symbol.split] (str) {
const [, ...matches] = str.split(RELEASE_LIST_ITEM)
log(`Found ${matches.length} release items`)
return matches.map((m, i) => `- [ ] <STEP_INDEX>. ${m}`.trim())
return matches.map((m) => `- [ ] <STEP_INDEX>. ${m}`.trim())
},
})
}
Expand All @@ -43,18 +48,26 @@ const getPrReleases = async (pr) => {
const MONO_VERSIONS = /<details><summary>(?:(.*?):\s)?(.*?)<\/summary>/
const ROOT_VERSION = /\n##\s\[(.*?)\]/

const workspaces = [...await mapWorkspaces({ pkg: pkg, cwd: ROOT })].reduce((acc, [k]) => {
const wsComponentName = k.startsWith('@') ? k.split('/')[1] : k
acc[wsComponentName] = k
return acc
}, {})

const getReleaseInfo = ({ name, version: rawVersion }) => {
const version = semver.parse(rawVersion)
const prerelease = !!version.prerelease.length
const tag = `${name ? `${name}-` : ''}v${rawVersion}`
const workspace = workspaces[name]

return {
name,
tag,
prerelease,
version: rawVersion,
major: version.major,
url: `https://github.com/${pr.base.repo.full_name}/releases/tag/${tag}`,
flags: name ? `-w ${name} ${prerelease ? `--tag prerelease` : ''}`.trim() : '',
flags: name ? `-w ${workspace} ${prerelease ? `--tag prerelease` : ''}`.trim() : '',
}
}

Expand All @@ -79,10 +92,10 @@ const getPrReleases = async (pr) => {
const release = getReleaseInfo({ name, version })

if (!name) {
log('Found root', release.tag)
log('Found root', release)
acc[0] = release
} else {
log('Found workspace', release.tag)
log('Found workspace', release)
acc[1].push(release)
}

Expand Down

0 comments on commit 00a3693

Please sign in to comment.