Skip to content

Commit

Permalink
feat: allow nested paths in target-folder + add attempt-limit par…
Browse files Browse the repository at this point in the history
…ameter (#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 <[email protected]>
  • Loading branch information
databasedav and JamesIves authored Nov 24, 2024
1 parent 56672c7 commit 84bd015
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ By default, the action does not need any token configuration and uses the provid
| `dry-run` | Do not actually push back, but use `--dry-run` on `git push` invocations instead. | `with` | **No** |
| `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** |
| `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** |
| `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** |
| `silent` | Silences the action output preventing it from displaying git messages. | `with` | **No** |
| `tag` | Add a tag to the commit. Only works when `dry-run` is not used. | `with` | **No** |

Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface ActionInterface {
folderPath?: string
/** Whether to force-push or attempt to merge existing changes. */
force?: boolean
/** How many times to attempt to merge existing changes into the remote HEAD. */
attemptLimit?: number;
/** Determines test scenarios the action is running in. */
isTest: TestFlag
/** The git config name. */
Expand Down Expand Up @@ -95,6 +97,9 @@ export const action: ActionInterface = {
force: !isNullOrUndefined(getInput('force'))
? getInput('force').toLowerCase() === 'true'
: true,
attemptLimit: !isNullOrUndefined(getInput('attempt-limit'))
? parseInt(getInput('attempt-limit'), 10)
: 3,
clean: !isNullOrUndefined(getInput('clean'))
? getInput('clean').toLowerCase() === 'true'
: false,
Expand Down
8 changes: 4 additions & 4 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
Allows the user to specify the root if '.' is provided.
rsync is used to prevent file duplication. */
await execute(
`rsync -q -av --checksum --progress ${action.folderPath}/. ${
`rsync -q -av --checksum --progress --mkpath ${action.folderPath}/. ${
action.targetFolder
? `${temporaryDeploymentDirectory}/${action.targetFolder}`
: temporaryDeploymentDirectory
Expand Down Expand Up @@ -268,7 +268,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
action.silent
)
} else {
const ATTEMPT_LIMIT = 3
const attemptLimit = action.attemptLimit || 3
// Attempt to push our changes, but fetch + rebase if there were
// other changes added in the meantime
let attempt = 0
Expand All @@ -279,7 +279,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
do {
attempt++

if (attempt > ATTEMPT_LIMIT) throw new Error(`Attempt limit exceeded`)
if (attempt > attemptLimit) throw new Error(`Attempt limit exceeded`)

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

info(`Pushing changes… (attempt ${attempt} of ${ATTEMPT_LIMIT})`)
info(`Pushing changes… (attempt ${attempt} of ${attemptLimit})`)

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

0 comments on commit 84bd015

Please sign in to comment.