Skip to content

Commit

Permalink
feat: add latest input (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-mago committed Jul 12, 2023
1 parent 65c5fb4 commit ff929b5
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -139,6 +139,7 @@ You can configure Release Drafter using the following key in your `.github/relea
| `sort-by` | Optional | Sort changelog by merged_at or title. Can be one of: `merged_at`, `title`. Default: `merged_at`. |
| `sort-direction` | Optional | Sort changelog in ascending or descending order. Can be one of: `ascending`, `descending`. Default: `descending`. |
| `prerelease` | Optional | Mark the draft release as pre-release. Default `false`. |
| `latest` | Optional | Mark the release as latest. Only works for published releases. Can be one of: `true`, `false`, `legacy`. Default `true`. |
| `version-resolver` | Optional | Adjust the `$RESOLVED_VERSION` variable using labels. Refer to [Version Resolver](#version-resolver) to learn more about this |
| `commitish` | Optional | The release target, i.e. branch or commit it should point to. Default: the ref that release-drafter runs for, e.g. `refs/heads/master` if configured to run on pushes to `master`. |
| `filter-by-commitish` | Optional | Filter previous releases to consider only those with the target matching `commitish`. Default: `false`. |
Expand Down Expand Up @@ -356,6 +357,7 @@ The Release Drafter GitHub Action accepts a number of optional inputs directly i
| `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. |
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -33,6 +33,11 @@ inputs:
A boolean indicating whether the release being created or updated should be immediately published.
required: false
default: ''
latest:
description: |
A string indicating whether the release being created or updated should be marked as latest.
required: false
default: ''
prerelease:
description: |
A boolean indicating whether the release being created or updated is a prerelease.
Expand Down
24 changes: 22 additions & 2 deletions dist/index.js
Expand Up @@ -142349,7 +142349,7 @@ module.exports = (app, { getRouter }) => {
configName,
})

const { isPreRelease } = getInput({ config })
const { isPreRelease, latest } = getInput({ config })

if (config === null || disableReleaser) return

Expand Down Expand Up @@ -142410,6 +142410,7 @@ module.exports = (app, { getRouter }) => {
tag,
name,
isPreRelease,
latest,
shouldDraft,
targetCommitish,
})
Expand Down Expand Up @@ -142465,8 +142466,18 @@ function getInput({ config } = {}) {
// the input takes precedence, because it's more easy to change at runtime
const preRelease = core.getInput('prerelease').toLowerCase()

const isPreRelease =
preRelease === 'true' || (!preRelease && config.prerelease)

const latestInput = core.getInput('latest').toLowerCase()

const latest = isPreRelease
? 'false'
: (!latestInput && config.latest) || latestInput || undefined

return {
isPreRelease: preRelease === 'true' || (!preRelease && config.prerelease),
isPreRelease,
latest,
}
}

Expand Down Expand Up @@ -142800,6 +142811,7 @@ const DEFAULT_CONFIG = Object.freeze({
'sort-by': SORT_BY.mergedAt,
'sort-direction': SORT_DIRECTIONS.descending,
prerelease: false,
latest: 'true',
'filter-by-commitish': false,
'include-pre-releases': false,
commitish: '',
Expand Down Expand Up @@ -143221,6 +143233,7 @@ const generateReleaseInfo = ({
tag,
name,
isPreRelease,
latest,
shouldDraft,
targetCommitish,
}) => {
Expand Down Expand Up @@ -143294,6 +143307,7 @@ const generateReleaseInfo = ({
body,
targetCommitish,
prerelease: isPreRelease,
make_latest: latest,
draft: shouldDraft,
resolvedVersion,
majorVersion,
Expand All @@ -143311,6 +143325,7 @@ const createRelease = ({ context, releaseInfo }) => {
body: releaseInfo.body,
draft: releaseInfo.draft,
prerelease: releaseInfo.prerelease,
make_latest: releaseInfo.make_latest,
})
)
}
Expand All @@ -143328,6 +143343,7 @@ const updateRelease = ({ context, draftRelease, releaseInfo }) => {
body: releaseInfo.body,
draft: releaseInfo.draft,
prerelease: releaseInfo.prerelease,
make_latest: releaseInfo.make_latest,
...updateReleaseParameters,
})
)
Expand Down Expand Up @@ -143444,6 +143460,10 @@ const schema = (context) => {

prerelease: Joi.boolean().default(DEFAULT_CONFIG.prerelease),

latest: Joi.string()
.allow('', 'true', 'false', 'legacy')
.default(DEFAULT_CONFIG.latest),

'filter-by-commitish': Joi.boolean().default(
DEFAULT_CONFIG['filter-by-commitish']
),
Expand Down
5 changes: 5 additions & 0 deletions docker/action.yml
Expand Up @@ -33,6 +33,11 @@ inputs:
A boolean indicating whether the release being created or updated should be immediately published.
required: false
default: ''
latest:
description: |
A string indicating whether the release being created or updated should be marked as latest.
required: false
default: ''
prerelease:
description: |
A boolean indicating whether the release being created or updated is a prerelease.
Expand Down
15 changes: 13 additions & 2 deletions index.js
Expand Up @@ -146,7 +146,7 @@ module.exports = (app, { getRouter }) => {
configName,
})

const { isPreRelease } = getInput({ config })
const { isPreRelease, latest } = getInput({ config })

if (config === null || disableReleaser) return

Expand Down Expand Up @@ -207,6 +207,7 @@ module.exports = (app, { getRouter }) => {
tag,
name,
isPreRelease,
latest,
shouldDraft,
targetCommitish,
})
Expand Down Expand Up @@ -262,8 +263,18 @@ function getInput({ config } = {}) {
// the input takes precedence, because it's more easy to change at runtime
const preRelease = core.getInput('prerelease').toLowerCase()

const isPreRelease =
preRelease === 'true' || (!preRelease && config.prerelease)

const latestInput = core.getInput('latest').toLowerCase()

const latest = isPreRelease
? 'false'
: (!latestInput && config.latest) || latestInput || undefined

return {
isPreRelease: preRelease === 'true' || (!preRelease && config.prerelease),
isPreRelease,
latest,
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Expand Up @@ -25,6 +25,7 @@ const DEFAULT_CONFIG = Object.freeze({
'sort-by': SORT_BY.mergedAt,
'sort-direction': SORT_DIRECTIONS.descending,
prerelease: false,
latest: 'true',
'filter-by-commitish': false,
'include-pre-releases': false,
commitish: '',
Expand Down
4 changes: 4 additions & 0 deletions lib/releases.js
Expand Up @@ -326,6 +326,7 @@ const generateReleaseInfo = ({
tag,
name,
isPreRelease,
latest,
shouldDraft,
targetCommitish,
}) => {
Expand Down Expand Up @@ -399,6 +400,7 @@ const generateReleaseInfo = ({
body,
targetCommitish,
prerelease: isPreRelease,
make_latest: latest,
draft: shouldDraft,
resolvedVersion,
majorVersion,
Expand All @@ -416,6 +418,7 @@ const createRelease = ({ context, releaseInfo }) => {
body: releaseInfo.body,
draft: releaseInfo.draft,
prerelease: releaseInfo.prerelease,
make_latest: releaseInfo.make_latest,
})
)
}
Expand All @@ -433,6 +436,7 @@ const updateRelease = ({ context, draftRelease, releaseInfo }) => {
body: releaseInfo.body,
draft: releaseInfo.draft,
prerelease: releaseInfo.prerelease,
make_latest: releaseInfo.make_latest,
...updateReleaseParameters,
})
)
Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Expand Up @@ -77,6 +77,10 @@ const schema = (context) => {

prerelease: Joi.boolean().default(DEFAULT_CONFIG.prerelease),

latest: Joi.string()
.allow('', 'true', 'false', 'legacy')
.default(DEFAULT_CONFIG.latest),

'filter-by-commitish': Joi.boolean().default(
DEFAULT_CONFIG['filter-by-commitish']
),
Expand Down
12 changes: 12 additions & 0 deletions schema.json
Expand Up @@ -117,6 +117,18 @@
"default": false,
"type": "boolean"
},
"latest": {
"anyOf": [
{
"type": "string",
"enum": ["", "true", "false", "legacy"]
},
{
"default": "true",
"type": "string"
}
]
},
"filter-by-commitish": {
"default": false,
"type": "boolean"
Expand Down

0 comments on commit ff929b5

Please sign in to comment.