mirror of https://github.com/actions/toolkit
parent
05b1b08f77
commit
713902387e
|
@ -4,45 +4,51 @@
|
|||
|
||||
## Usage
|
||||
|
||||
#### Inputs/Outputs
|
||||
|
||||
You can use this library to get inputs or set outputs:
|
||||
### Import the package
|
||||
|
||||
```js
|
||||
// javascript
|
||||
const core = require('@actions/core');
|
||||
|
||||
const myInput = core.getInput('inputName', { required: true });
|
||||
// typescript
|
||||
import * as core from '@actions/core';
|
||||
```
|
||||
|
||||
// Do stuff
|
||||
#### Inputs/Outputs
|
||||
|
||||
Action inputs can be read with `getInput`. Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
|
||||
|
||||
```js
|
||||
const myInput = core.getInput('inputName', { required: true });
|
||||
|
||||
core.setOutput('outputKey', 'outputVal');
|
||||
```
|
||||
|
||||
#### Exporting variables
|
||||
|
||||
You can also export variables for future steps. Variables get set in the environment.
|
||||
Since each step runs in a separate process, you can use `exportVariable` to add it to this step and future steps environment blocks.
|
||||
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
||||
// Do stuff
|
||||
|
||||
core.exportVariable('envVar', 'Val');
|
||||
```
|
||||
|
||||
Exporting a secret exports the variable but also registers the secret with the runner to ensure it is masked in logs.
|
||||
|
||||
```js
|
||||
core.exportSecret('myPassword', mypass);
|
||||
```
|
||||
|
||||
#### PATH Manipulation
|
||||
|
||||
You can explicitly add items to the path for all remaining steps in a workflow:
|
||||
To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `addPath`. The runner will prepend the path given to the jobs PATH.
|
||||
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
||||
core.addPath('pathToTool');
|
||||
core.addPath('/path/to/mytool');
|
||||
```
|
||||
|
||||
#### Exit codes
|
||||
|
||||
You should use this library to set the failing exit code for your action:
|
||||
You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
|
||||
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
@ -55,6 +61,8 @@ catch (err) {
|
|||
core.setFailed(`Action failed with error ${err}`);
|
||||
}
|
||||
|
||||
Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
|
||||
|
||||
```
|
||||
|
||||
#### Logging
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
# @actions/core Releases
|
||||
|
||||
### 1.1.2
|
||||
|
||||
- set-secret is now available for use [#141](https://github.com/actions/toolkit/issues/141)
|
||||
|
||||
### 1.1.1
|
||||
|
||||
- set-secret is now available for use [#141](https://github.com/actions/toolkit/issues/141)
|
||||
- Add support for action input variables with multiple spaces [#127](https://github.com/actions/toolkit/issues/127)
|
||||
- Switched ## commands to :: commands (should have no noticeable impact) [#110)(https://github.com/actions/toolkit/pull/110)
|
||||
|
||||
|
|
|
@ -125,11 +125,6 @@ describe('@actions/core', () => {
|
|||
assertWriteCalls([`::set-output name=some output,::some value${os.EOL}`])
|
||||
})
|
||||
|
||||
it('setNeutral sets the correct exit code', () => {
|
||||
core.setFailed('Failure message')
|
||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||
})
|
||||
|
||||
it('setFailure sets the correct exit code and failure message', () => {
|
||||
core.setFailed('Failure message')
|
||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@actions/core",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"description": "Actions core lib",
|
||||
"keywords": [
|
||||
"github",
|
||||
|
|
Loading…
Reference in New Issue