import { parseArgsStringToArgv } from 'string-argv' ; import * as core from '@actions/core' ; import { Toolkit } from 'actions-toolkit' ; import fs from 'fs' ; interface InputTypes { add : string ; author_name : string ; author_email : string ; branch : string ; branch_mode : 'throw' | 'create' ; commit : string | undefined ; committer_name : string ; committer_email : string ; cwd : string ; default_author : 'github_actor' | 'user_info' | 'github_actions' ; message : string ; pathspec_error_handling : 'ignore' | 'exitImmediately' | 'exitAtEnd' ; pull : string | undefined ; push : string ; remove : string | undefined ; tag : string | undefined ; github_token : string | undefined ; } export type input = keyof InputTypes ; interface OutputTypes { committed : 'true' | 'false' ; commit_sha : string | undefined ; pushed : 'true' | 'false' ; tagged : 'true' | 'false' ; } export type output = keyof OutputTypes ; export const outputs = { committed : 'false' , commit_sha : undefined , pushed : 'false' , tagged : 'false' } ; type RecordOf < T extends string > = Record < T , string | undefined > ; export const tools = new Toolkit < RecordOf < input > , RecordOf < output > > ( { secrets : [ 'GITHUB_EVENT_PATH' , 'GITHUB_EVENT_NAME' , 'GITHUB_REF' , 'GITHUB_ACTOR' ] } ) ; export function getInput < T extends input > ( name , parseAsBool ) ; export function getInput < T extends input > ( name , parseAsBool ? ) ; export function getInput < T extends input > ( name , parseAsBool = false ) { if ( parseAsBool ) return core . getBooleanInput ( name ) ; return core . getInput ( name ) ; } export async function getUserInfo ( username ? ) { if ( ! username ) return undefined ; const res = await tools . github . users . getByUsername ( { username } ) ; core . debug ( `Fetched github actor from the API: ${ JSON . stringify ( res ?. data , null , 2 ) }` ) ; return { name : res ?. data ?. name , email : res ?. data ?. email } ; } export function log ( err , data ? ) { if ( data ) console . log ( data ) ; if ( err ) core . error ( err ) ; } /**
 * Matches the given string to an array of arguments.
 * The parsing is made by `string-argv`: if your way of using argument is not supported, the issue is theirs!
 *  https example returns export function matchGitArgs ( string ) { const parsed = parseArgsStringToArgv ( string ) ; core . debug ( `Git args parsed:
  - Original: ${ string }
  - Parsed: ${ JSON . stringify ( parsed ) }` ) ; return parsed ; } export function readJSON ( filePath ) { let fileContent ; try { fileContent = fs . readFileSync ( filePath , { encoding : 'utf8' } ) ; } catch { throw `Couldn't read file. File path: ${ filePath }` ; } try { return JSON . parse ( fileContent ) ; } catch { throw `Couldn't parse file to JSON. File path: ${ filePath }` ; } } export function setOutput < T extends output > ( name , value ) { core . debug ( `Setting output: ${ name }=${ value }` ) ; outputs [ name ] = value ; core . setOutput ( name , value ) ; } Object . entries ( outputs ) . forEach ( ( [ name , value ] ) => core . setOutput ( name , value ) ) ;