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

Commit 4845e49

Browse files
authoredJan 31, 2021
feat(release-please): add default branch input option (#202)
1 parent a9e0f67 commit 4845e49

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Automate releases with Conventional Commit Messages.
4646
| `version-file` | provide a path to a version file to increment (used by ruby releaser) |
4747
| `fork` | Should the PR be created from a fork (does not work with `secrets.GITHUB_TOKEN`) |
4848
| `command` | release-please command to run, either `github-release`, or `release-pr` (_defaults to running both_) |
49+
| `default-branch` | branch to open pull release PR against (detected by default) |
4950

5051
| output | description |
5152
|:---:|---|

‎action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ inputs:
3838
version-file:
3939
description: 'provide a path to a version file to increment (used by ruby releaser)'
4040
required: false
41+
default-branch:
42+
description: 'branch to open pull release PR against (detected by default)'
43+
required: false
4144
runs:
4245
using: 'node12'
4346
main: 'dist/index.js'

‎index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function main () {
1616
const changelogTypes = core.getInput('changelog-types')
1717
const command = core.getInput('command') ? core.getInput('command') : undefined
1818
const versionFile = core.getInput('version-file') ? core.getInput('version-file') : undefined
19+
const defaultBranch = core.getInput('default-branch') ? core.getInput('default-branch') : undefined
1920

2021
// Parse the changelogTypes if there are any
2122
let changelogSections
@@ -60,7 +61,8 @@ async function main () {
6061
label: RELEASE_LABEL,
6162
bumpMinorPreMajor,
6263
changelogSections,
63-
versionFile
64+
versionFile,
65+
defaultBranch
6466
})
6567
const pr = await release.run()
6668
if (pr) {

‎test/release-please.js

+48-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const core = require('@actions/core')
55
const sinon = require('sinon')
66

77
describe('release-please-action', () => {
8-
it('both opens PR and tags GitHub releases by default', async () => {
8+
it('both opens PR to the default branch and tags GitHub releases by default', async () => {
99
const output = {}
1010
core.setOutput = (name, value) => {
1111
output[name] = value
@@ -26,17 +26,59 @@ describe('release-please-action', () => {
2626
return Release
2727
}
2828
const releasePR = sinon.stub().returns(25)
29+
const buildStatic = sinon.stub().returns({
30+
run: releasePR
31+
})
2932
action.getReleasePRFactory = () => {
3033
return {
31-
buildStatic: () => {
32-
return {
33-
run: releasePR
34-
}
35-
}
34+
buildStatic
35+
}
36+
}
37+
await action.main()
38+
sinon.assert.calledOnce(createRelease)
39+
sinon.assert.calledWith(buildStatic, 'node', sinon.match.hasOwn('defaultBranch', undefined))
40+
sinon.assert.calledOnce(releasePR)
41+
assert.deepStrictEqual(output, {
42+
release_created: true,
43+
upload_url: 'http://example.com',
44+
tag_name: 'v1.0.0',
45+
pr: 25
46+
})
47+
})
48+
49+
it('both opens PR to a different default branch and tags GitHub releases by default', async () => {
50+
const output = {}
51+
core.setOutput = (name, value) => {
52+
output[name] = value
53+
}
54+
const input = {
55+
'release-type': 'node',
56+
'default-branch': 'dev'
57+
}
58+
core.getInput = (name) => {
59+
return input[name]
60+
}
61+
const createRelease = sinon.stub().returns({
62+
upload_url: 'http://example.com',
63+
tag_name: 'v1.0.0'
64+
})
65+
action.getGitHubRelease = () => {
66+
class Release {}
67+
Release.prototype.createRelease = createRelease
68+
return Release
69+
}
70+
const releasePR = sinon.stub().returns(25)
71+
const buildStatic = sinon.stub().returns({
72+
run: releasePR
73+
})
74+
action.getReleasePRFactory = () => {
75+
return {
76+
buildStatic
3677
}
3778
}
3879
await action.main()
3980
sinon.assert.calledOnce(createRelease)
81+
sinon.assert.calledWith(buildStatic, 'node', sinon.match.hasOwn('defaultBranch', 'dev'))
4082
sinon.assert.calledOnce(releasePR)
4183
assert.deepStrictEqual(output, {
4284
release_created: true,

0 commit comments

Comments
 (0)
This repository has been archived.