Skip to content

Commit 84bd015

Browse files
feat: allow nested paths in target-folder + add attempt-limit parameter (#1737)
* use --mkpath in rsync + add attempt limits parameter * make attempt limit optional so tests pass * Update src/constants.ts --------- Co-authored-by: James Ives <iam@jamesiv.es>
1 parent 56672c7 commit 84bd015

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
166166
Allows the user to specify the root if '.' is provided.
167167
rsync is used to prevent file duplication. */
168168
await execute(
169-
`rsync -q -av --checksum --progress ${action.folderPath}/. ${
169+
`rsync -q -av --checksum --progress --mkpath ${action.folderPath}/. ${
170170
action.targetFolder
171171
? `${temporaryDeploymentDirectory}/${action.targetFolder}`
172172
: temporaryDeploymentDirectory
@@ -268,7 +268,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
268268
action.silent
269269
)
270270
} else {
271-
const ATTEMPT_LIMIT = 3
271+
const attemptLimit = action.attemptLimit || 3
272272
// Attempt to push our changes, but fetch + rebase if there were
273273
// other changes added in the meantime
274274
let attempt = 0
@@ -279,7 +279,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
279279
do {
280280
attempt++
281281

282-
if (attempt > ATTEMPT_LIMIT) throw new Error(`Attempt limit exceeded`)
282+
if (attempt > attemptLimit) throw new Error(`Attempt limit exceeded`)
283283

284284
// Handle rejection for the previous attempt first such that, on
285285
// the final attempt, time is not wasted rebasing it when it will
@@ -299,7 +299,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
299299
)
300300
}
301301

302-
info(`Pushing changes… (attempt ${attempt} of ${ATTEMPT_LIMIT})`)
302+
info(`Pushing changes… (attempt ${attempt} of ${attemptLimit})`)
303303

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

0 commit comments

Comments
 (0)