mirror of https://github.com/actions/toolkit
Add the "@actions/exit" package
It is useful to have the exit logic separated into its own packagepull/1/head
parent
1e32709630
commit
cca9523c73
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright 2019 GitHub
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,11 @@
|
||||||
|
# `@actions/exit`
|
||||||
|
|
||||||
|
> TODO: description
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
const exit = require('@actions/exit');
|
||||||
|
|
||||||
|
// TODO: DEMONSTRATE API
|
||||||
|
```
|
|
@ -0,0 +1,19 @@
|
||||||
|
import * as exit from '../src/exit'
|
||||||
|
|
||||||
|
it('exits successfully', () => {
|
||||||
|
jest.spyOn(process, 'exit').mockImplementation()
|
||||||
|
exit.success()
|
||||||
|
expect(process.exit).toHaveBeenCalledWith(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exits as a failure', () => {
|
||||||
|
jest.spyOn(process, 'exit').mockImplementation()
|
||||||
|
exit.failure()
|
||||||
|
expect(process.exit).toHaveBeenCalledWith(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exits neutrally', () => {
|
||||||
|
jest.spyOn(process, 'exit').mockImplementation()
|
||||||
|
exit.neutral()
|
||||||
|
expect(process.exit).toHaveBeenCalledWith(78)
|
||||||
|
})
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "@actions/exit",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"lockfileVersion": 1
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"name": "@actions/exit",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Functions for safely exiting from GitHub Actions",
|
||||||
|
"main": "lib/exit.js",
|
||||||
|
"keywords": [
|
||||||
|
"github",
|
||||||
|
"actions",
|
||||||
|
"toolkit"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exit",
|
||||||
|
"license": "MIT",
|
||||||
|
"directories": {
|
||||||
|
"lib": "lib",
|
||||||
|
"test": "__tests__"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/actions/toolkit.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
|
"tsc": "tsc"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* The code to exit an action
|
||||||
|
*/
|
||||||
|
export enum ExitCode {
|
||||||
|
/**
|
||||||
|
* A code indicating that the action was successful
|
||||||
|
*/
|
||||||
|
Success = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A code indicating that the action was a failure
|
||||||
|
*/
|
||||||
|
Failure = 1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A code indicating that the action is complete, but neither succeeded nor failed
|
||||||
|
*/
|
||||||
|
Neutral = 78
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: These exit codes may not behave as expected on the new runtime, due to
|
||||||
|
// complexities of async logging and sync exiting.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit the action as a success.
|
||||||
|
*/
|
||||||
|
export function success() {
|
||||||
|
process.exit(ExitCode.Success)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit the action as a failure.
|
||||||
|
*/
|
||||||
|
export function failure() {
|
||||||
|
process.exit(ExitCode.Failure)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit the action neither a success or a failure
|
||||||
|
*/
|
||||||
|
export function neutral() {
|
||||||
|
process.exit(ExitCode.Neutral)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "./",
|
||||||
|
"outDir": "./lib",
|
||||||
|
"rootDir": "./src"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./src"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue