Skip to content

Commit 8fdb87f

Browse files
committed
fix: add retry when update is not fast forward
1 parent b52ce9e commit 8fdb87f

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/index.mjs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ import 'zx/globals'
66

77
/* global $ */
88
$.verbose = false
9+
const retryLimit = 10
10+
11+
const getResult = async (context, token, branch, repo, files, message, tag, count) => {
12+
if (!count) count = 0
13+
try {
14+
const result = await commit(
15+
{
16+
token,
17+
branch,
18+
owner: repo[0],
19+
repo: repo[1],
20+
},
21+
files,
22+
message,
23+
tag
24+
)
25+
echo`${JSON.stringify({ result, context, branch, repo, message, tag }, undefined, 2)}`
26+
return result
27+
} catch (error) {
28+
if (error.message === 'Update is not a fast forward' && count <= retryLimit ) {
29+
count++
30+
return await getResult(context, token, branch, repo, files, message, tag, count)
31+
} else if (error.message === 'Update is not a fast forward') {
32+
throw new Error('Update is not a fast forward, retry limit reached.')
33+
} else {
34+
throw error
35+
}
36+
}
37+
}
938

1039
try {
1140
const filesInput = core.getInput('files')
@@ -16,18 +45,7 @@ try {
1645
const branch = core.getInput('ref') || context.github.ref_name
1746
const tag = core.getInput('tag') || false
1847
const files = await getFiles(filesInput)
19-
const result = await commit(
20-
{
21-
token,
22-
branch,
23-
owner: repo[0],
24-
repo: repo[1],
25-
},
26-
files,
27-
message,
28-
tag
29-
)
30-
echo`${JSON.stringify({ result, context, branch, repo, message, tag }, undefined, 2)}`
48+
const result = await getResult(context, token, branch, repo, files, message, tag)
3149
core.setOutput('sha', result.object?.sha)
3250
} catch (error) {
3351
core.setFailed(error.message)

0 commit comments

Comments
 (0)