File tree Expand file tree Collapse file tree 1 file changed +46
-22
lines changed Expand file tree Collapse file tree 1 file changed +46
-22
lines changed Original file line number Diff line number Diff line change @@ -21,34 +21,58 @@ export async function init(action: ActionInterface): Promise<void | Error> {
21
21
info ( `Deploying using ${ action . tokenType } … 🔑` )
22
22
info ( 'Configuring git…' )
23
23
24
- try {
24
+ // Keep trying to configure Git with various different methods until it works with a maximum of 2 attempts.
25
+ const ATTEMPT_LIMIT = 2
26
+
27
+ let attempt = 0
28
+ let rejected = false
29
+
30
+ do {
31
+ attempt ++
32
+
33
+ if ( attempt > ATTEMPT_LIMIT ) {
34
+ throw new Error ( ) ;
35
+ }
36
+
37
+ if ( attempt > 1 ) {
38
+ await execute (
39
+ `git init` ,
40
+ action . workspace ,
41
+ action . silent
42
+ )
43
+
44
+ await execute (
45
+ `git commit -m "Initial commit" --allow-empty` ,
46
+ action . workspace ,
47
+ action . silent
48
+ )
49
+ }
50
+
25
51
await execute (
26
52
`git config --global --add safe.directory "${ action . workspace } "` ,
27
53
action . workspace ,
28
54
action . silent
29
55
)
30
- } catch {
31
- info ( 'Unable to set workspace as a safe directory…' )
32
- }
33
-
34
- await execute (
35
- `git config user.name "${ action . name } "` ,
36
- action . workspace ,
37
- action . silent
38
- )
39
-
40
- await execute (
41
- `git config user.email "${ action . email } "` ,
42
- action . workspace ,
43
- action . silent
44
- )
45
-
46
- await execute (
47
- `git config core.ignorecase false` ,
48
- action . workspace ,
49
- action . silent
50
- )
51
56
57
+ await execute (
58
+ `git config user.name "${ action . name } "` ,
59
+ action . workspace ,
60
+ action . silent
61
+ )
62
+
63
+ await execute (
64
+ `git config user.email "${ action . email } "` ,
65
+ action . workspace ,
66
+ action . silent
67
+ )
68
+
69
+ await execute (
70
+ `git config core.ignorecase false` ,
71
+ action . workspace ,
72
+ action . silent
73
+ )
74
+ } while ( rejected )
75
+
52
76
try {
53
77
if ( ( process . env . CI && ! action . sshKey ) || action . isTest ) {
54
78
/* Ensures that previously set Git configs do not interfere with the deployment.
You can’t perform that action at this time.
0 commit comments