Skip to content

Commit

Permalink
Merge branch 'dev' into releases/v4
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Sep 27, 2024
2 parents 920cbb3 + dd28e19 commit c30eaca
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
8 changes: 4 additions & 4 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -123,7 +123,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toHaveBeenCalledTimes(6)
expect(execute).toHaveBeenCalledTimes(7)

process.env.CI = undefined
})
Expand All @@ -144,7 +144,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toHaveBeenCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(8)
})
})

Expand Down
4 changes: 2 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> (https://jamesiv.es)",
"version": "4.6.3",
"version": "4.6.4",
"license": "MIT",
"main": "lib/lib.js",
"types": "lib/lib.d.ts",
Expand Down
17 changes: 16 additions & 1 deletion src/execute.ts
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -21,7 +30,7 @@ export async function execute(
cmd: string,
cwd: string,
silent: boolean,
ignoreReturnCode = false
ignoreReturnCode: boolean = false
): Promise<ExecuteOutput> {
output.stdout = ''
output.stderr = ''
Expand All @@ -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 (
Expand All @@ -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 (
Expand Down
18 changes: 18 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ export async function init(action: ActionInterface): Promise<void | Error> {
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}"`,
Expand Down

0 comments on commit c30eaca

Please sign in to comment.