diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index ddb0b65d2..f1c7bc5fa 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -54,7 +54,7 @@ describe('git', () => { }) await init(action) - expect(execute).toHaveBeenCalledTimes(7) + expect(execute).toHaveBeenCalledTimes(8) }) it('should catch when a function throws an error', async () => { @@ -101,7 +101,7 @@ describe('git', () => { }) await init(action) - expect(execute).toHaveBeenCalledTimes(7) + expect(execute).toHaveBeenCalledTimes(8) }) it('should not unset git config if a user is using ssh', async () => { @@ -123,7 +123,7 @@ describe('git', () => { }) await init(action) - expect(execute).toHaveBeenCalledTimes(6) + expect(execute).toHaveBeenCalledTimes(7) process.env.CI = undefined }) @@ -144,7 +144,7 @@ describe('git', () => { }) await init(action) - expect(execute).toHaveBeenCalledTimes(7) + expect(execute).toHaveBeenCalledTimes(8) }) }) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index f0ec58053..3d33495aa 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -53,7 +53,7 @@ describe('main', () => { debug: true }) await run(action) - expect(execute).toHaveBeenCalledTimes(18) + expect(execute).toHaveBeenCalledTimes(19) expect(rmRF).toHaveBeenCalledTimes(1) expect(exportVariable).toHaveBeenCalledTimes(1) }) @@ -73,7 +73,7 @@ describe('main', () => { isTest: TestFlag.HAS_CHANGED_FILES }) await run(action) - expect(execute).toHaveBeenCalledTimes(21) + expect(execute).toHaveBeenCalledTimes(22) expect(rmRF).toHaveBeenCalledTimes(1) expect(exportVariable).toHaveBeenCalledTimes(1) }) diff --git a/package.json b/package.json index e34e2b0d0..a8e06b0ad 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@jamesives/github-pages-deploy-action", "description": "GitHub action for building a project and deploying it to GitHub pages.", "author": "James Ives (https://jamesiv.es)", - "version": "4.6.3", + "version": "4.6.4", "license": "MIT", "main": "lib/lib.js", "types": "lib/lib.d.ts", 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}"`,