Skip to content

Commit ec82a36

Browse files
committed
add attemptLimit
1 parent eb3eb01 commit ec82a36

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
<a href="https://github.com/JamesIves/github-pages-deploy-action/actions">
1313
<img src="https://github.com/JamesIves/github-pages-deploy-action/workflows/unit-tests/badge.svg" alt="Unit test status badge">
1414
</a>
15-
15+
1616
<a href="https://github.com/JamesIves/github-pages-deploy-action/actions">
1717
<img src="https://github.com/JamesIves/github-pages-deploy-action/workflows/integration-tests/badge.svg" alt="Integration test status badge">
1818
</a>
19-
19+
2020
<a href="https://codecov.io/gh/JamesIves/github-pages-deploy-action/branch/dev">
2121
<img src="https://codecov.io/gh/JamesIves/github-pages-deploy-action/branch/dev/graph/badge.svg" alt="Code coverage status badge">
2222
</a>
23-
23+
2424
<a href="https://github.com/JamesIves/github-pages-deploy-action/releases">
2525
<img src="https://img.shields.io/github/v/release/JamesIves/github-pages-deploy-action.svg?logo=github" alt="Release version badge">
2626
</a>
27-
27+
2828
<a href="https://github.com/marketplace/actions/deploy-to-github-pages">
2929
<img src="https://img.shields.io/badge/action-marketplace-blue.svg?logo=github&color=orange" alt="Github marketplace badge">
3030
</a>
@@ -134,6 +134,7 @@ By default, the action does not need any token configuration and uses the provid
134134
| `dry-run` | Do not actually push back, but use `--dry-run` on `git push` invocations instead. | `with` | **No** |
135135
| `single-commit` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** |
136136
| `force` | Force-push new deployments to overwrite the previous version; otherwise, attempt to rebase new deployments onto any existing ones. This option is turned on by default and can be toggled off by setting it to `false`, which may be useful if there are multiple deployments in a single branch. | `with` | **No** |
137+
| `attempt-limit` | How many rebase attempts to make before suspending the job. This option defaults to `3` and may be useful to increase when there are multiple deployments in a single branch. | `with` | **No** |
137138
| `silent` | Silences the action output preventing it from displaying git messages. | `with` | **No** |
138139
| `tag` | Add a tag to the commit. Only works when `dry-run` is not used. | `with` | **No** |
139140

lib/constants.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface ActionInterface {
2727
folderPath?: string;
2828
/** Whether to force-push or attempt to merge existing changes. */
2929
force?: boolean;
30+
/** How many times to attempt to merge existing changes into the remote HEAD. */
31+
attemptLimit: number;
3032
/** Determines test scenarios the action is running in. */
3133
isTest: TestFlag;
3234
/** The git config name. */

lib/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ exports.action = {
5151
force: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('force'))
5252
? (0, core_1.getInput)('force').toLowerCase() === 'true'
5353
: true,
54+
attemptLimit: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('attempt-limit'))
55+
? parseInt((0, core_1.getInput)('attempt-limit'), 10)
56+
: 3,
5457
clean: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('clean'))
5558
? (0, core_1.getInput)('clean').toLowerCase() === 'true'
5659
: false,

lib/git.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,14 @@ function deploy(action) {
159159
yield (0, execute_1.execute)(`git push --force ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
160160
}
161161
else {
162-
const ATTEMPT_LIMIT = 3;
163162
// Attempt to push our changes, but fetch + rebase if there were
164163
// other changes added in the meantime
165164
let attempt = 0;
166165
// Keep track of whether the most recent attempt was rejected
167166
let rejected = false;
168167
do {
169168
attempt++;
170-
if (attempt > ATTEMPT_LIMIT)
169+
if (attempt > action.attemptLimit)
171170
throw new Error(`Attempt limit exceeded`);
172171
// Handle rejection for the previous attempt first such that, on
173172
// the final attempt, time is not wasted rebasing it when it will
@@ -178,7 +177,7 @@ function deploy(action) {
178177
(0, core_1.info)(`Rebasing this deployment onto ${action.branch}…`);
179178
yield (0, execute_1.execute)(`git rebase ${action.branch} ${temporaryDeploymentBranch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
180179
}
181-
(0, core_1.info)(`Pushing changes… (attempt ${attempt} of ${ATTEMPT_LIMIT})`);
180+
(0, core_1.info)(`Pushing changes… (attempt ${attempt} of ${action.attemptLimit})`);
182181
const pushResult = yield (0, execute_1.execute)(`git push --porcelain ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent, true // Ignore non-zero exit status
183182
);
184183
rejected =

src/constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface ActionInterface {
3838
folderPath?: string
3939
/** Whether to force-push or attempt to merge existing changes. */
4040
force?: boolean
41+
/** How many times to attempt to merge existing changes into the remote HEAD. */
42+
attemptLimit: number
4143
/** Determines test scenarios the action is running in. */
4244
isTest: TestFlag
4345
/** The git config name. */
@@ -95,6 +97,9 @@ export const action: ActionInterface = {
9597
force: !isNullOrUndefined(getInput('force'))
9698
? getInput('force').toLowerCase() === 'true'
9799
: true,
100+
attemptLimit: !isNullOrUndefined(getInput('attempt-limit'))
101+
? parseInt(getInput('attempt-limit'), 10)
102+
: 3,
98103
clean: !isNullOrUndefined(getInput('clean'))
99104
? getInput('clean').toLowerCase() === 'true'
100105
: false,

src/git.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ export async function deploy(action: ActionInterface): Promise<Status> {
268268
action.silent
269269
)
270270
} else {
271-
const ATTEMPT_LIMIT = 3
272271
// Attempt to push our changes, but fetch + rebase if there were
273272
// other changes added in the meantime
274273
let attempt = 0
@@ -279,7 +278,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
279278
do {
280279
attempt++
281280

282-
if (attempt > ATTEMPT_LIMIT) throw new Error(`Attempt limit exceeded`)
281+
if (attempt > action.attemptLimit) throw new Error(`Attempt limit exceeded`)
283282

284283
// Handle rejection for the previous attempt first such that, on
285284
// the final attempt, time is not wasted rebasing it when it will
@@ -299,7 +298,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
299298
)
300299
}
301300

302-
info(`Pushing changes… (attempt ${attempt} of ${ATTEMPT_LIMIT})`)
301+
info(`Pushing changes… (attempt ${attempt} of ${action.attemptLimit})`)
303302

304303
const pushResult = await execute(
305304
`git push --porcelain ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`,

0 commit comments

Comments
 (0)