Skip to content

Commit 31fa027

Browse files
committed
fix: add safe directory commands
1 parent bfd213f commit 31fa027

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/execute.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import {exec} from '@actions/exec'
22
import buffer from 'buffer'
33

4+
/**
5+
* The output of a command.
6+
*/
47
type ExecuteOutput = {
8+
/**
9+
* The standard output of the command.
10+
*/
511
stdout: string
12+
/**
13+
* The standard error of the command.
14+
*/
615
stderr: string
716
}
817

@@ -21,7 +30,7 @@ export async function execute(
2130
cmd: string,
2231
cwd: string,
2332
silent: boolean,
24-
ignoreReturnCode = false
33+
ignoreReturnCode: boolean = false
2534
): Promise<ExecuteOutput> {
2635
output.stdout = ''
2736
output.stderr = ''
@@ -37,6 +46,9 @@ export async function execute(
3746
return Promise.resolve(output)
3847
}
3948

49+
/**
50+
* Writes the output of a command to the stdout buffer.
51+
*/
4052
export function stdout(data: Buffer | string): void {
4153
const dataString = data.toString().trim()
4254
if (
@@ -47,6 +59,9 @@ export function stdout(data: Buffer | string): void {
4759
}
4860
}
4961

62+
/**
63+
* Writes the output of a command to the stderr buffer.
64+
*/
5065
export function stderr(data: Buffer | string): void {
5166
const dataString = data.toString().trim()
5267
if (

src/git.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ export async function init(action: ActionInterface): Promise<void | Error> {
2323
info(`Deploying using ${action.tokenType}… 🔑`)
2424
info('Configuring git…')
2525

26+
/**
27+
* Add safe directory to the global git config.
28+
*/
29+
try {
30+
await execute(
31+
`git config --global safe.directory '*'`,
32+
action.workspace,
33+
action.silent
34+
)
35+
} catch {
36+
info('Unable to set workflow file tree as a safe directory…')
37+
}
38+
39+
/**
40+
* Ensure that the workspace is a safe directory, this is somewhat redundant as the action
41+
* will always set the workspace as a safe directory, but this is a fallback in case the action
42+
* fails to do so.
43+
*/
2644
try {
2745
await execute(
2846
`git config --global --add safe.directory "${action.workspace}"`,

0 commit comments

Comments
 (0)