Skip to content

Commit

Permalink
feat: handle prerelease-identifier as input
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Jul 21, 2023
1 parent 629b6cf commit 38f141e
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 142 deletions.
33 changes: 17 additions & 16 deletions README.md
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -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.
Expand Down
123 changes: 63 additions & 60 deletions dist/index.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -142405,6 +142390,8 @@ module.exports = (app, { getRouter }) => {
config['sort-direction']
)

const { shouldDraft, version, tag, name } = input

const releaseInfo = generateReleaseInfo({
context,
commits,
Expand All @@ -142414,7 +142401,7 @@ module.exports = (app, { getRouter }) => {
version,
tag,
name,
isPreRelease,
isPreRelease: prerelease,
latest,
shouldDraft,
targetCommitish,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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: '',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 38f141e

Please sign in to comment.