Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
action-input-parser
Advanced tools
core.getInput()
.env
files) during developmentInstall action-input-parser via npm:
npm install action-input-parser
Import action-input-parser
and use it like this:
const parser = require('action-input-parser')
const value = parser.getInput('name')
Let's say you have the following workflow file (see below on how to specify inputs during development):
uses: username/action
with:
names: |
Maximilian
Richard
Pass an options object to the getInput
function to specify the array
type:
const parser = require('action-input-parser')
const value = parser.getInput('names', {
type: 'array'
})
// [ 'Maximilian', 'Richard' ]
action-input-parser will parse the names
input and return an array.
See below for all options or checkout a few more examples.
You can pass the following JavaScript object to getInput
as the first or second parameter to tell action-input-parser what to parse:
const options = {
key: 'names',
type: 'array',
default: [ 'maximilian' ]
}
parser.getInput(options)
Here are all the options you can use and there default values:
Name | Description | Required | Default |
---|---|---|---|
key | The key of the input option (can also be an array of keys) | Yes | N/A |
type | The type of the input value (string /boolean /number /array ) | No | string |
required | Specify if the input is required | No | false |
default | Specify a default value for the input | No | N/A |
disableable | Specify if the input should be able to be disabled by setting it to false | No | false |
modifier | A function which gets passed the parsed value as a parameter and returns another value | No | N/A |
You can either specify a single key as a string, or multiple keys as an array of strings.
You can specify one of the following types which will determine how the input is parsed:
string
- default type, the input value will only be trimmedboolean
- will parse a boolean based on the yaml 1.2 specificationnumber
- will convert the input to a numberarray
- will parse line or comma seperated values to an arrayNote: if the input can not be converted to the specifed type, an error is thrown
When you set required to true and the input is not set, action-input-parser will throw an error.
You can specify a default value for the input which will be used when the input is not set.
If you have an input with a default value but you still want the user to be able to unset the input, set the disableable
option to true
.
When the input is then set to false
, action-input-parser will return undefined
instead of your default value.
If your input needs additional processing you can specify a function which will be passed the parsed input value.
If you run your Action locally during development, you can set the inputs as environment variables or specify them in a .env
file. action-input-parser will use them as the inputs automatically.
Here are some examples on how to use action-input-parser:
Action Workflow:
uses: username/action
with:
name: Maximilian
Action code:
const parser = require('action-input-parser')
const value = parser.getInput('name')
// value -> Maximilian
or
const parser = require('action-input-parser')
const value = parser.getInput({
key: 'name'
})
// value -> Maximilian
Action Workflow:
uses: username/action
with:
dry_run: true
Action code:
const parser = require('action-input-parser')
const value = parser.getInput({
key: 'dry_run',
type: 'boolean'
})
// Without setting the type to boolean, the value would have been 'true'
Action code:
const parser = require('action-input-parser')
const value = parser.getInput({
key: 'name',
default: 'Maximilian'
})
// If name is not set, Maximilian will be returned as the name
Action code:
const parser = require('action-input-parser')
const value = parser.getInput({
key: 'name',
required: true
})
// Will throw an error if name is not set
Action Workflow:
uses: username/action
with:
labels: false
Action code:
const parser = require('action-input-parser')
const value = parser.getInput({
key: 'labels',
default: [ 'merged', 'ready' ],
disableable: true
})
// Value will be undefined because labels was set to false
Action code:
const parser = require('action-input-parser')
const value = parser.getInput({
key: [ 'GITHUB_TOKEN', 'GH_PAT' ]
})
// The first key takes precedence
Action Workflow:
uses: username/action
with:
name: Maximilian
Action code:
const parser = require('action-input-parser')
const value = parser.getInput({
key: 'name',
modifier: (val) => {
return val.toLowerCase()
}
})
// Value will be maximilian
Action Workflow:
uses: username/action
with:
github_token: TOKEN
repository: username/reponame
labels: |
merged
ready
Action code:
const { getInput } = require('action-input-parser')
const config = {
githubToken: getInput({
key: 'github_token',
required: true
}),
repository: getInput({
key: 'repository',
modifier: (val) => {
const [user, repo] = val.split('/')
return { user, repo }
}
}),
labels: getInput({
key: 'labels',
type: 'array'
}),
dryRun: getInput({
key: 'dry_run',
type: 'boolean',
default: false
}),
}
// parsed config:
{
githubToken: 'TOKEN',
repository: {
name: 'username',
repo: 'reponame'
},
labels: [ 'merged', 'ready' ],
dryRun: false
}
Issues and PRs are very welcome!
The actual source code of this library is in the src
folder.
yarn lint
or npm run lint
to run eslint.yarn build
or npm run build
to produce a compiled version in the lib
folder.This project was developed by me (@betahuhn) in my free time. If you want to support me:
Copyright 2021 Maximilian Schiller
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Helper for parsing inputs in a GitHub Action
The npm package action-input-parser receives a total of 33 weekly downloads. As such, action-input-parser popularity was classified as not popular.
We found that action-input-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.