Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
feat: add additional outputs (#106)
Browse files Browse the repository at this point in the history
Opening a release PR now outputs a release #. Creating a GitHub release outputs
SemVer major/minor/patch values
  • Loading branch information
bcoe committed Nov 25, 2020
1 parent dda9b7b commit c0f7d24
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 30 deletions.
18 changes: 13 additions & 5 deletions README.md
Expand Up @@ -20,7 +20,7 @@ Automate releases with Conventional Commit Messages.
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2.7.0
- uses: GoogleCloudPlatform/release-please-action@v2.8.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
Expand All @@ -44,14 +44,22 @@ Automate releases with Conventional Commit Messages.
| `monorepo-tags` | add prefix to tags and branches, allowing multiple libraries to be released from the same repository. |
| `changelog-types` | A JSON formatted String containing to override the outputted changlog sections |
| `version-file` | provide a path to a version file to increment (used by ruby releaser) |
| `fork` | Should the PR be created from a fork (does not work with `secrets.GITHUB_TOKEN`) |
| `clean` | Should stale release PRs be closed post release? Default `true` |
| `command` | release-please command to run, either `github-release`, or `release-pr` (_defaults to running both_) |

| output | description |
|:---:|---|
| `release_created` | `true` if the release was created, `false` otherwise |
| `upload_url` | Directly related to [**Create a release**](https://developer.github.com/v3/repos/releases/#response-4) API |
| `html_url` | Directly related to [**Create a release**](https://developer.github.com/v3/repos/releases/#response-4) API |
| `tag_name` | Directly related to [**Create a release**](https://developer.github.com/v3/repos/releases/#response-4) API |
| `fork` | Should the PR be created from a fork (does not work with `secrets.GITHUB_TOKEN`) |
| `command` | release-please command to run, either `github-release`, or `release-pr` (_defaults to running both_) |
| `major` | Number representing major semver value |
| `minor` | Number representing minor semver value |
| `patch` | Number representing patch semver value |
| `sha` | sha that a GitHub release was tagged at |
| `pr` | The PR number of an opened release (undefined if no release created) |


### Release types supported

Expand Down Expand Up @@ -108,7 +116,7 @@ To output more commit information in the changelog, a JSON formatted String can
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2.7.0
- uses: GoogleCloudPlatform/release-please-action@v2.8.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
Expand All @@ -131,7 +139,7 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2.7.0
- uses: GoogleCloudPlatform/release-please-action@v2.8.0
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -8,6 +8,9 @@ inputs:
fork:
description: 'should the PR be proposed from a fork (does not work with secrets.GITHUB_TOKEN)'
required: false
clean:
description: 'Should stale release PRs be closed post release? Defaults to true'
required: false
package-name:
description: 'name of the distributions releases are being created for, e.g., "name" in package.json, or "setup.py"'
required: true
Expand Down
12 changes: 7 additions & 5 deletions index.js
Expand Up @@ -6,6 +6,7 @@ const RELEASE_LABEL = 'autorelease: pending'

async function main () {
const bumpMinorPreMajor = Boolean(core.getInput('bump-minor-pre-major'))
const clean = core.getInput('clean') ? true : undefined
const monorepoTags = Boolean(core.getInput('monorepo-tags'))
const packageName = core.getInput('package-name')
const path = core.getInput('path') ? core.getInput('path') : undefined
Expand Down Expand Up @@ -35,18 +36,18 @@ async function main () {
})
const releaseCreated = await gr.createRelease()
if (releaseCreated) {
// eslint-disable-next-line
const { upload_url, tag_name } = releaseCreated
core.setOutput('release_created', true)
core.setOutput('upload_url', upload_url)
core.setOutput('tag_name', tag_name)
for (const key of Object.keys(releaseCreated)) {
core.setOutput(key, releaseCreated[key])
}
}
}

// Next we check for PRs merged since the last release, and groom the
// release PR:
if (!command || command === 'release-pr') {
const release = releasePlease.getReleasePRFactory().buildStatic(releaseType, {
clean,
monorepoTags,
packageName,
path,
Expand All @@ -59,7 +60,8 @@ async function main () {
changelogSections,
versionFile
})
await release.run()
const pr = await release.run()
core.setOutput('pr', pr)
}
}

Expand Down
32 changes: 16 additions & 16 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
Expand Up @@ -26,7 +26,7 @@
"homepage": "https://github.com/bcoe/release-please-action#readme",
"dependencies": {
"@actions/core": "^1.2.6",
"release-please": "^6.9.0"
"release-please": "^7.0.0-candidate.1"
},
"devDependencies": {
"@zeit/ncc": "^0.22.3",
Expand Down
77 changes: 74 additions & 3 deletions test/release-please.js
Expand Up @@ -41,11 +41,12 @@ describe('release-please-action', () => {
assert.deepStrictEqual(output, {
release_created: true,
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
tag_name: 'v1.0.0',
pr: undefined
})
})

it('only opens PRs if, command set to release-pr', async () => {
it('only opens PR, if command set to release-pr', async () => {
const output = {}
core.setOutput = (name, value) => {
output[name] = value
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('release-please-action', () => {
sinon.assert.calledOnce(releasePR)
})

it('only opens tags releases, if command set to github-release', async () => {
it('only creates GitHub release, if command set to github-release', async () => {
const output = {}
core.setOutput = (name, value) => {
output[name] = value
Expand Down Expand Up @@ -116,4 +117,74 @@ describe('release-please-action', () => {
sinon.assert.calledOnce(githubRelease)
sinon.assert.notCalled(releasePR)
})

it('sets approprite outputs when GitHub release created', async () => {
const expected = {
release_created: true,
upload_url: 'http://example.com',
html_url: 'http://example2.com',
tag_name: 'v1.0.0',
major: 1,
minor: 2,
patch: 3,
version: 'v1.2.3',
sha: 'abc123',
pr: 33
}
const output = {}
core.setOutput = (name, value) => {
output[name] = value
}
const input = {
'release-type': 'node',
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
}
const githubRelease = sinon.stub().returns(expected)
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = githubRelease
return Release
}
const releasePR = sinon.stub()
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
}
}
await action.main()
assert.deepStrictEqual(output, expected)
})

it('sets appropriate outputs when release PR opened', async () => {
const output = {}
core.setOutput = (name, value) => {
output[name] = value
}
const input = {
'release-type': 'node',
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
}
const releasePR = sinon.stub().returns(95)
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
}
}
await action.main()
assert.strictEqual(output.pr, 95)
})
})

0 comments on commit c0f7d24

Please sign in to comment.