Skip to content

Commit

Permalink
Merge pull request #41 from HackerHappyHour/get-boolean-inputs
Browse files Browse the repository at this point in the history
Get boolean inputs
  • Loading branch information
LongLiveCHIEF authored Nov 29, 2020
2 parents ce9ac6b + 2801352 commit 26a0a43
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 14 deletions.
14 changes: 9 additions & 5 deletions __tests__/__data__/taggingStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ exports.scenarios = [
],
[
'foo/bar:1,foo/bar:1.0,foo/bar:1.0.0,foo/bar:latest',
{inputTags:'%X%,%X.Y%,%X.Y.Z%', tagName:'1.0.0', imageName: 'foo/bar', latest: true}
{inputTags:'%X%,%X.Y%,%X.Y.Z%', tagName:'1.0.0', imageName: 'foo/bar', latest: 'TRUE'}
],
[
'1,1.0,1.0.0,latest',
{inputTags:'%X%,%X.Y%,%X.Y.Z%', tagName:'1.0.0', latest: true}
{inputTags:'%X%,%X.Y%,%X.Y.Z%', tagName:'1.0.0', latest: 'truE'}
],
[
'1-foobar,1.0-foobar,1.0.0-foobar',
{inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0'}
],
[
'1-foobar,1.0-foobar,1.0.0-foobar,latest',{inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0', latest: true}
'1-foobar,1.0-foobar,1.0.0-foobar,latest',{inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0', latest: 'TRue'}
],
[
'hello/world:1-foobar,hello/world:1.0-foobar,hello/world:1.0.0-foobar,hello/world:latest',
{inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0', latest: true, imageName: 'hello/world'}
{inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0', latest: 'true', imageName: 'hello/world'}
],
[
'1-rc1,1.0-rc1,1.0.0-rc1',
Expand All @@ -41,6 +41,10 @@ exports.scenarios = [
],
[
'hello/world:1-rc1-foobar,hello/world:1.0-rc1-foobar,hello/world:1.0.0-rc1-foobar,hello/world:latest',
{latest: true, inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0rc1', imageName: 'hello/world'}
{latest: 'True', inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0rc1', imageName: 'hello/world'}
],
[
'hello/world:1-rc1-foobar,hello/world:1.0-rc1-foobar,hello/world:1.0.0-rc1-foobar',
{latest: 'false', inputTags:'%X%-foobar,%X.Y%-foobar,%X.Y.Z%-foobar', tagName:'1.0.0rc1', imageName: 'hello/world'}
],
]
8 changes: 8 additions & 0 deletions __tests__/__data__/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.getInputBooleanScenarios = [
['true', true],
['TRUE', true],
['TRUe', true],
['false', false],
['FALSE', false],
['fALse', false]
]
8 changes: 8 additions & 0 deletions __tests__/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {getInputBoolean} = require('../src/utils')
const {getInputBooleanScenarios} = require('./__data__/utils')

describe('getInputBoolean', () => {
test.each(getInputBooleanScenarios)('%s should be %s', (scenario, expected) => {
expect(getInputBoolean(scenario)).toBe(expected)
})
})
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ branding:
inputs:
latest:
description: 'whether or not to produce a latest tag'
required: true
default: false
required: false
default: 'false'
tags:
description: 'The tagging strategy for this run'
required: true
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const github = __webpack_require__(2943)
const {taggingStrategy} = __webpack_require__(1457)
const {getInputBoolean} = __webpack_require__(1440)

const inputTags = getInputBoolean(core.getInput('tags'))
const inputTags = core.getInput('tags')
const tagName = core.getInput('tag_name')
const latest = core.getInput('latest')
const latest = getInputBoolean(core.getInput('latest') || 'false')
const imageName = core.getInput('image_name')

try {
Expand Down Expand Up @@ -8042,7 +8042,7 @@ exports.taggingStrategy = ({inputTags, latest, tagName, imageName}) => {
return imageName ? [...tags, `${imageName}:${tag.tag}`] : [...tags, tag.tag]
}, [])

if(latest !== 'false'){
if(/true/i.test(latest)){
imageName ? outputTags.push(`${imageName}:latest`) : outputTags.push('latest')
}
return outputTags.join(',')
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const github = require('@actions/github')
const {taggingStrategy} = require('./src/taggingStrategy')
const {getInputBoolean} = require('./src/utils')

const inputTags = getInputBoolean(core.getInput('tags'))
const inputTags = core.getInput('tags')
const tagName = core.getInput('tag_name')
const latest = core.getInput('latest')
const latest = getInputBoolean(core.getInput('latest') || 'false')
const imageName = core.getInput('image_name')

try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tagging-strategy",
"version": "2.1.0",
"version": "2.1.1",
"description": "A github action for specifying tagging strategies for docker images using semver or other common docker tags",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/taggingStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.taggingStrategy = ({inputTags, latest, tagName, imageName}) => {
return imageName ? [...tags, `${imageName}:${tag.tag}`] : [...tags, tag.tag]
}, [])

if(latest !== 'false'){
if(/true/i.test(latest)){
imageName ? outputTags.push(`${imageName}:latest`) : outputTags.push('latest')
}
return outputTags.join(',')
Expand Down

0 comments on commit 26a0a43

Please sign in to comment.