mirror of
https://github.com/joaquinjsb/gitea-release-please-action
synced 2026-05-13 22:31:37 +02:00
fix: get the correct boolean value of the input (#233)
This commit is contained in:
10
action.yml
10
action.yml
@@ -9,9 +9,11 @@ inputs:
|
|||||||
fork:
|
fork:
|
||||||
description: 'should the PR be proposed from a fork (does not work with secrets.GITHUB_TOKEN)'
|
description: 'should the PR be proposed from a fork (does not work with secrets.GITHUB_TOKEN)'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
clean:
|
clean:
|
||||||
description: 'Should stale release PRs be closed post release? Defaults to true'
|
description: 'Should stale release PRs be closed post release? Defaults to true'
|
||||||
required: false
|
required: false
|
||||||
|
default: true
|
||||||
package-name:
|
package-name:
|
||||||
description: 'name of the distributions releases are being created for, e.g., "name" in package.json, or "setup.py"'
|
description: 'name of the distributions releases are being created for, e.g., "name" in package.json, or "setup.py"'
|
||||||
required: true
|
required: true
|
||||||
@@ -21,27 +23,35 @@ inputs:
|
|||||||
bump-minor-pre-major:
|
bump-minor-pre-major:
|
||||||
description: 'should breaking changes before 1.0.0 produce minor bumps'
|
description: 'should breaking changes before 1.0.0 produce minor bumps'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
path:
|
path:
|
||||||
description: "create a release from a path other than the repository's root"
|
description: "create a release from a path other than the repository's root"
|
||||||
required: false
|
required: false
|
||||||
|
default: ''
|
||||||
monorepo-tags:
|
monorepo-tags:
|
||||||
description: 'add prefix to tags and branches, allowing multiple libraries to be released from the same repository'
|
description: 'add prefix to tags and branches, allowing multiple libraries to be released from the same repository'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
changelog-path:
|
changelog-path:
|
||||||
description: 'specify a CHANGELOG path other than the root CHANGELOG.md'
|
description: 'specify a CHANGELOG path other than the root CHANGELOG.md'
|
||||||
required: false
|
required: false
|
||||||
|
default: ''
|
||||||
changelog-types:
|
changelog-types:
|
||||||
description: 'changlelog commit types'
|
description: 'changlelog commit types'
|
||||||
required: false
|
required: false
|
||||||
|
default: ''
|
||||||
command:
|
command:
|
||||||
description: 'release-please command to run, either "github-release", or "release-pr" (defaults to running both)'
|
description: 'release-please command to run, either "github-release", or "release-pr" (defaults to running both)'
|
||||||
required: false
|
required: false
|
||||||
|
default: ''
|
||||||
version-file:
|
version-file:
|
||||||
description: 'provide a path to a version file to increment (used by ruby releaser)'
|
description: 'provide a path to a version file to increment (used by ruby releaser)'
|
||||||
required: false
|
required: false
|
||||||
|
default: ''
|
||||||
default-branch:
|
default-branch:
|
||||||
description: 'branch to open pull release PR against (detected by default)'
|
description: 'branch to open pull release PR against (detected by default)'
|
||||||
required: false
|
required: false
|
||||||
|
default: ''
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
43
index.js
43
index.js
@@ -5,25 +5,29 @@ const RELEASE_LABEL = 'autorelease: pending'
|
|||||||
const GITHUB_RELEASE_COMMAND = 'github-release'
|
const GITHUB_RELEASE_COMMAND = 'github-release'
|
||||||
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
|
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
|
||||||
|
|
||||||
async function main () {
|
function getBooleanInput (input) {
|
||||||
const bumpMinorPreMajor = Boolean(core.getInput('bump-minor-pre-major'))
|
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
|
||||||
const monorepoTags = Boolean(core.getInput('monorepo-tags'))
|
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
|
||||||
const packageName = core.getInput('package-name')
|
const stringInput = core.getInput(input)
|
||||||
const path = core.getInput('path') ? core.getInput('path') : undefined
|
if (trueValue.indexOf(stringInput) > -1) return true
|
||||||
const releaseType = core.getInput('release-type')
|
if (falseValue.indexOf(stringInput) > -1) return false
|
||||||
const token = core.getInput('token')
|
throw TypeError(`Wrong boolean value of the input '${input}'`)
|
||||||
const fork = core.getInput('fork') ? true : undefined
|
}
|
||||||
const changelogPath = core.getInput('changelog-path') ? 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
|
async function main () {
|
||||||
let changelogSections
|
const bumpMinorPreMajor = getBooleanInput('bump-minor-pre-major')
|
||||||
if (changelogTypes) {
|
const monorepoTags = getBooleanInput('monorepo-tags')
|
||||||
changelogSections = JSON.parse(changelogTypes)
|
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 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
|
// First we check for any merged release PRs (PRs merged with the label
|
||||||
// "autorelease: pending"):
|
// "autorelease: pending"):
|
||||||
@@ -74,7 +78,8 @@ async function main () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const releasePlease = {
|
const releasePlease = {
|
||||||
main
|
main,
|
||||||
|
getBooleanInput
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|||||||
@@ -5,6 +5,19 @@ const core = require('@actions/core')
|
|||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const { factory, GitHubRelease } = require('release-please/build/src')
|
const { factory, GitHubRelease } = require('release-please/build/src')
|
||||||
const { Node } = require('release-please/build/src/releasers/node')
|
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()
|
const sandbox = sinon.createSandbox()
|
||||||
process.env.GITHUB_REPOSITORY = 'google/cloud'
|
process.env.GITHUB_REPOSITORY = 'google/cloud'
|
||||||
@@ -14,6 +27,47 @@ describe('release-please-action', () => {
|
|||||||
sandbox.restore()
|
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 () => {
|
it('both opens PR to the default branch and tags GitHub releases by default', async () => {
|
||||||
const output = {}
|
const output = {}
|
||||||
core.setOutput = (name, value) => {
|
core.setOutput = (name, value) => {
|
||||||
@@ -23,7 +77,7 @@ describe('release-please-action', () => {
|
|||||||
'release-type': 'node'
|
'release-type': 'node'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -61,7 +115,7 @@ describe('release-please-action', () => {
|
|||||||
'default-branch': 'dev'
|
'default-branch': 'dev'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -100,7 +154,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'release-pr'
|
command: 'release-pr'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -129,7 +183,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'github-release'
|
command: 'github-release'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -170,7 +224,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'github-release'
|
command: 'github-release'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -195,7 +249,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'release-pr'
|
command: 'release-pr'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -217,7 +271,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'release-pr'
|
command: 'release-pr'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||||
@@ -239,7 +293,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'release-pr'
|
command: 'release-pr'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
await action.main()
|
await action.main()
|
||||||
assert.ok(maybeReleasePR instanceof Node)
|
assert.ok(maybeReleasePR instanceof Node)
|
||||||
@@ -255,7 +309,7 @@ describe('release-please-action', () => {
|
|||||||
command: 'github-release'
|
command: 'github-release'
|
||||||
}
|
}
|
||||||
core.getInput = (name) => {
|
core.getInput = (name) => {
|
||||||
return input[name]
|
return input[name] || defaultInput[name]
|
||||||
}
|
}
|
||||||
await action.main()
|
await action.main()
|
||||||
assert.ok(maybeGitHubRelease instanceof GitHubRelease)
|
assert.ok(maybeGitHubRelease instanceof GitHubRelease)
|
||||||
|
|||||||
Reference in New Issue
Block a user