Skip to content
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

Improve prerelease handling #246

Merged
merged 7 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ That version is a `semver.inc(currentRelease.version, 'patch')` by default for e

The semver increment level defaults to `patch` but can be set to `major`, `minor`, `patch` or `prerelease` by putting a corresponding label on the feature branch PR.

**pr-release** is especially careful with pre-releases. If the last release was a `prerelease` then the next release will also default to a semver `prerelease`.
**pr-release** is especially careful with pre-releases. If the last release was a `prerelease` then the next release will also default to a semver `prerelease`. This makes it hard to accidentally publish to the stable channel without being explicit.

**pr-release** infers the current version by checking multiple sources (package.json, release PR header, git tag, prior release) and always takes the highest found version as the authoritative one. So if you want to override the generated version, just manually update the release PR title to be a normal non-semver prerelease and merge. From then on, versions will not be prerelease incremented.

Expand Down
28 changes: 14 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function updateDocs(){
}

function getNextVersion({ recentBranches, version }){
let severityIdx = groupBy( x => prSeverity(x, version), recentBranches )
let severityIdx = groupBy( x => prSeverity(x), recentBranches )

// todo-james
let nextVersion; {
Expand All @@ -224,13 +224,16 @@ function getNextVersion({ recentBranches, version }){
}
}

let prerelease = semver.prerelease(version, 'prerelease')
if ( semver.compare(nextVersion,version) == 0 ) {
let level =
semver.prerelease(nextVersion, 'prerelease')
? 'prerelease'
: 'patch'
prerelease
? ['prerelease', ...prerelease]
: ['patch']

nextVersion = semver.inc(nextVersion, level)
nextVersion = semver.inc(nextVersion, ...level)
} else if ( prerelease ) {
nextVersion = semver.inc(nextVersion, 'prerelease', ...prerelease)
}
}

Expand Down Expand Up @@ -742,11 +745,7 @@ async function inferVersion({ owner, repo, lastRelease }){
return { version, versionType }
}

function prSeverity(x, currentVersion){

if ( semver.prerelease(currentVersion) ) {
return 'prerelease'
}
function prSeverity(x){

let prerelease = x.labels.find( x => x.name == 'prerelease' )
let patch = x.labels.find( x => x.name == 'patch' )
Expand Down Expand Up @@ -970,7 +969,7 @@ async function pr(options){
return ''
}

let severityIdx = groupBy( x => prSeverity(x, version), recentBranches )
let severityIdx = groupBy( x => prSeverity(x), recentBranches )

let nextVersion = getNextVersion({ recentBranches, version })

Expand Down Expand Up @@ -1378,12 +1377,13 @@ async function rollback({ version, ignore=null }){
,sha: commit.data.sha
})

let prerelease = semver.prerelease(currentReleaseTag, 'prerelease')
let level =
semver.prerelease(currentReleaseTag, 'prerelease')
? 'prerelease'
prerelease
? ['prerelease', ...prerelease]
: 'patch'

let newReleaseTag = semver.inc(currentReleaseTag, level)
let newReleaseTag = semver.inc(currentReleaseTag, ...level)

await octokit.rest.repos.createRelease({
owner
Expand Down