-
Notifications
You must be signed in to change notification settings - Fork 21
feat(scripts): allow subset release and major #3174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,18 +208,37 @@ export function getNextVersion(current: string, releaseType: semver.ReleaseType | |
export async function decideReleaseStrategy({ | ||
versions, | ||
commits, | ||
languages, | ||
major, | ||
}: { | ||
versions: VersionsBeforeBump; | ||
commits: PassedCommit[]; | ||
languages: Language[]; | ||
major?: boolean; | ||
}): Promise<Versions> { | ||
const versionsToPublish: Versions = {}; | ||
|
||
for (const [lang, version] of Object.entries(versions)) { | ||
const currentVersion = versions[lang].current; | ||
|
||
if (!languages.includes(lang as Language)) { | ||
console.log(`${lang} is not in the given language list, skipping release`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this console log is interesting for debug mode, but in regular use it would be more interesting to log only the chosen languages There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the release script is pretty verbose which I believe is nice as it's a process that can fail in many ways :/ I'm fine with keeping the log, wdyt? |
||
|
||
versionsToPublish[lang] = { | ||
...version, | ||
noCommit: true, | ||
releaseType: null, | ||
skipRelease: true, | ||
next: getNextVersion(currentVersion, null), | ||
}; | ||
|
||
continue; | ||
} | ||
|
||
const commitsPerLang = commits.filter( | ||
(commit) => commit.scope === lang || COMMON_SCOPES.includes(commit.scope), | ||
); | ||
|
||
const currentVersion = versions[lang].current; | ||
let nbGitDiff = await getNbGitDiff({ | ||
branch: await getLastReleasedTag(), | ||
head: null, | ||
|
@@ -233,7 +252,7 @@ export async function decideReleaseStrategy({ | |
nbGitDiff = 1; | ||
} | ||
|
||
if (nbGitDiff === 0 || commitsPerLang.length === 0) { | ||
if (!major && (nbGitDiff === 0 || commitsPerLang.length === 0)) { | ||
versionsToPublish[lang] = { | ||
...version, | ||
noCommit: true, | ||
|
@@ -253,47 +272,33 @@ export async function decideReleaseStrategy({ | |
continue; | ||
} | ||
|
||
// snapshots should not be bumped as prerelease | ||
if (semver.prerelease(currentVersion) && !currentVersion.endsWith('-SNAPSHOT')) { | ||
// if version is like 0.1.2-beta.1, it increases to 0.1.2-beta.2, even if there's a breaking change. | ||
versionsToPublish[lang] = { | ||
...version, | ||
releaseType: 'prerelease', | ||
next: getNextVersion(currentVersion, 'prerelease'), | ||
}; | ||
|
||
continue; | ||
} | ||
|
||
if (commitsPerLang.some((commit) => commit.message.includes('BREAKING CHANGE'))) { | ||
versionsToPublish[lang] = { | ||
...version, | ||
releaseType: 'major', | ||
next: getNextVersion(currentVersion, 'major'), | ||
}; | ||
|
||
continue; | ||
} | ||
|
||
let releaseType: semver.ReleaseType = 'patch'; | ||
let skipRelease = false; | ||
const commitTypes = new Set(commitsPerLang.map(({ type }) => type)); | ||
if (commitTypes.has('feat')) { | ||
versionsToPublish[lang] = { | ||
...version, | ||
releaseType: 'minor', | ||
next: getNextVersion(currentVersion, 'minor'), | ||
}; | ||
|
||
continue; | ||
switch (true) { | ||
case major || commitsPerLang.some((commit) => commit.message.includes('BREAKING CHANGE')): | ||
releaseType = 'major'; | ||
break; | ||
case semver.prerelease(currentVersion) && !currentVersion.endsWith('-SNAPSHOT'): | ||
releaseType = 'prerelease'; | ||
break; | ||
case commitTypes.has('feat'): | ||
releaseType = 'minor'; | ||
break; | ||
case !commitTypes.has('fix'): | ||
skipRelease = true; | ||
break; | ||
default: | ||
releaseType = 'patch'; | ||
} | ||
|
||
versionsToPublish[lang] = { | ||
...version, | ||
releaseType: 'patch', | ||
...(commitTypes.has('fix') ? undefined : { skipRelease: true }), | ||
next: getNextVersion(currentVersion, 'patch'), | ||
releaseType, | ||
skipRelease, | ||
next: getNextVersion(currentVersion, releaseType), | ||
}; | ||
|
||
continue; | ||
} | ||
|
||
return versionsToPublish; | ||
|
@@ -475,7 +480,13 @@ async function updateLTS(versions: Versions, withGraphs?: boolean): Promise<void | |
); | ||
} | ||
|
||
async function createReleasePR(): Promise<void> { | ||
export async function createReleasePR({ | ||
languages, | ||
major, | ||
}: { | ||
languages: Language[]; | ||
major?: boolean; | ||
}): Promise<void> { | ||
await prepareGitEnvironment(); | ||
|
||
console.log('Searching for commits since last release...'); | ||
|
@@ -484,11 +495,13 @@ async function createReleasePR(): Promise<void> { | |
const versions = await decideReleaseStrategy({ | ||
versions: readVersions(), | ||
commits: validCommits, | ||
languages, | ||
major, | ||
}); | ||
|
||
const versionChanges = getVersionChangesText(versions); | ||
|
||
console.log('Creating changelogs for all languages...'); | ||
console.log(`Creating changelogs for languages: ${languages}...`); | ||
const changelog: Changelog = LANGUAGES.reduce((newChangelog, lang) => { | ||
if (versions[lang].noCommit) { | ||
return newChangelog; | ||
|
@@ -571,8 +584,3 @@ async function createReleasePR(): Promise<void> { | |
console.log(`Release PR #${data.number} is ready for review.`); | ||
console.log(` > ${data.html_url}`); | ||
} | ||
|
||
if (import.meta.url.endsWith(process.argv[1])) { | ||
setVerbose(false); | ||
createReleasePR(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be really cool to have a dry run option for this one !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true!! I'll add it in a subsequent pr