Skip to content

Commit

Permalink
Merge pull request #498 from /issues/497
Browse files Browse the repository at this point in the history
Fix #497: Support for release output
  • Loading branch information
madhead authored Sep 21, 2022
2 parents bd375d3 + 9c3165c commit dc1fa2d
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ jobs:
- run: npm install
- run: npm run all

- uses: ./
id: test-0
with:
version: wrong
- run: '[[ "" == "${{ steps.test-1.outputs.release }}" ]]'
- run: '[[ "" == "${{ steps.test-1.outputs.major }}" ]]'
- run: '[[ "" == "${{ steps.test-1.outputs.minor }}" ]]'
- run: '[[ "" == "${{ steps.test-1.outputs.patch }}" ]]'
- run: '[[ "" == "${{ steps.test-1.outputs.any_other_property }}" ]]'

- uses: ./
id: test-1
with:
version: 1.2.3-alpha.gamma+4.5.6
- run: '[[ "1.2.3" == "${{ steps.test-1.outputs.release }}" ]]'
- run: '[[ "1" == "${{ steps.test-1.outputs.major }}" ]]'
- run: '[[ "2" == "${{ steps.test-1.outputs.minor }}" ]]'
- run: '[[ "3" == "${{ steps.test-1.outputs.patch }}" ]]'
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ A wrapper around [semver](https://www.npmjs.com/package/semver), so read [its do
# A range to check against
satisfies: 1.x
- run: |
echo "${{ steps.version.outputs.release }}" # 1.2.3
echo "${{ steps.version.outputs.major }}" # 1
echo "${{ steps.version.outputs.minor }}" # 2
echo "${{ steps.version.outputs.patch }}" # 3
Expand All @@ -42,6 +43,8 @@ A wrapper around [semver](https://www.npmjs.com/package/semver), so read [its do
echo "${{ steps.version.outputs.inc-prerelease }}" # 1.2.4-0
```
If the version cannot be parsed, all the outputs [will be equal to an empty string](.github/workflows/default.yml#L18-L26).
If any of the inputs cannot be parsed, it is just silently ignored.
This action tries its best not to fail.
Expand Down
2 changes: 2 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('parse', () => {
const parsedVersion = parse(item.version)

if (parsedVersion) {
expect(stdout).toContain(`::set-output name=release::${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}`)
expect(stdout).toContain(`::set-output name=major::${parsedVersion.major}`)
expect(stdout).toContain(`::set-output name=minor::${parsedVersion.minor}`)
expect(stdout).toContain(`::set-output name=patch::${parsedVersion.patch}`)
Expand All @@ -128,6 +129,7 @@ describe('parse', () => {
})
}
} else {
expect(stdout).not.toContain(`::set-output name=release::`)
expect(stdout).not.toContain(`::set-output name=major::`)
expect(stdout).not.toContain(`::set-output name=minor::`)
expect(stdout).not.toContain(`::set-output name=patch::`)
Expand Down
2 changes: 2 additions & 0 deletions action-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ inputs:
identifier:
type: string
outputs:
release:
type: string
major:
type: string
minor:
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ inputs:
required: false
description: An identifier to pass to the semver's inc function
outputs:
release:
description: Version's release (major.minor.patch)
major:
description: Version's major number
minor:
Expand Down
1 change: 1 addition & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "semver-utils",
"version": "2.2.0",
"version": "2.3.0",
"private": true,
"description": "One-stop shop for working with semantic versions in your workflows",
"main": "lib/main.js",
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function run(): Promise<void> {
return
}

core.setOutput('release', `${version.major}.${version.minor}.${version.patch}`)
core.setOutput('major', version.major)
core.setOutput('minor', version.minor)
core.setOutput('patch', version.patch)
Expand Down

0 comments on commit dc1fa2d

Please sign in to comment.