fix: make GitHub releases canonical for release-please (#295)
This commit is contained in:
29
src/release/config.ts
Normal file
29
src/release/config.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import path from "path"
|
||||
|
||||
type ReleasePleasePackageConfig = {
|
||||
"changelog-path"?: string
|
||||
"skip-changelog"?: boolean
|
||||
}
|
||||
|
||||
type ReleasePleaseConfig = {
|
||||
packages: Record<string, ReleasePleasePackageConfig>
|
||||
}
|
||||
|
||||
export function validateReleasePleaseConfig(config: ReleasePleaseConfig): string[] {
|
||||
const errors: string[] = []
|
||||
|
||||
for (const [packagePath, packageConfig] of Object.entries(config.packages)) {
|
||||
const changelogPath = packageConfig["changelog-path"]
|
||||
if (!changelogPath) continue
|
||||
|
||||
const normalized = path.posix.normalize(changelogPath)
|
||||
const segments = normalized.split("/")
|
||||
if (segments.includes("..")) {
|
||||
errors.push(
|
||||
`Package "${packagePath}" uses an unsupported changelog-path "${changelogPath}". release-please does not allow upward-relative paths like "../".`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
@@ -180,39 +180,3 @@ export async function syncReleaseMetadata(options: SyncOptions = {}): Promise<Me
|
||||
|
||||
return { updates }
|
||||
}
|
||||
|
||||
export async function updateRootChangelog(options: {
|
||||
root?: string
|
||||
entries: Array<{ component: ReleaseComponent; version: string; date: string; sections: Record<string, string[]> }>
|
||||
write?: boolean
|
||||
}): Promise<{ path: string; changed: boolean; content: string }> {
|
||||
const root = options.root ?? process.cwd()
|
||||
const changelogPath = path.join(root, "CHANGELOG.md")
|
||||
const existing = await readText(changelogPath)
|
||||
const renderedEntries = options.entries
|
||||
.map((entry) => renderChangelogEntry(entry.component, entry.version, entry.date, entry.sections))
|
||||
.join("\n\n")
|
||||
const next = `${existing.trimEnd()}\n\n${renderedEntries}\n`
|
||||
const changed = next !== existing
|
||||
if (options.write && changed) {
|
||||
await writeText(changelogPath, next)
|
||||
}
|
||||
return { path: changelogPath, changed, content: next }
|
||||
}
|
||||
|
||||
export function renderChangelogEntry(
|
||||
component: ReleaseComponent,
|
||||
version: string,
|
||||
date: string,
|
||||
sections: Record<string, string[]>,
|
||||
): string {
|
||||
const lines = [`## ${component} v${version} - ${date}`]
|
||||
for (const [section, items] of Object.entries(sections)) {
|
||||
if (items.length === 0) continue
|
||||
lines.push("", `### ${section}`)
|
||||
for (const item of items) {
|
||||
lines.push(`- ${item}`)
|
||||
}
|
||||
}
|
||||
return lines.join("\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user