Skip to content

Commit

Permalink
SRE-208 - Adding additional outputs when setting prerelease input.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsclifford committed Oct 14, 2024
1 parent e87a591 commit b6b8bc6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ For pre-release versions the commits on the current branch are used, and for rel

The action will increment the major version if it identifies any of the following patterns in the commit body or notes:
| Pattern | Examples |
|------------------------------------|------------------------------------|
| ---------------------------------- | ---------------------------------- |
| `/\+semver:\s*(breaking\|major)/i` | +semver:breaking, +semver:major |
| `/BREAKING CHANGES?:?/` | BREAKING CHANGE:, BREAKING CHANGES |

The action will increment the minor version if it identifies any of the following patterns in the commit body or notes:
| Pattern | Examples |
|-----------------------------------|---------------------------------------------------|
| --------------------------------- | ------------------------------------------------- |
| `/\+semver:\s*(feature\|minor)/i` | +semver:feature, +semver:minor |
| `/feat\([^)]*\):\s/` | feat(area): something, feat(): something |
| `/feature\([^)]*\):\s/` | feature(area): something, feature(): something |
Expand All @@ -60,7 +60,7 @@ If none of the previous patterns match, the action will increment the patch vers
## Inputs

| Parameter | Is Required | Default | Description |
|--------------------------------|--------------------------------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ------------------------------ | ------------------------------------------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tag-prefix` | false | `v` | By default the action strips the prefixes off, but any value provided here will be prepended to the next calculated version.<br/><br/>GitHub indicates it is common practice to prefix your version names with the letter `v` (which is the default). If you do not want a prefix use `tag-prefix: none`. |
| `fallback-to-no-prefix-search` | false | `true` | Flag indicating whether it should fallback to a prefix-less search if no tags are found with the current prefix. Helpful when starting to use prefixes with tags. Accepted values: true\|false. |
| `calculate-prerelease-version` | false | `false` | Flag indicating whether to calculate a pre-release version rather than a release version. Accepts: `true\|false`. |
Expand All @@ -71,17 +71,23 @@ If none of the previous patterns match, the action will increment the patch vers

Each of the outputs are available as environment variables and as action outputs.

| Output | Description |
|--------------------------------|-----------------------------------------------------------------|
| `NEXT_VERSION` | The next `major.minor.patch` version |
| `NEXT_VERSION_NO_PREFIX` | The next `major.minor.patch` version without the tag prefix |
| `NEXT_MINOR_VERSION` | The next `major.minor` version |
| `NEXT_MINOR_VERSION_NO_PREFIX` | The next `major.minor` version without the tag prefix |
| `NEXT_MAJOR_VERSION` | The next `major` version |
| `NEXT_MAJOR_VERSION_NO_PREFIX` | The next `major` version without the tag prefix |
| `NEXT_VERSION_SHA` | The SHA of the next version as an environment variable |
| `PRIOR_VERSION` | The previous `major.minor.patch` version |
| `PRIOR_VERSION_NO_PREFIX` | The previous `major.minor.patch` version without the tag prefix |
| Output | Description |
| -------------------------------------- | --------------------------------------------------------------------------------- |
| `NEXT_VERSION` | The next `major.minor.patch` version |
| `NEXT_VERSION_NO_PREFIX` | The next `major.minor.patch` version without the tag prefix |
| `NEXT_MINOR_VERSION` | The next `major.minor` version |
| `NEXT_MINOR_VERSION_NO_PREFIX` | The next `major.minor` version without the tag prefix |
| `NEXT_MAJOR_VERSION` | The next `major` version |
| `NEXT_MAJOR_VERSION_NO_PREFIX` | The next `major` version without the tag prefix |
| `NEXT_VERSION_SHA` | The SHA of the next version as an environment variable |
| `PRIOR_VERSION` | The previous `major.minor.patch` version |
| `PRIOR_VERSION_NO_PREFIX` | The previous `major.minor.patch` version without the tag prefix |
| `NEXT_VERSION_NOLABEL` | The next `major.minor.patch` version without pre-release label |
| `NEXT_VERSION_NOLABEL_NO_PREFIX` | The next `major.minor.patch` version without the tag prefix and pre-release label |
| `NEXT_MINOR_NOLABEL_VERSION` | The next `major.minor` version without pre-release label |
| `NEXT_MINOR_VERSION_NOLABEL_NO_PREFIX` | The next `major.minor` version without the tag prefix and pre-release label |
| `NEXT_MAJOR_NOLABEL_VERSION` | The next `major` version without pre-release label |
| `NEXT_MAJOR_VERSION_NOLABEL_NO_PREFIX` | The next `major` version without the tag prefix and pre-release label |

## Breaking Changes

Expand Down Expand Up @@ -145,7 +151,7 @@ When creating PRs, please review the following guidelines:
This repo uses [git-version-lite] in its workflows to examine commit messages to determine whether to perform a major, minor or patch increment on merge if [source code] changes have been made. The following table provides the fragment that should be included in a commit message to active different increment strategies.

| Increment Type | Commit Message Fragment |
|----------------|---------------------------------------------|
| -------------- | ------------------------------------------- |
| major | +semver:breaking |
| major | +semver:major |
| minor | +semver:feature |
Expand Down
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ outputs:
PRIOR_VERSION_NO_PREFIX:
description: 'The previous major.minor.patch version without the tag prefix.'

NEXT_VERSION_NOLABEL:
description: 'The calculated next version without pre-release label.'

NEXT_VERSION_NOLABEL_NO_PREFIX:
description: 'The calculated next version without the tag prefix and pre-release label.'

NEXT_MINOR_VERSION_NOLABEL:
description: 'The next major.minor version without pre-release label.'

NEXT_MINOR_VERSION_NOLABEL_NO_PREFIX:
description: 'The next major.minor version without the tag prefix and pre-release label.'

NEXT_MAJOR_VERSION_NOLABEL:
description: 'The next major version without pre-release label.'

NEXT_MAJOR_VERSION_NOLABEL_NO_PREFIX:
description: 'The next major version without the tag prefix and pre-release label.'

runs:
using: 'node20'
main: 'dist/index.js'
6 changes: 5 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ async function run() {
console.log('version to build:');
console.log(versionToBuild);

const { nextPatch, nextMinor, nextMajor, priorVersion } = versionToBuild;
const { nextPatch, nextMinor, nextMajor, priorVersion, nextPatchNoLabel, nextMinorNoLabel, nextMajorNoLabel } = versionToBuild;
setTheOutputs('PRIOR_VERSION', priorVersion, tagPrefix);
setTheOutputs('NEXT_VERSION', nextPatch, tagPrefix);
setTheOutputs('NEXT_MINOR_VERSION', nextMinor, tagPrefix);
setTheOutputs('NEXT_MAJOR_VERSION', nextMajor, tagPrefix);
setTheOutputs('NEXT_VERSION_NOLABEL', nextPatchNoLabel, tagPrefix);
setTheOutputs('NEXT_MINOR_VERSION_NOLABEL', nextMinorNoLabel, tagPrefix);
setTheOutputs('NEXT_MAJOR_VERSION_NOLABEL', nextMajorNoLabel, tagPrefix);

} catch (error) {
const versionTxt = calculatePrereleaseVersion ? 'pre-release' : 'release';
core.setFailed(
Expand Down
11 changes: 9 additions & 2 deletions src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ function nextReleaseVersion(defaultReleaseType, tagPrefix, fallbackToNoPrefixSea
priorVersion: priorSemver.toString(),
nextPatch: nextSemver.toString(),
nextMinor: `${nextSemver.major}.${nextSemver.minor}`,
nextMajor: `${nextSemver.major}`
nextMajor: `${nextSemver.major}`,
nextPatchNoLabel: nextSemver.toString(),
nextMinorNoLabel: `${nextSemver.major}.${nextSemver.minor}`,
nextMajorNoLabel: `${nextSemver.major}`
};
}

Expand Down Expand Up @@ -205,11 +208,15 @@ function nextPrereleaseVersion(label, defaultReleaseType, tagPrefix, fallbackToN

const priorSemver = new SemVer(priorReleaseVersion);
const nextSemver = new SemVer(prereleaseVersion);
const nextSemverNoLabel = new SemVer(nextReleaseVersion);
return {
priorVersion: priorSemver.toString(),
nextPatch: nextSemver.toString(),
nextMinor: `${nextSemver.major}.${nextSemver.minor}`,
nextMajor: `${nextSemver.major}`
nextMajor: `${nextSemver.major}`,
nextPatchNoLabel: nextSemverNoLabel.toString(),
nextMinorNoLabel: `${nextSemverNoLabel.major}.${nextSemverNoLabel.minor}`,
nextMajorNoLabel: `${nextSemverNoLabel.major}`
};
}

Expand Down

0 comments on commit b6b8bc6

Please sign in to comment.