Gathering detailed insights and metrics for @unlike/github-actions-core
Gathering detailed insights and metrics for @unlike/github-actions-core
Gathering detailed insights and metrics for @unlike/github-actions-core
Gathering detailed insights and metrics for @unlike/github-actions-core
npm install @unlike/github-actions-core
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
5
@unlike/github-actions-core
Core functions for setting results, logging, registering secrets and exporting variables across actions
Supports
NodeJS
>=20.10.0ES
module npm package1import * as core from '@unlike/github-actions-core'
or
1import {getInput} from '@unlike/github-actions-core'
Action inputs can be read with getInput
which returns a string
or getBooleanInput
which parses a boolean based on the yaml 1.2 specification. If required
set to be false, the input should have a default value in action.yml
.
Outputs can be set with setOutput
which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
1import { 2 getBooleanInput, 3 getInput, 4 getMultilineInput, 5 setOutput 6} from '@unlike/github-actions-core' 7 8const myInput = getInput('inputName', {required: true}) 9const myBooleanInput = getBooleanInput('booleanInputName', { 10 required: true 11}) 12const myMultilineInput = getMultilineInput('multilineInputName', { 13 required: true 14}) 15setOutput('outputKey', 'outputVal')
Since each step runs in a separate process, you can use exportVariable
to add it to this step and future steps environment blocks.
1exportVariable('envVar', 'Val')
Setting a secret registers the secret with the runner to ensure it is masked in logs.
1setSecret('myPassword')
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.
1addPath('/path/to/mytool')
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.
1import {setFailed} from '@unlike/github-actions-core' 2 3try { 4 // Do stuff 5} catch (err) { 6 // setFailed logs the message and sets a failing exit code 7 setFailed(`Action failed with error ${err}`) 8}
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the Step Debug Logs.
1import * as core from '@unlike/github-actions-core' 2 3const myInput = core.getInput('input') 4try { 5 core.debug('Inside try block') 6 7 if (!myInput) { 8 core.warning('myInput was not set') 9 } 10 11 if (core.isDebug()) { 12 // curl -v https://github.com 13 } else { 14 // curl https://github.com 15 } 16 17 // Do stuff 18 core.info('Output to the actions build log') 19 20 core.notice('This is a message that will also emit an annotation') 21} catch (err) { 22 core.error(`Error ${err}, action may still succeed though`) 23}
This library can also wrap chunks of output in foldable groups.
1import * as core from '@unlike/github-actions-core' 2 3// Manually wrap output 4core.startGroup('Do some function') 5doSomeFunction() 6core.endGroup() 7 8// Wrap an asynchronous function call 9const result = await core.group('Do something async', async () => { 10 const response = await doSomeHTTPRequest() 11 return response 12})
This library has 3 methods that will produce annotations.
1core.error('This is a bad error, action may still succeed though.') 2 3core.warning("Something went wrong, but it's not bad enough to fail the build.") 4 5core.notice('Something happened that you might want to know about.')
These will surface to the UI in the Actions page and on Pull Requests. They look something like this:
These annotations can also be attached to particular lines and columns of your source files to show exactly where a problem is occuring.
These options are:
1export interface AnnotationProperties { 2 /** 3 * A title for the annotation. 4 */ 5 title?: string 6 7 /** 8 * The name of the file for which the annotation should be created. 9 */ 10 file?: string 11 12 /** 13 * The start line for the annotation. 14 */ 15 startLine?: number 16 17 /** 18 * The end line for the annotation. Defaults to `startLine` when `startLine` is provided. 19 */ 20 endLine?: number 21 22 /** 23 * The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values. 24 */ 25 startColumn?: number 26 27 /** 28 * The end column for the annotation. Cannot be sent when `startLine` and `endLine` are different values. 29 * Defaults to `startColumn` when `startColumn` is provided. 30 */ 31 endColumn?: number 32}
Colored output is supported in the Action logs via standard ANSI escape codes. 3/4 bit, 8 bit and 24 bit colors are all supported.
Foreground colors:
1// 3/4 bit 2core.info('\u001b[35mThis foreground will be magenta') 3 4// 8 bit 5core.info('\u001b[38;5;6mThis foreground will be cyan') 6 7// 24 bit 8core.info('\u001b[38;2;255;0;0mThis foreground will be bright red')
Background colors:
1// 3/4 bit 2core.info('\u001b[43mThis background will be yellow') 3 4// 8 bit 5core.info('\u001b[48;5;6mThis background will be cyan') 6 7// 24 bit 8core.info('\u001b[48;2;255;0;0mThis background will be bright red')
Special styles:
1core.info('\u001b[1mBold text') 2core.info('\u001b[3mItalic text') 3core.info('\u001b[4mUnderlined text')
ANSI escape codes can be combined with one another:
1core.info( 2 '\u001b[31;46mRed foreground with a cyan background and \u001b[1mbold text at the end' 3)
Note: Escape codes reset at the start of each line
1core.info('\u001b[35mThis foreground will be magenta') 2core.info('This foreground will reset to the default')
Manually typing escape codes can be a little difficult, but you can use third party modules such as ansi-styles.
1const style = require('ansi-styles') 2core.info(style.color.ansi16m.hex('#abcdef') + 'Hello world!')
You can use this library to save state and get state for sharing information between a given wrapper action:
action.yml:
1name: 'Wrapper action sample' 2inputs: 3 name: 4 default: 'GitHub' 5runs: 6 using: 'node12' 7 main: 'main.js' 8 post: 'cleanup.js'
In action's main.js
:
1import {saveState} from '@unlike/github-actions-core' 2 3saveState('pidToKill', 12345)
In action's cleanup.js
:
1import {getState} from '@unlike/github-actions-core' 2 3const pid = getState('pidToKill') 4 5process.kill(pid)
You can use these methods to interact with the GitHub OIDC provider and get a JWT ID token which would help to get access token from third party cloud providers.
Method Name: getIDToken()
Inputs
audience : optional
Outputs
A JWT ID Token
In action's main.ts
:
1import * as core from '@unlike/github-actions-core' 2 3async function getIDTokenAction(): Promise<void> { 4 const audience = core.getInput('audience', {required: false}) 5 6 const id_token1 = await core.getIDToken() // ID Token with default audience 7 const id_token2 = await core.getIDToken(audience) // ID token with custom audience 8 9 // this id_token can be used to get access token from third party cloud providers 10} 11getIDTokenAction()
In action's actions.yml
:
1name: 'GetIDToken' 2description: 'Get ID token from Github OIDC provider' 3inputs: 4 audience: 5 description: 'Audience for which the ID token is intended for' 6 required: false 7outputs: 8 id_token1: 9 description: 'ID token obtained from OIDC provider' 10 id_token2: 11 description: 'ID token obtained from OIDC provider' 12runs: 13 using: 'node16' 14 main: 'dist/index.js'
You can use these methods to manipulate file paths across operating systems.
The toPosixPath
function converts input paths to Posix-style (Linux) paths.
The toWin32Path
function converts input paths to Windows-style paths. These
functions work independently of the underlying runner operating system.
1toPosixPath('\\foo\\bar') // => /foo/bar
2toWin32Path('/foo/bar') // => \foo\bar
The toPlatformPath
function converts input paths to the expected value on the runner's operating system.
1// On a Windows runner.
2toPlatformPath('/foo/bar') // => \foo\bar
3
4// On a Linux runner.
5toPlatformPath('\\foo\\bar') // => /foo/bar
No vulnerabilities found.
No security vulnerabilities found.