Skip to content

Commit

Permalink
feat: output version bump type (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jveldboom authored Feb 28, 2023
1 parent 8a73acd commit 6772f33
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ jobs:
assert.deepEqual(outputs['major-with-prefix'], `v${major}`)
assert.deepEqual(outputs.minor, minor)
assert.deepEqual(outputs.patch, patch)
// check output is a valid bump string
assert.deepEqual(['major','minor','patch'].indexOf(outputs.bump) > -1, true)
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Design Descisions
`major-with-prefix` | major version number with `v` prefix (`v1`)
`minor` | minor version number
`patch` | patch version number
`bump` | version bump type (major, minor, or patch)

## Example Use-Cases
### Auto version on any push to the `main` branch
Expand Down Expand Up @@ -107,9 +108,10 @@ yarn lint
- [x] Improve index.js file
- Should it be simplified and wrapped in a try/catch?
- How can we get 100% test coverage on it?
- [x] Output version bump (major, minor, patch) No specific use case but I believe it will be useful
- [ ] Add version suffix that are semver
- [ ] Improve integration testing to cover all use-case. May require the ability to pass in a list of commits
- [ ] Output version bump (major, minor, patch) No specific use case but I believe it will be useful


## Notes
- Commit Analyzer https://github.com/semantic-release/commit-analyzer#releaserules
Expand Down
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44181,7 +44181,7 @@ module.exports = async () => {
// return a default version if no previous github tags
if (!latestRelease) {
const incrementedVersion = semver.inc('0.0.0', core.getInput('default-bump'))
return utils.setVersionOutputs(incrementedVersion)
return utils.setVersionOutputs(incrementedVersion, core.getInput('default-bump'))
}

if (!semver.valid(latestRelease.name)) {
Expand All @@ -44193,7 +44193,7 @@ module.exports = async () => {
const bump = await utils.getVersionBump(commits, core.getInput('default-bump'))

const incrementedVersion = semver.inc(latestRelease.name, bump)
utils.setVersionOutputs(incrementedVersion)
utils.setVersionOutputs(incrementedVersion, bump)
}


Expand All @@ -44209,8 +44209,9 @@ const commit = __nccwpck_require__(156)
/**
* Output version details
* @param {string} version version number
* @param {string} bump version bump name (major, minor, patch)
*/
const setVersionOutputs = (version) => {
const setVersionOutputs = (version, bump) => {
const output = semver.parse(version)

core.setOutput('version', output.version)
Expand All @@ -44219,6 +44220,7 @@ const setVersionOutputs = (version) => {
core.setOutput('major-with-prefix', `v${output.major}`)
core.setOutput('minor', output.minor)
core.setOutput('patch', output.patch)
core.setOutput('bump', bump)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = async () => {
// return a default version if no previous github tags
if (!latestRelease) {
const incrementedVersion = semver.inc('0.0.0', core.getInput('default-bump'))
return utils.setVersionOutputs(incrementedVersion)
return utils.setVersionOutputs(incrementedVersion, core.getInput('default-bump'))
}

if (!semver.valid(latestRelease.name)) {
Expand All @@ -37,5 +37,5 @@ module.exports = async () => {
const bump = await utils.getVersionBump(commits, core.getInput('default-bump'))

const incrementedVersion = semver.inc(latestRelease.name, bump)
utils.setVersionOutputs(incrementedVersion)
utils.setVersionOutputs(incrementedVersion, bump)
}
2 changes: 2 additions & 0 deletions src/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('run', () => {
expect(core.setOutput).toHaveBeenNthCalledWith(4, 'major-with-prefix', 'v0')
expect(core.setOutput).toHaveBeenNthCalledWith(5, 'minor', 0)
expect(core.setOutput).toHaveBeenNthCalledWith(6, 'patch', 1)
expect(core.setOutput).toHaveBeenNthCalledWith(7, 'bump', 'patch')
})

it('should fail when latest tag is no valid semver', async () => {
Expand All @@ -73,5 +74,6 @@ describe('run', () => {
expect(core.setOutput).toHaveBeenNthCalledWith(4, 'major-with-prefix', 'v1')
expect(core.setOutput).toHaveBeenNthCalledWith(5, 'minor', 2)
expect(core.setOutput).toHaveBeenNthCalledWith(6, 'patch', 4)
expect(core.setOutput).toHaveBeenNthCalledWith(7, 'bump', 'patch')
})
})
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const commit = require('@semantic-release/commit-analyzer')
/**
* Output version details
* @param {string} version version number
* @param {string} bump version bump name (major, minor, patch)
*/
const setVersionOutputs = (version) => {
const setVersionOutputs = (version, bump) => {
const output = semver.parse(version)

core.setOutput('version', output.version)
Expand All @@ -15,6 +16,7 @@ const setVersionOutputs = (version) => {
core.setOutput('major-with-prefix', `v${output.major}`)
core.setOutput('minor', output.minor)
core.setOutput('patch', output.patch)
core.setOutput('bump', bump)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ describe('utils', () => {

describe('setVersionOutputs()', () => {
it('should set output for all values', () => {
utils.setVersionOutputs('2.3.4')
utils.setVersionOutputs('2.3.4', 'minor')
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'version', '2.3.4')
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'version-with-prefix', 'v2.3.4')
expect(core.setOutput).toHaveBeenNthCalledWith(3, 'major', 2)
expect(core.setOutput).toHaveBeenNthCalledWith(4, 'major-with-prefix', 'v2')
expect(core.setOutput).toHaveBeenNthCalledWith(5, 'minor', 3)
expect(core.setOutput).toHaveBeenNthCalledWith(6, 'patch', 4)
expect(core.setOutput).toHaveBeenNthCalledWith(7, 'bump', 'minor')
})
})

Expand Down

0 comments on commit 6772f33

Please sign in to comment.