diff --git a/docs/faq.md b/docs/faq.md index 60b6ae1..0aae51e 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -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. diff --git a/lib/index.js b/lib/index.js index 96c9374..108e979 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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; { @@ -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) } } @@ -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' ) @@ -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 }) @@ -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