Skip to content

Commit

Permalink
Improve prerelease handling (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes authored Jan 9, 2022
1 parent e812f68 commit ac25966
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
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

0 comments on commit ac25966

Please sign in to comment.