Skip to content

Commit

Permalink
Merge branch 'main' of github.com:balazsorban44/monorepo-release
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Jan 27, 2024
2 parents ce5d150 + 30fc21a commit ecafc4f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
50 changes: 40 additions & 10 deletions packages/monorepo-release/src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,39 @@ export async function analyze(config: Config): Promise<PackageToRelease[]> {
bugfixes: [],
breaking: [],
// List dependency commits under the dependent's "other" category
other: overrideScope([...pkg.features, ...pkg.bugfixes], pkgName),
other: getDependencyMessage(
[...pkg.features, ...pkg.bugfixes],
pkgName,
),
dependents: [],
},
)
}

const result = Array.from(packagesToRelease.values()).filter(
(p) => !config.ignorePackages.includes(p.name),
const { ignored, toRelease } = Array.from(packagesToRelease.values()).reduce(
(acc, p) => {
if (config.ignorePackages.includes(p.name)) acc.ignored.push(p)
else acc.toRelease.push(p)
return acc
},
{ ignored: [] as PackageToRelease[], toRelease: [] as PackageToRelease[] },
)

if (config.peek) {
log.peekInfo(
"Following packages can be released:\n",
...result.map(
`Following packages are ignored from releasing:\n`,
...ignored.map((p) => ` - ${bold(p.name)}`),
)
log.peekInfo(
"\nFollowing packages can be released:\n",
...toRelease.map(
(p) => ` - ${bold(p.name)}: ${p.oldVersion} -> ${p.newVersion}`,
),
)
exit()
}

return result
return toRelease
}

function addToPackagesToRelease(
Expand Down Expand Up @@ -269,9 +281,27 @@ function addToPackagesToRelease(
packagesToRelease.set(pkgName, pkgToRelease)
}

function overrideScope(commits: Commit[], scope: string): Commit[] {
return commits.map((commit) => {
commit.parsed.scope = scope
return commit
function getDependencyMessage(commits: Commit[], scope: string): Commit[] {
const sorted = commits.sort((a, b) => {
const aDate = new Date(a.committer.date)
const bDate = new Date(b.committer.date)
return aDate.getTime() - bDate.getTime()
})

// const first = sorted[0].commit.short
const last = sorted[sorted.length - 1].commit.short
const body = ""
// const body = ` ([compare changes](https://github.com/user/repository/compare/${first}..${last}))`
// TODO: Instead of last commit, try to get a link to the dependency's release notes
const short = last
const subject = `dependency update`
const type = "chore"
const raw = `${type}(${scope}): ${subject}`
return [
{
body,
commit: { short },
parsed: { type, subject, scope, header: raw, raw },
} as any,
]
}
9 changes: 5 additions & 4 deletions packages/monorepo-release/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { defaultConfig } from "./config.js"
import { type Config, defaultConfig } from "./config.js"
import { shouldSkip } from "./skip.js"
import { analyze } from "./analyze.js"
import { publish } from "./publish.js"
import { log } from "./utils.js"
import { bold } from "yoctocolors"

const userConfig = {} // TODO: Allow user config
const config = { ...defaultConfig, ...userConfig }
// TODO: Allow user config
const userConfig: Partial<Config> = {}
const config = { ...defaultConfig, ...userConfig } satisfies Config

const endMsg = bold("Done")

Expand Down Expand Up @@ -36,7 +37,7 @@ if (config.dryRun) {
if (!process.env.GITHUB_TOKEN) throw new Error("GITHUB_TOKEN is not set")
}

const packages = await analyze(defaultConfig)
const packages = await analyze(config)

log.debug(
"Packages to release:",
Expand Down

0 comments on commit ecafc4f

Please sign in to comment.