Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add additional outputs #106

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"homepage": "https:/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
Original file line number Diff line number Diff line change
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)
})
})