feat: Add pre-release support
parent
3a5eb5d392
commit
14cc315abe
|
@ -29,6 +29,8 @@ This action will bump version, tag commit and generate a changelog with conventi
|
|||
- **Optional** `pre-changelog-generation`: Path to the pre-changelog-generation script file. No hook by default.
|
||||
- **Optional** `skip-ci`: Adds instruction to Github to not consider the push something to rebuild. Default `true`.
|
||||
- **Optional** `create-summary`: Adds the generated changelog as Action Summary. Default `false`.
|
||||
- **Optional** `pre-release`: Marks the release as pre-release. Default `false`.
|
||||
- **Optional** `pre-release-identifier`: The identifier to use for the pre-release. Default `rc`.
|
||||
|
||||
### Pre-Commit hook
|
||||
|
||||
|
|
14
action.yml
14
action.yml
|
@ -44,7 +44,7 @@ inputs:
|
|||
git-branch:
|
||||
description: 'The git branch to be pushed'
|
||||
default: ${{ github.ref }}
|
||||
required: false
|
||||
required: false
|
||||
|
||||
preset:
|
||||
description: 'The preset from Conventional Changelog to use'
|
||||
|
@ -80,7 +80,7 @@ inputs:
|
|||
description: 'Do not pull the repo before tagging. Ensure you full cloned the repo in the first place to get tags'
|
||||
default: 'false'
|
||||
required: false
|
||||
|
||||
|
||||
skip-on-empty:
|
||||
description: 'Do nothing when the changelog from the latest release is empty'
|
||||
default: 'true'
|
||||
|
@ -133,6 +133,16 @@ inputs:
|
|||
default: 'false'
|
||||
required: false
|
||||
|
||||
pre-release:
|
||||
description: 'Marks the release as pre-release'
|
||||
default: 'false'
|
||||
required: false
|
||||
|
||||
pre-release-identifier:
|
||||
description: 'The identifier to use for pre-releases'
|
||||
default: 'rc'
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
changelog:
|
||||
description: 'The generated changelog for the new version'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const core = require('@actions/core')
|
||||
const semverValid = require('semver').valid
|
||||
const semver = require('semver')
|
||||
|
||||
const requireScript = require('./requireScript')
|
||||
|
||||
|
@ -11,45 +11,28 @@ const requireScript = require('./requireScript')
|
|||
* @returns {string}
|
||||
*/
|
||||
module.exports = async (releaseType, version) => {
|
||||
let major, minor, patch
|
||||
let newVersion
|
||||
|
||||
const prerelease = core.getBooleanInput('pre-release')
|
||||
const identifier = core.getInput('pre-release-identifier')
|
||||
|
||||
if (version) {
|
||||
[major, minor, patch] = version.split('.')
|
||||
|
||||
switch (releaseType) {
|
||||
case 'major':
|
||||
major = parseInt(major, 10) + 1
|
||||
minor = 0
|
||||
patch = 0
|
||||
break
|
||||
|
||||
case 'minor':
|
||||
minor = parseInt(minor, 10) + 1
|
||||
patch = 0
|
||||
break
|
||||
|
||||
default:
|
||||
patch = parseInt(patch, 10) + 1
|
||||
}
|
||||
newVersion = semver.inc(version, (prerelease ? 'prerelease' : releaseType), identifier)
|
||||
} else {
|
||||
let version = semverValid(core.getInput('fallback-version'))
|
||||
let version = semver.valid(core.getInput('fallback-version'))
|
||||
|
||||
if (version) {
|
||||
[major, minor, patch] = version.split('.')
|
||||
newVersion = version
|
||||
} else {
|
||||
// default
|
||||
major = 0
|
||||
minor = 1
|
||||
patch = 0
|
||||
newVersion = '0.1.0'
|
||||
}
|
||||
|
||||
core.info(`The version could not be detected, using fallback version '${major}.${minor}.${patch}'.`)
|
||||
core.info(`The version could not be detected, using fallback version '${newVersion}'.`)
|
||||
}
|
||||
|
||||
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
|
||||
|
||||
let newVersion = `${major}.${minor}.${patch}`
|
||||
|
||||
if (preChangelogGenerationFile) {
|
||||
const preChangelogGenerationScript = requireScript(preChangelogGenerationFile)
|
||||
|
||||
|
|
|
@ -10,13 +10,15 @@ const conventionalChangelog = require('conventional-changelog')
|
|||
* @param releaseCount
|
||||
* @param config
|
||||
* @param gitPath
|
||||
* @param skipUnstable
|
||||
* @returns {*}
|
||||
*/
|
||||
const getChangelogStream = (tagPrefix, preset, version, releaseCount, config, gitPath) => conventionalChangelog({
|
||||
const getChangelogStream = (tagPrefix, preset, version, releaseCount, config, gitPath, skipUnstable) => conventionalChangelog({
|
||||
preset,
|
||||
releaseCount: parseInt(releaseCount, 10),
|
||||
tagPrefix,
|
||||
config
|
||||
config,
|
||||
skipUnstable
|
||||
},
|
||||
{
|
||||
version,
|
||||
|
@ -40,10 +42,11 @@ module.exports = getChangelogStream
|
|||
* @param releaseCount
|
||||
* @param config
|
||||
* @param gitPath
|
||||
* @param skipUnstable
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCount, config, gitPath) => new Promise((resolve, reject) => {
|
||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath)
|
||||
module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCount, config, gitPath, skipUnstable) => new Promise((resolve, reject) => {
|
||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath, skipUnstable)
|
||||
|
||||
let changelog = ''
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ async function run() {
|
|||
const gitPath = core.getInput('git-path')
|
||||
const skipCi = core.getBooleanInput('skip-ci')
|
||||
const createSummary = core.getBooleanInput('create-summary')
|
||||
const prerelease = core.getBooleanInput('pre-release')
|
||||
|
||||
if (skipCi) {
|
||||
gitCommitMessage += ' [skip ci]'
|
||||
|
@ -84,7 +85,7 @@ async function run() {
|
|||
|
||||
const config = conventionalConfigFile && requireScript(conventionalConfigFile)
|
||||
|
||||
conventionalRecommendedBump({ preset, tagPrefix, config }, async (error, recommendation) => {
|
||||
conventionalRecommendedBump({ preset, tagPrefix, config, skipUnstable: !prerelease }, async (error, recommendation) => {
|
||||
if (error) {
|
||||
core.setFailed(error.message)
|
||||
return
|
||||
|
@ -146,7 +147,7 @@ async function run() {
|
|||
}
|
||||
|
||||
// Generate the string changelog
|
||||
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config, gitPath)
|
||||
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config, gitPath, !prerelease)
|
||||
core.info('Changelog generated')
|
||||
core.info(stringChangelog)
|
||||
|
||||
|
|
|
@ -9,8 +9,9 @@ module.exports = class Git extends BaseVersioning {
|
|||
bump = (releaseType) => {
|
||||
return new Promise((resolve) => {
|
||||
const tagPrefix = core.getInput('tag-prefix')
|
||||
const prerelease = core.getBooleanInput('pre-release')
|
||||
|
||||
gitSemverTags({ tagPrefix, }, async (err, tags) => {
|
||||
gitSemverTags({ tagPrefix, skipUnstable: !prerelease }, async (err, tags) => {
|
||||
const currentVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null
|
||||
|
||||
// Get the new version
|
||||
|
|
Loading…
Reference in New Issue