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

Commit c23605f

Browse files
authored
fix: get the correct boolean value of the input (#233)
1 parent eea7db7 commit c23605f

File tree

3 files changed

+96
-27
lines changed

3 files changed

+96
-27
lines changed

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ inputs:
99
fork:
1010
description: 'should the PR be proposed from a fork (does not work with secrets.GITHUB_TOKEN)'
1111
required: false
12+
default: false
1213
clean:
1314
description: 'Should stale release PRs be closed post release? Defaults to true'
1415
required: false
16+
default: true
1517
package-name:
1618
description: 'name of the distributions releases are being created for, e.g., "name" in package.json, or "setup.py"'
1719
required: true
@@ -21,27 +23,35 @@ inputs:
2123
bump-minor-pre-major:
2224
description: 'should breaking changes before 1.0.0 produce minor bumps'
2325
required: false
26+
default: false
2427
path:
2528
description: "create a release from a path other than the repository's root"
2629
required: false
30+
default: ''
2731
monorepo-tags:
2832
description: 'add prefix to tags and branches, allowing multiple libraries to be released from the same repository'
2933
required: false
34+
default: false
3035
changelog-path:
3136
description: 'specify a CHANGELOG path other than the root CHANGELOG.md'
3237
required: false
38+
default: ''
3339
changelog-types:
3440
description: 'changlelog commit types'
3541
required: false
42+
default: ''
3643
command:
3744
description: 'release-please command to run, either "github-release", or "release-pr" (defaults to running both)'
3845
required: false
46+
default: ''
3947
version-file:
4048
description: 'provide a path to a version file to increment (used by ruby releaser)'
4149
required: false
50+
default: ''
4251
default-branch:
4352
description: 'branch to open pull release PR against (detected by default)'
4453
required: false
54+
default: ''
4555
runs:
4656
using: 'node12'
4757
main: 'dist/index.js'

index.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@ const RELEASE_LABEL = 'autorelease: pending'
55
const GITHUB_RELEASE_COMMAND = 'github-release'
66
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
77

8+
function getBooleanInput (input) {
9+
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
10+
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
11+
const stringInput = core.getInput(input)
12+
if (trueValue.indexOf(stringInput) > -1) return true
13+
if (falseValue.indexOf(stringInput) > -1) return false
14+
throw TypeError(`Wrong boolean value of the input '${input}'`)
15+
}
16+
817
async function main () {
9-
const bumpMinorPreMajor = Boolean(core.getInput('bump-minor-pre-major'))
10-
const monorepoTags = Boolean(core.getInput('monorepo-tags'))
11-
const packageName = core.getInput('package-name')
12-
const path = core.getInput('path') ? core.getInput('path') : undefined
13-
const releaseType = core.getInput('release-type')
14-
const token = core.getInput('token')
15-
const fork = core.getInput('fork') ? true : undefined
16-
const changelogPath = core.getInput('changelog-path') ? core.getInput('changelog-path') : undefined
18+
const bumpMinorPreMajor = getBooleanInput('bump-minor-pre-major')
19+
const monorepoTags = getBooleanInput('monorepo-tags')
20+
const packageName = core.getInput('package-name', { required: true })
21+
const path = core.getInput('path') || undefined
22+
const releaseType = core.getInput('release-type', { required: true })
23+
const token = core.getInput('token', { required: true })
24+
const fork = getBooleanInput('fork')
25+
const changelogPath = core.getInput('changelog-path') || undefined
1726
const changelogTypes = core.getInput('changelog-types')
18-
const command = core.getInput('command') ? core.getInput('command') : undefined
19-
const versionFile = core.getInput('version-file') ? core.getInput('version-file') : undefined
20-
const defaultBranch = core.getInput('default-branch') ? core.getInput('default-branch') : undefined
21-
22-
// Parse the changelogTypes if there are any
23-
let changelogSections
24-
if (changelogTypes) {
25-
changelogSections = JSON.parse(changelogTypes)
26-
}
27+
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
28+
const command = core.getInput('command') || undefined
29+
const versionFile = core.getInput('version-file') || undefined
30+
const defaultBranch = core.getInput('default-branch') || undefined
2731

2832
// First we check for any merged release PRs (PRs merged with the label
2933
// "autorelease: pending"):
@@ -74,7 +78,8 @@ async function main () {
7478
}
7579

7680
const releasePlease = {
77-
main
81+
main,
82+
getBooleanInput
7883
}
7984

8085
if (require.main === module) {

test/release-please.js

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ const core = require('@actions/core')
55
const sinon = require('sinon')
66
const { factory, GitHubRelease } = require('release-please/build/src')
77
const { Node } = require('release-please/build/src/releasers/node')
8+
// As defined in action.yml
9+
const defaultInput = {
10+
fork: 'false',
11+
clean: 'true',
12+
'bump-minor-pre-major': 'false',
13+
path: '',
14+
'monorepo-tags': 'false',
15+
'changelog-path': '',
16+
'changelog-types': '',
17+
command: '',
18+
'version-file': '',
19+
'default-branch': ''
20+
}
821

922
const sandbox = sinon.createSandbox()
1023
process.env.GITHUB_REPOSITORY = 'google/cloud'
@@ -14,6 +27,47 @@ describe('release-please-action', () => {
1427
sandbox.restore()
1528
})
1629

30+
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
31+
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
32+
33+
trueValue.forEach(value => {
34+
it(`get the boolean true with the input of '${value}'`, () => {
35+
const input = {
36+
fork: value
37+
}
38+
core.getInput = (name) => {
39+
return input[name] || defaultInput[name]
40+
}
41+
const actual = action.getBooleanInput('fork')
42+
assert.strictEqual(actual, true)
43+
})
44+
})
45+
46+
falseValue.forEach(value => {
47+
it(`get the boolean with the input of '${value}'`, () => {
48+
const input = {
49+
fork: value
50+
}
51+
core.getInput = (name) => {
52+
return input[name] || defaultInput[name]
53+
}
54+
const actual = action.getBooleanInput('fork')
55+
assert.strictEqual(actual, false)
56+
})
57+
})
58+
59+
it('get an error when inputting the wrong boolean value', () => {
60+
const input = {
61+
fork: 'wrong'
62+
}
63+
core.getInput = (name) => {
64+
return input[name] || defaultInput[name]
65+
}
66+
assert.throws(() => {
67+
action.getBooleanInput('fork')
68+
}, { name: 'TypeError', message: 'Wrong boolean value of the input \'fork\'' })
69+
})
70+
1771
it('both opens PR to the default branch and tags GitHub releases by default', async () => {
1872
const output = {}
1973
core.setOutput = (name, value) => {
@@ -23,7 +77,7 @@ describe('release-please-action', () => {
2377
'release-type': 'node'
2478
}
2579
core.getInput = (name) => {
26-
return input[name]
80+
return input[name] || defaultInput[name]
2781
}
2882

2983
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -61,7 +115,7 @@ describe('release-please-action', () => {
61115
'default-branch': 'dev'
62116
}
63117
core.getInput = (name) => {
64-
return input[name]
118+
return input[name] || defaultInput[name]
65119
}
66120

67121
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -100,7 +154,7 @@ describe('release-please-action', () => {
100154
command: 'release-pr'
101155
}
102156
core.getInput = (name) => {
103-
return input[name]
157+
return input[name] || defaultInput[name]
104158
}
105159

106160
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -129,7 +183,7 @@ describe('release-please-action', () => {
129183
command: 'github-release'
130184
}
131185
core.getInput = (name) => {
132-
return input[name]
186+
return input[name] || defaultInput[name]
133187
}
134188

135189
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -170,7 +224,7 @@ describe('release-please-action', () => {
170224
command: 'github-release'
171225
}
172226
core.getInput = (name) => {
173-
return input[name]
227+
return input[name] || defaultInput[name]
174228
}
175229

176230
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -195,7 +249,7 @@ describe('release-please-action', () => {
195249
command: 'release-pr'
196250
}
197251
core.getInput = (name) => {
198-
return input[name]
252+
return input[name] || defaultInput[name]
199253
}
200254

201255
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -217,7 +271,7 @@ describe('release-please-action', () => {
217271
command: 'release-pr'
218272
}
219273
core.getInput = (name) => {
220-
return input[name]
274+
return input[name] || defaultInput[name]
221275
}
222276

223277
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -239,7 +293,7 @@ describe('release-please-action', () => {
239293
command: 'release-pr'
240294
}
241295
core.getInput = (name) => {
242-
return input[name]
296+
return input[name] || defaultInput[name]
243297
}
244298
await action.main()
245299
assert.ok(maybeReleasePR instanceof Node)
@@ -255,7 +309,7 @@ describe('release-please-action', () => {
255309
command: 'github-release'
256310
}
257311
core.getInput = (name) => {
258-
return input[name]
312+
return input[name] || defaultInput[name]
259313
}
260314
await action.main()
261315
assert.ok(maybeGitHubRelease instanceof GitHubRelease)

0 commit comments

Comments
 (0)