Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core.getInput(): change input name replace regex to [ -]+ #1740

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
core: Update README.md I/O section
  • Loading branch information
rindeal committed May 23, 2024
commit ef2f9405ab66f76c710ba8549c2ea8fdcd2dd696
26 changes: 21 additions & 5 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ import * as core from '@actions/core';

#### Inputs/Outputs

Action inputs can be read with `getInput` which returns a `string` or `getBooleanInput` which parses a boolean based on the [yaml 1.2 specification](https://yaml.org/spec/1.2/spec.html#id2804923). If `required` set to be false, the input should have a default value in `action.yml`.
There are three functions to parse an action's input from the `INPUT_*` environment variables:

Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
- `getInput(name: string, options?: InputOptions): string`
- This function returns the input value as a string.

- `getBooleanInput(name: string, options?: InputOptions): boolean`
- This function parses the input value as a boolean, following the [YAML 1.2 specification](https://yaml.org/spec/1.2/spec.html#id2804923).

- `getMultilineInput(name: string, options?: InputOptions): string[]`
- This function parses the input value as an array of non-blank lines.

> Please note that in the input name, dashes and spaces are replaced with underscores and converted to uppercase when matching the INPUT_* environment variable.
> Consecutive dashes or spaces are merged into a single underscore.

If the `required` option is set to `false` and the input environment variable is not set, these functions will throw an error. To prevent this, `action.yml` should define a default value.

If the `trimWhitespace` option is set to `true`, `getInput()` and `getMultilineInput()` will trim whitespace from the returned values, and `getBooleanInput()` will trim whitespace before parsing the value.

To set outputs for downstream actions, use `setOutput(name: string, value: any): void`. Any data passed to this function will be available as action inputs for downstream actions, ensuring decoupling between actions. Non-string values will be converted to a string using `JSON.stringify()`.

```js
const myInput = core.getInput('inputName', { required: true });
const myBooleanInput = core.getBooleanInput('booleanInputName', { required: true });
const myMultilineInput = core.getMultilineInput('multilineInputName', { required: true });
const myBooleanInput = core.getBooleanInput('booleanInputName');
const myMultilineInput = core.getMultilineInput('multilineInputName', { trimWhitespace: true });
core.setOutput('outputKey', 'outputVal');
```

Expand Down Expand Up @@ -483,4 +499,4 @@ core.summary.emptyBuffer()

// Writes text in the buffer to the summary buffer file and empties the buffer, optionally overwriting all existing content in the summary file with buffer contents. Defaults to false.
core.summary.write({overwrite: true})
```
```