1
0
Fork 0

Add the "@actions/exit" package

It is useful to have the exit logic separated into its own package
pull/1/head
Jonathan Clem 2019-04-20 10:52:56 -04:00
parent 1e32709630
commit cca9523c73
No known key found for this signature in database
GPG Key ID: 48C5B22E9FD6E80F
7 changed files with 130 additions and 0 deletions

7
packages/exit/LICENSE.md Normal file
View File

@ -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.

11
packages/exit/README.md Normal file
View File

@ -0,0 +1,11 @@
# `@actions/exit`
> TODO: description
## Usage
```
const exit = require('@actions/exit');
// TODO: DEMONSTRATE API
```

View File

@ -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)
})

5
packages/exit/package-lock.json generated Normal file
View File

@ -0,0 +1,5 @@
{
"name": "@actions/exit",
"version": "0.0.0",
"lockfileVersion": 1
}

View File

@ -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"
}
}

43
packages/exit/src/exit.ts Normal file
View File

@ -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)
}

View File

@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "./lib",
"rootDir": "./src"
},
"include": [
"./src"
]
}