diff --git a/README.md b/README.md index 25aaa3497..ea63cfffc 100644 --- a/README.md +++ b/README.md @@ -339,14 +339,14 @@ autolabeler: - '/JIRA-[0-9]{1,4}/' ``` -## Pre-release increment +## Prerelease increment -When creating Pre-release (`prerelease: true`), you can add a pre-release identifier to increment the pre-release version number, with the `pre-release-identifier` option. It accept any string, but it's recommended to use [Semantic Versioning](https://semver.org/) pre-release identifiers (alpha, beta, rc, etc). +When creating prerelease (`prerelease: true`), you can add a prerelease identifier to increment the prerelease version number, with the `prerelease-identifier` option. It accept any string, but it's recommended to use [Semantic Versioning](https://semver.org/) prerelease identifiers (alpha, beta, rc, etc). -Using `pre-release-identifier` automatically enable `include-pre-releases`. +Using `prerelease-identifier` automatically enable `include-prereleases`. ```yml -pre-release-identifier: 'alpha' # will create a pre-release with version number x.x.x-alpha.x +prerelease-identifier: 'alpha' # will create a prerelease with version number x.x.x-alpha.x ``` ## Projects that don't use Semantic Versioning @@ -359,18 +359,19 @@ For example, if your project doesn't use patch version numbers, you can set `ver The Release Drafter GitHub Action accepts a number of optional inputs directly in your workflow configuration. These will typically override default behavior specified in your `release-drafter.yml` config. -| Input | Description | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `config-name` | If your workflow requires multiple release-drafter configs it be helpful to override the config-name. The config should still be located inside `.github` as that's where we are looking for config files. | -| `name` | The name that will be used in the GitHub release that's created or updated. This will override any `name-template` specified in your `release-drafter.yml` if defined. | -| `tag` | The tag name to be associated with the GitHub release that's created or updated. This will override any `tag-template` specified in your `release-drafter.yml` if defined. | -| `version` | The version to be associated with the GitHub release that's created or updated. This will override any version calculated by the release-drafter. | -| `publish` | A boolean indicating whether the release being created or updated should be immediately published. This may be useful if the output of a previous workflow step determines that a new version of your project has been (or will be) released, as with [`salsify/action-detect-and-tag-new-version`](https://github.com/salsify/action-detect-and-tag-new-version). | -| `prerelease` | A boolean indicating whether the release being created or updated is a prerelease. | -| `latest` | A string indicating whether the release being created or updated should be marked as latest. | -| `commitish` | A string specifying the target branch for the release being created. | -| `header` | A string that would be added before the template body. | -| `footer` | A string that would be added after the template body. | +| Input | Description | +| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `config-name` | If your workflow requires multiple release-drafter configs it be helpful to override the config-name. The config should still be located inside `.github` as that's where we are looking for config files. | +| `name` | The name that will be used in the GitHub release that's created or updated. This will override any `name-template` specified in your `release-drafter.yml` if defined. | +| `tag` | The tag name to be associated with the GitHub release that's created or updated. This will override any `tag-template` specified in your `release-drafter.yml` if defined. | +| `version` | The version to be associated with the GitHub release that's created or updated. This will override any version calculated by the release-drafter. | +| `publish` | A boolean indicating whether the release being created or updated should be immediately published. This may be useful if the output of a previous workflow step determines that a new version of your project has been (or will be) released, as with [`salsify/action-detect-and-tag-new-version`](https://github.com/salsify/action-detect-and-tag-new-version). | +| `prerelease` | A boolean indicating whether the release being created or updated is a prerelease. | +| `prerelease-identifier` | A string indicating an identifier (alpha, beta, rc, etc), to increment the prerelease version. number | +| `latest` | A string indicating whether the release being created or updated should be marked as latest. | +| `commitish` | A string specifying the target branch for the release being created. | +| `header` | A string that would be added before the template body. | +| `footer` | A string that would be added after the template body. | ## Action Outputs diff --git a/action.yml b/action.yml index 546a96ef8..8ad4b1bcb 100644 --- a/action.yml +++ b/action.yml @@ -43,6 +43,11 @@ inputs: A boolean indicating whether the release being created or updated is a prerelease. required: false default: '' + prerelease-identifier: + description: | + A string indicating an identifier (alpha, beta, rc, etc), to increment the prerelease version. + required: false + default: '' commitish: description: | The object that the release should be created to point to. diff --git a/dist/index.js b/dist/index.js index 54ca2db44..96194eea5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -142235,11 +142235,11 @@ module.exports = (app, { getRouter }) => { 'pull_request_target.edited', ], async (context) => { - const { disableAutolabeler } = getInput() + const { configName, disableAutolabeler } = getInput() const config = await getConfig({ context, - configName: core.getInput('config-name'), + configName, }) if (config === null || disableAutolabeler) return @@ -142334,24 +142334,16 @@ module.exports = (app, { getRouter }) => { ) const drafter = async (context) => { - const { - shouldDraft, - configName, - version, - tag, - name, - disableReleaser, - commitish, - } = getInput() + const input = getInput() const config = await getConfig({ context, - configName, + configName: input.configName, }) - const { isPreRelease, latest } = getInput({ config }) + if (!config || input.disableReleaser) return - if (config === null || disableReleaser) return + updateConfigFromInput(config, input) // GitHub Actions merge payloads slightly differ, in that their ref points // to the PR branch instead of refs/heads/master @@ -142361,28 +142353,21 @@ module.exports = (app, { getRouter }) => { return } - const targetCommitish = commitish || config['commitish'] || ref + const targetCommitish = config.commitish || ref + const { 'filter-by-commitish': filterByCommitish, 'include-pre-releases': includePreReleases, - 'pre-release-identifier': preReleaseIdentifier, + 'prerelease-identifier': preReleaseIdentifier, 'tag-prefix': tagPrefix, + latest, + prerelease, } = config const shouldIncludePreReleases = Boolean( includePreReleases || preReleaseIdentifier ) - // override header and footer when passed as input - const header = core.getInput('header') - const footer = core.getInput('footer') - if (header) { - config['header'] = header - } - if (footer) { - config['footer'] = footer - } - const { draftRelease, lastRelease } = await findReleases({ context, targetCommitish, @@ -142405,6 +142390,8 @@ module.exports = (app, { getRouter }) => { config['sort-direction'] ) + const { shouldDraft, version, tag, name } = input + const releaseInfo = generateReleaseInfo({ context, commits, @@ -142414,7 +142401,7 @@ module.exports = (app, { getRouter }) => { version, tag, name, - isPreRelease, + isPreRelease: prerelease, latest, shouldDraft, targetCommitish, @@ -142450,40 +142437,56 @@ module.exports = (app, { getRouter }) => { } } -function getInput({ config } = {}) { - // Returns all the inputs that doesn't need a merge with the config file - if (!config) { - return { - shouldDraft: core.getInput('publish').toLowerCase() !== 'true', - configName: core.getInput('config-name'), - version: core.getInput('version') || undefined, - tag: core.getInput('tag') || undefined, - name: core.getInput('name') || undefined, - disableReleaser: - core.getInput('disable-releaser').toLowerCase() === 'true', - disableAutolabeler: - core.getInput('disable-autolabeler').toLowerCase() === 'true', - commitish: core.getInput('commitish') || undefined, - } +function getInput() { + return { + configName: core.getInput('config-name'), + shouldDraft: core.getInput('publish').toLowerCase() !== 'true', + version: core.getInput('version') || undefined, + tag: core.getInput('tag') || undefined, + name: core.getInput('name') || undefined, + disableReleaser: core.getInput('disable-releaser').toLowerCase() === 'true', + disableAutolabeler: + core.getInput('disable-autolabeler').toLowerCase() === 'true', + commitish: core.getInput('commitish') || undefined, + header: core.getInput('header') || undefined, + footer: core.getInput('footer') || undefined, + prerelease: + core.getInput('prerelease') !== '' + ? core.getInput('prerelease').toLowerCase() === 'true' + : undefined, + preReleaseIdentifier: core.getInput('prerelease-identifier') || undefined, + latest: core.getInput('latest')?.toLowerCase() || undefined, } +} - // Merges the config file with the input - // the input takes precedence, because it's more easy to change at runtime - const preRelease = core.getInput('prerelease').toLowerCase() +/** + * Merges the config file with the input + * the input takes precedence, because it's more easy to change at runtime + */ +function updateConfigFromInput(config, input) { + if (input.commitish) { + config.commitish = input.commitish + } - const isPreRelease = - preRelease === 'true' || (!preRelease && config.prerelease) + if (input.header) { + config.header = input.header + } - const latestInput = core.getInput('latest').toLowerCase() + if (input.footer) { + config.footer = input.footer + } - const latest = isPreRelease - ? 'false' - : (!latestInput && config.latest) || latestInput || undefined + if (input.prerelease !== undefined) { + config.prerelease = input.prerelease + } - return { - isPreRelease, - latest, + if (input.preReleaseIdentifier) { + config['prerelease-identifier'] = input.preReleaseIdentifier } + + config.latest = config.prerelease + ? 'false' + : input.latest || config.latest || undefined } function setActionOutput( @@ -142816,10 +142819,10 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-by': SORT_BY.mergedAt, 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, + 'prerelease-identifier': '', + 'include-pre-releases': false, latest: 'true', 'filter-by-commitish': false, - 'include-pre-releases': false, - 'pre-release-identifier': '', commitish: '', 'category-template': `## $TITLE`, header: '', @@ -143247,7 +143250,7 @@ const resolveVersionKeyIncrement = ( const versionKeyIncrement = versionKey || config['version-resolver'].default const shouldIncrementAsPrerelease = - isPreRelease && config['pre-release-identifier'] + isPreRelease && config['prerelease-identifier'] if (!shouldIncrementAsPrerelease) { return versionKeyIncrement @@ -143305,7 +143308,7 @@ const generateReleaseInfo = ({ version || tag || name, versionKeyIncrement, config['tag-prefix'], - config['pre-release-identifier'] + config['prerelease-identifier'] ) core.debug('versionInfo: ' + JSON.stringify(versionInfo, null, 2)) @@ -143508,9 +143511,9 @@ const schema = (context) => { prerelease: Joi.boolean().default(DEFAULT_CONFIG.prerelease), - 'pre-release-identifier': Joi.string() + 'prerelease-identifier': Joi.string() .allow('') - .default(DEFAULT_CONFIG['pre-release-identifier']), + .default(DEFAULT_CONFIG['prerelease-identifier']), latest: Joi.string() .allow('', 'true', 'false', 'legacy') diff --git a/index.js b/index.js index c194dc08b..3f3366bbb 100644 --- a/index.js +++ b/index.js @@ -32,11 +32,11 @@ module.exports = (app, { getRouter }) => { 'pull_request_target.edited', ], async (context) => { - const { disableAutolabeler } = getInput() + const { configName, disableAutolabeler } = getInput() const config = await getConfig({ context, - configName: core.getInput('config-name'), + configName, }) if (config === null || disableAutolabeler) return @@ -131,24 +131,16 @@ module.exports = (app, { getRouter }) => { ) const drafter = async (context) => { - const { - shouldDraft, - configName, - version, - tag, - name, - disableReleaser, - commitish, - } = getInput() + const input = getInput() const config = await getConfig({ context, - configName, + configName: input.configName, }) - const { isPreRelease, latest } = getInput({ config }) + if (!config || input.disableReleaser) return - if (config === null || disableReleaser) return + updateConfigFromInput(config, input) // GitHub Actions merge payloads slightly differ, in that their ref points // to the PR branch instead of refs/heads/master @@ -158,28 +150,21 @@ module.exports = (app, { getRouter }) => { return } - const targetCommitish = commitish || config['commitish'] || ref + const targetCommitish = config.commitish || ref + const { 'filter-by-commitish': filterByCommitish, 'include-pre-releases': includePreReleases, - 'pre-release-identifier': preReleaseIdentifier, + 'prerelease-identifier': preReleaseIdentifier, 'tag-prefix': tagPrefix, + latest, + prerelease, } = config const shouldIncludePreReleases = Boolean( includePreReleases || preReleaseIdentifier ) - // override header and footer when passed as input - const header = core.getInput('header') - const footer = core.getInput('footer') - if (header) { - config['header'] = header - } - if (footer) { - config['footer'] = footer - } - const { draftRelease, lastRelease } = await findReleases({ context, targetCommitish, @@ -202,6 +187,8 @@ module.exports = (app, { getRouter }) => { config['sort-direction'] ) + const { shouldDraft, version, tag, name } = input + const releaseInfo = generateReleaseInfo({ context, commits, @@ -211,7 +198,7 @@ module.exports = (app, { getRouter }) => { version, tag, name, - isPreRelease, + isPreRelease: prerelease, latest, shouldDraft, targetCommitish, @@ -247,40 +234,56 @@ module.exports = (app, { getRouter }) => { } } -function getInput({ config } = {}) { - // Returns all the inputs that doesn't need a merge with the config file - if (!config) { - return { - shouldDraft: core.getInput('publish').toLowerCase() !== 'true', - configName: core.getInput('config-name'), - version: core.getInput('version') || undefined, - tag: core.getInput('tag') || undefined, - name: core.getInput('name') || undefined, - disableReleaser: - core.getInput('disable-releaser').toLowerCase() === 'true', - disableAutolabeler: - core.getInput('disable-autolabeler').toLowerCase() === 'true', - commitish: core.getInput('commitish') || undefined, - } +function getInput() { + return { + configName: core.getInput('config-name'), + shouldDraft: core.getInput('publish').toLowerCase() !== 'true', + version: core.getInput('version') || undefined, + tag: core.getInput('tag') || undefined, + name: core.getInput('name') || undefined, + disableReleaser: core.getInput('disable-releaser').toLowerCase() === 'true', + disableAutolabeler: + core.getInput('disable-autolabeler').toLowerCase() === 'true', + commitish: core.getInput('commitish') || undefined, + header: core.getInput('header') || undefined, + footer: core.getInput('footer') || undefined, + prerelease: + core.getInput('prerelease') !== '' + ? core.getInput('prerelease').toLowerCase() === 'true' + : undefined, + preReleaseIdentifier: core.getInput('prerelease-identifier') || undefined, + latest: core.getInput('latest')?.toLowerCase() || undefined, } +} - // Merges the config file with the input - // the input takes precedence, because it's more easy to change at runtime - const preRelease = core.getInput('prerelease').toLowerCase() +/** + * Merges the config file with the input + * the input takes precedence, because it's more easy to change at runtime + */ +function updateConfigFromInput(config, input) { + if (input.commitish) { + config.commitish = input.commitish + } - const isPreRelease = - preRelease === 'true' || (!preRelease && config.prerelease) + if (input.header) { + config.header = input.header + } - const latestInput = core.getInput('latest').toLowerCase() + if (input.footer) { + config.footer = input.footer + } - const latest = isPreRelease - ? 'false' - : (!latestInput && config.latest) || latestInput || undefined + if (input.prerelease !== undefined) { + config.prerelease = input.prerelease + } - return { - isPreRelease, - latest, + if (input.preReleaseIdentifier) { + config['prerelease-identifier'] = input.preReleaseIdentifier } + + config.latest = config.prerelease + ? 'false' + : input.latest || config.latest || undefined } function setActionOutput( diff --git a/lib/default-config.js b/lib/default-config.js index 7ef39ecca..22af5fc55 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -25,10 +25,10 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-by': SORT_BY.mergedAt, 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, + 'prerelease-identifier': '', + 'include-pre-releases': false, latest: 'true', 'filter-by-commitish': false, - 'include-pre-releases': false, - 'pre-release-identifier': '', commitish: '', 'category-template': `## $TITLE`, header: '', diff --git a/lib/releases.js b/lib/releases.js index 924c22a66..1f22d6eb1 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -334,7 +334,7 @@ const resolveVersionKeyIncrement = ( const versionKeyIncrement = versionKey || config['version-resolver'].default const shouldIncrementAsPrerelease = - isPreRelease && config['pre-release-identifier'] + isPreRelease && config['prerelease-identifier'] if (!shouldIncrementAsPrerelease) { return versionKeyIncrement @@ -392,7 +392,7 @@ const generateReleaseInfo = ({ version || tag || name, versionKeyIncrement, config['tag-prefix'], - config['pre-release-identifier'] + config['prerelease-identifier'] ) core.debug('versionInfo: ' + JSON.stringify(versionInfo, null, 2)) diff --git a/lib/schema.js b/lib/schema.js index 0891b0acd..7f0d42c06 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -77,9 +77,9 @@ const schema = (context) => { prerelease: Joi.boolean().default(DEFAULT_CONFIG.prerelease), - 'pre-release-identifier': Joi.string() + 'prerelease-identifier': Joi.string() .allow('') - .default(DEFAULT_CONFIG['pre-release-identifier']), + .default(DEFAULT_CONFIG['prerelease-identifier']), latest: Joi.string() .allow('', 'true', 'false', 'legacy') diff --git a/schema.json b/schema.json index 4b080e6a1..326c7c69a 100644 --- a/schema.json +++ b/schema.json @@ -137,7 +137,7 @@ "default": false, "type": "boolean" }, - "pre-release-identifier": { + "prerelease-identifier": { "anyOf": [ { "type": "string", diff --git a/test/fixtures/config/config-with-pre-release-identifier.yml b/test/fixtures/config/config-with-pre-release-identifier.yml index 577b95aa6..0ac5971c5 100644 --- a/test/fixtures/config/config-with-pre-release-identifier.yml +++ b/test/fixtures/config/config-with-pre-release-identifier.yml @@ -1,4 +1,4 @@ template: This is a Pre-release with identifier. name-template: 'v$RESOLVED_VERSION' tag-template: 'v$RESOLVED_VERSION' -pre-release-identifier: alpha +prerelease-identifier: alpha diff --git a/test/index.test.js b/test/index.test.js index 2b44c5e3c..a1bfa3305 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2707,7 +2707,7 @@ describe('release-drafter', () => { ) }) - it('resolves tag with incremented pre-release identifier', async () => { + it('resolves tag with incremented prerelease identifier', async () => { return overridesTest( { prerelease: 'true', diff --git a/test/versions.test.js b/test/versions.test.js index 3f5b8d790..8bae0c33f 100644 --- a/test/versions.test.js +++ b/test/versions.test.js @@ -75,7 +75,7 @@ describe('versions', () => { }, ], [ - 'handles incremental pre-releases', + 'handles incremental prereleases', { release: { tag_name: 'v10.0.3', @@ -93,7 +93,7 @@ describe('versions', () => { }, ], [ - 'handles incremental pre-releases on existing pre-releases', + 'handles incremental prereleases on existing prereleases', { release: { tag_name: 'v10.0.3-alpha.2', @@ -172,7 +172,7 @@ describe('versions', () => { ) expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH') - // Next pre-release version checks + // Next prerelease version checks expect(versionInfo.$NEXT_PRERELEASE_VERSION.version).toEqual( expected.$PRERELEASE )