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

Commit

Permalink
fix: get the correct boolean value of the input (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-Xu-0100 committed Feb 17, 2021
1 parent eea7db7 commit c23605f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 27 deletions.
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ inputs:
fork:
description: 'should the PR be proposed from a fork (does not work with secrets.GITHUB_TOKEN)'
required: false
default: false
clean:
description: 'Should stale release PRs be closed post release? Defaults to true'
required: false
default: true
package-name:
description: 'name of the distributions releases are being created for, e.g., "name" in package.json, or "setup.py"'
required: true
Expand All @@ -21,27 +23,35 @@ inputs:
bump-minor-pre-major:
description: 'should breaking changes before 1.0.0 produce minor bumps'
required: false
default: false
path:
description: "create a release from a path other than the repository's root"
required: false
default: ''
monorepo-tags:
description: 'add prefix to tags and branches, allowing multiple libraries to be released from the same repository'
required: false
default: false
changelog-path:
description: 'specify a CHANGELOG path other than the root CHANGELOG.md'
required: false
default: ''
changelog-types:
description: 'changlelog commit types'
required: false
default: ''
command:
description: 'release-please command to run, either "github-release", or "release-pr" (defaults to running both)'
required: false
default: ''
version-file:
description: 'provide a path to a version file to increment (used by ruby releaser)'
required: false
default: ''
default-branch:
description: 'branch to open pull release PR against (detected by default)'
required: false
default: ''
runs:
using: 'node12'
main: 'dist/index.js'
41 changes: 23 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ const RELEASE_LABEL = 'autorelease: pending'
const GITHUB_RELEASE_COMMAND = 'github-release'
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'

function getBooleanInput (input) {
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
const stringInput = core.getInput(input)
if (trueValue.indexOf(stringInput) > -1) return true
if (falseValue.indexOf(stringInput) > -1) return false
throw TypeError(`Wrong boolean value of the input '${input}'`)
}

async function main () {
const bumpMinorPreMajor = Boolean(core.getInput('bump-minor-pre-major'))
const monorepoTags = Boolean(core.getInput('monorepo-tags'))
const packageName = core.getInput('package-name')
const path = core.getInput('path') ? core.getInput('path') : undefined
const releaseType = core.getInput('release-type')
const token = core.getInput('token')
const fork = core.getInput('fork') ? true : undefined
const changelogPath = core.getInput('changelog-path') ? core.getInput('changelog-path') : undefined
const bumpMinorPreMajor = getBooleanInput('bump-minor-pre-major')
const monorepoTags = getBooleanInput('monorepo-tags')
const packageName = core.getInput('package-name', { required: true })
const path = core.getInput('path') || undefined
const releaseType = core.getInput('release-type', { required: true })
const token = core.getInput('token', { required: true })
const fork = getBooleanInput('fork')
const changelogPath = core.getInput('changelog-path') || undefined
const changelogTypes = core.getInput('changelog-types')
const command = core.getInput('command') ? core.getInput('command') : undefined
const versionFile = core.getInput('version-file') ? core.getInput('version-file') : undefined
const defaultBranch = core.getInput('default-branch') ? core.getInput('default-branch') : undefined

// Parse the changelogTypes if there are any
let changelogSections
if (changelogTypes) {
changelogSections = JSON.parse(changelogTypes)
}
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
const command = core.getInput('command') || undefined
const versionFile = core.getInput('version-file') || undefined
const defaultBranch = core.getInput('default-branch') || undefined

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

const releasePlease = {
main
main,
getBooleanInput
}

if (require.main === module) {
Expand Down
72 changes: 63 additions & 9 deletions test/release-please.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ const core = require('@actions/core')
const sinon = require('sinon')
const { factory, GitHubRelease } = require('release-please/build/src')
const { Node } = require('release-please/build/src/releasers/node')
// As defined in action.yml
const defaultInput = {
fork: 'false',
clean: 'true',
'bump-minor-pre-major': 'false',
path: '',
'monorepo-tags': 'false',
'changelog-path': '',
'changelog-types': '',
command: '',
'version-file': '',
'default-branch': ''
}

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

const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']

trueValue.forEach(value => {
it(`get the boolean true with the input of '${value}'`, () => {
const input = {
fork: value
}
core.getInput = (name) => {
return input[name] || defaultInput[name]
}
const actual = action.getBooleanInput('fork')
assert.strictEqual(actual, true)
})
})

falseValue.forEach(value => {
it(`get the boolean with the input of '${value}'`, () => {
const input = {
fork: value
}
core.getInput = (name) => {
return input[name] || defaultInput[name]
}
const actual = action.getBooleanInput('fork')
assert.strictEqual(actual, false)
})
})

it('get an error when inputting the wrong boolean value', () => {
const input = {
fork: 'wrong'
}
core.getInput = (name) => {
return input[name] || defaultInput[name]
}
assert.throws(() => {
action.getBooleanInput('fork')
}, { name: 'TypeError', message: 'Wrong boolean value of the input \'fork\'' })
})

it('both opens PR to the default branch and tags GitHub releases by default', async () => {
const output = {}
core.setOutput = (name, value) => {
Expand All @@ -23,7 +77,7 @@ describe('release-please-action', () => {
'release-type': 'node'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand Down Expand Up @@ -61,7 +115,7 @@ describe('release-please-action', () => {
'default-branch': 'dev'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand Down Expand Up @@ -100,7 +154,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand Down Expand Up @@ -129,7 +183,7 @@ describe('release-please-action', () => {
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand Down Expand Up @@ -170,7 +224,7 @@ describe('release-please-action', () => {
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand All @@ -195,7 +249,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand All @@ -217,7 +271,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}

const runCommandStub = sandbox.stub(factory, 'runCommand')
Expand All @@ -239,7 +293,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
await action.main()
assert.ok(maybeReleasePR instanceof Node)
Expand All @@ -255,7 +309,7 @@ describe('release-please-action', () => {
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
await action.main()
assert.ok(maybeGitHubRelease instanceof GitHubRelease)
Expand Down

0 comments on commit c23605f

Please sign in to comment.