Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit c0f7d24

Browse files
author
Benjamin E. Coe
authored
feat: add additional outputs (#106)
Opening a release PR now outputs a release #. Creating a GitHub release outputs SemVer major/minor/patch values
1 parent dda9b7b commit c0f7d24

6 files changed

Lines changed: 114 additions & 30 deletions

File tree

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Automate releases with Conventional Commit Messages.
2020
release-please:
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: GoogleCloudPlatform/release-please-action@v2.7.0
23+
- uses: GoogleCloudPlatform/release-please-action@v2.8.0
2424
with:
2525
token: ${{ secrets.GITHUB_TOKEN }}
2626
release-type: node
@@ -44,14 +44,22 @@ Automate releases with Conventional Commit Messages.
4444
| `monorepo-tags` | add prefix to tags and branches, allowing multiple libraries to be released from the same repository. |
4545
| `changelog-types` | A JSON formatted String containing to override the outputted changlog sections |
4646
| `version-file` | provide a path to a version file to increment (used by ruby releaser) |
47+
| `fork` | Should the PR be created from a fork (does not work with `secrets.GITHUB_TOKEN`) |
48+
| `clean` | Should stale release PRs be closed post release? Default `true` |
49+
| `command` | release-please command to run, either `github-release`, or `release-pr` (_defaults to running both_) |
4750

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

5664
### Release types supported
5765

@@ -108,7 +116,7 @@ To output more commit information in the changelog, a JSON formatted String can
108116
release-please:
109117
runs-on: ubuntu-latest
110118
steps:
111-
- uses: GoogleCloudPlatform/release-please-action@v2.7.0
119+
- uses: GoogleCloudPlatform/release-please-action@v2.8.0
112120
with:
113121
token: ${{ secrets.GITHUB_TOKEN }}
114122
release-type: node
@@ -131,7 +139,7 @@ jobs:
131139
release-please:
132140
runs-on: ubuntu-latest
133141
steps:
134-
- uses: GoogleCloudPlatform/release-please-action@v2.7.0
142+
- uses: GoogleCloudPlatform/release-please-action@v2.8.0
135143
id: release
136144
with:
137145
token: ${{ secrets.GITHUB_TOKEN }}

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
fork:
99
description: 'should the PR be proposed from a fork (does not work with secrets.GITHUB_TOKEN)'
1010
required: false
11+
clean:
12+
description: 'Should stale release PRs be closed post release? Defaults to true'
13+
required: false
1114
package-name:
1215
description: 'name of the distributions releases are being created for, e.g., "name" in package.json, or "setup.py"'
1316
required: true

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const RELEASE_LABEL = 'autorelease: pending'
66

77
async function main () {
88
const bumpMinorPreMajor = Boolean(core.getInput('bump-minor-pre-major'))
9+
const clean = core.getInput('clean') ? true : undefined
910
const monorepoTags = Boolean(core.getInput('monorepo-tags'))
1011
const packageName = core.getInput('package-name')
1112
const path = core.getInput('path') ? core.getInput('path') : undefined
@@ -35,18 +36,18 @@ async function main () {
3536
})
3637
const releaseCreated = await gr.createRelease()
3738
if (releaseCreated) {
38-
// eslint-disable-next-line
39-
const { upload_url, tag_name } = releaseCreated
4039
core.setOutput('release_created', true)
41-
core.setOutput('upload_url', upload_url)
42-
core.setOutput('tag_name', tag_name)
40+
for (const key of Object.keys(releaseCreated)) {
41+
core.setOutput(key, releaseCreated[key])
42+
}
4343
}
4444
}
4545

4646
// Next we check for PRs merged since the last release, and groom the
4747
// release PR:
4848
if (!command || command === 'release-pr') {
4949
const release = releasePlease.getReleasePRFactory().buildStatic(releaseType, {
50+
clean,
5051
monorepoTags,
5152
packageName,
5253
path,
@@ -59,7 +60,8 @@ async function main () {
5960
changelogSections,
6061
versionFile
6162
})
62-
await release.run()
63+
const pr = await release.run()
64+
core.setOutput('pr', pr)
6365
}
6466
}
6567

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"homepage": "https://github.com/bcoe/release-please-action#readme",
2727
"dependencies": {
2828
"@actions/core": "^1.2.6",
29-
"release-please": "^6.9.0"
29+
"release-please": "^7.0.0-candidate.1"
3030
},
3131
"devDependencies": {
3232
"@zeit/ncc": "^0.22.3",

test/release-please.js

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ describe('release-please-action', () => {
4141
assert.deepStrictEqual(output, {
4242
release_created: true,
4343
upload_url: 'http://example.com',
44-
tag_name: 'v1.0.0'
44+
tag_name: 'v1.0.0',
45+
pr: undefined
4546
})
4647
})
4748

48-
it('only opens PRs if, command set to release-pr', async () => {
49+
it('only opens PR, if command set to release-pr', async () => {
4950
const output = {}
5051
core.setOutput = (name, value) => {
5152
output[name] = value
@@ -81,7 +82,7 @@ describe('release-please-action', () => {
8182
sinon.assert.calledOnce(releasePR)
8283
})
8384

84-
it('only opens tags releases, if command set to github-release', async () => {
85+
it('only creates GitHub release, if command set to github-release', async () => {
8586
const output = {}
8687
core.setOutput = (name, value) => {
8788
output[name] = value
@@ -116,4 +117,74 @@ describe('release-please-action', () => {
116117
sinon.assert.calledOnce(githubRelease)
117118
sinon.assert.notCalled(releasePR)
118119
})
120+
121+
it('sets approprite outputs when GitHub release created', async () => {
122+
const expected = {
123+
release_created: true,
124+
upload_url: 'http://example.com',
125+
html_url: 'http://example2.com',
126+
tag_name: 'v1.0.0',
127+
major: 1,
128+
minor: 2,
129+
patch: 3,
130+
version: 'v1.2.3',
131+
sha: 'abc123',
132+
pr: 33
133+
}
134+
const output = {}
135+
core.setOutput = (name, value) => {
136+
output[name] = value
137+
}
138+
const input = {
139+
'release-type': 'node',
140+
command: 'github-release'
141+
}
142+
core.getInput = (name) => {
143+
return input[name]
144+
}
145+
const githubRelease = sinon.stub().returns(expected)
146+
action.getGitHubRelease = () => {
147+
class Release {}
148+
Release.prototype.createRelease = githubRelease
149+
return Release
150+
}
151+
const releasePR = sinon.stub()
152+
action.getReleasePRFactory = () => {
153+
return {
154+
buildStatic: () => {
155+
return {
156+
run: releasePR
157+
}
158+
}
159+
}
160+
}
161+
await action.main()
162+
assert.deepStrictEqual(output, expected)
163+
})
164+
165+
it('sets appropriate outputs when release PR opened', async () => {
166+
const output = {}
167+
core.setOutput = (name, value) => {
168+
output[name] = value
169+
}
170+
const input = {
171+
'release-type': 'node',
172+
command: 'release-pr'
173+
}
174+
core.getInput = (name) => {
175+
return input[name]
176+
}
177+
const releasePR = sinon.stub().returns(95)
178+
action.getReleasePRFactory = () => {
179+
return {
180+
buildStatic: () => {
181+
return {
182+
run: releasePR
183+
}
184+
}
185+
}
186+
}
187+
await action.main()
188+
assert.strictEqual(output.pr, 95)
189+
})
119190
})

0 commit comments

Comments
 (0)