mirror of https://github.com/actions/toolkit
parent
05b1b08f77
commit
713902387e
|
@ -4,45 +4,51 @@
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
#### Inputs/Outputs
|
### Import the package
|
||||||
|
|
||||||
You can use this library to get inputs or set outputs:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
// javascript
|
||||||
const core = require('@actions/core');
|
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');
|
core.setOutput('outputKey', 'outputVal');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Exporting variables
|
#### 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
|
```js
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
// Do stuff
|
|
||||||
|
|
||||||
core.exportVariable('envVar', 'Val');
|
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
|
#### 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
|
```js
|
||||||
const core = require('@actions/core');
|
core.addPath('/path/to/mytool');
|
||||||
|
|
||||||
core.addPath('pathToTool');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Exit codes
|
#### 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
|
```js
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
@ -55,6 +61,8 @@ catch (err) {
|
||||||
core.setFailed(`Action failed with error ${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
|
#### Logging
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
# @actions/core Releases
|
# @actions/core Releases
|
||||||
|
|
||||||
|
### 1.1.2
|
||||||
|
|
||||||
|
- set-secret is now available for use [#141](https://github.com/actions/toolkit/issues/141)
|
||||||
|
|
||||||
### 1.1.1
|
### 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)
|
- 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)
|
- 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}`])
|
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', () => {
|
it('setFailure sets the correct exit code and failure message', () => {
|
||||||
core.setFailed('Failure message')
|
core.setFailed('Failure message')
|
||||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@actions/core",
|
"name": "@actions/core",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"description": "Actions core lib",
|
"description": "Actions core lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
|
|
Loading…
Reference in New Issue