diff --git a/src/execute.ts b/src/execute.ts index db560fe99..86e93e97d 100644 --- a/src/execute.ts +++ b/src/execute.ts @@ -1,8 +1,17 @@ import {exec} from '@actions/exec' import buffer from 'buffer' +/** + * The output of a command. + */ type ExecuteOutput = { + /** + * The standard output of the command. + */ stdout: string + /** + * The standard error of the command. + */ stderr: string } @@ -21,7 +30,7 @@ export async function execute( cmd: string, cwd: string, silent: boolean, - ignoreReturnCode = false + ignoreReturnCode: boolean = false ): Promise { output.stdout = '' output.stderr = '' @@ -37,6 +46,9 @@ export async function execute( return Promise.resolve(output) } +/** + * Writes the output of a command to the stdout buffer. + */ export function stdout(data: Buffer | string): void { const dataString = data.toString().trim() if ( @@ -47,6 +59,9 @@ export function stdout(data: Buffer | string): void { } } +/** + * Writes the output of a command to the stderr buffer. + */ export function stderr(data: Buffer | string): void { const dataString = data.toString().trim() if ( diff --git a/src/git.ts b/src/git.ts index afa87f72e..f8b9a4e0f 100644 --- a/src/git.ts +++ b/src/git.ts @@ -23,6 +23,24 @@ export async function init(action: ActionInterface): Promise { info(`Deploying using ${action.tokenType}… 🔑`) info('Configuring git…') + /** + * Add safe directory to the global git config. + */ + try { + await execute( + `git config --global safe.directory '*'`, + action.workspace, + action.silent + ) + } catch { + info('Unable to set workflow file tree as a safe directory…') + } + + /** + * Ensure that the workspace is a safe directory, this is somewhat redundant as the action + * will always set the workspace as a safe directory, but this is a fallback in case the action + * fails to do so. + */ try { await execute( `git config --global --add safe.directory "${action.workspace}"`,