mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Improe coverage
This commit is contained in:
parent
e71f256f1c
commit
36e9415933
@ -424,5 +424,30 @@ describe('git', () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should execute commands if force is false and retry until limit is exceeded', async () => {
|
||||||
|
Object.assign(action, {
|
||||||
|
hostname: 'github.com',
|
||||||
|
silent: false,
|
||||||
|
folder: 'assets',
|
||||||
|
branch: 'branch',
|
||||||
|
force: false,
|
||||||
|
token: '123',
|
||||||
|
repositoryName: 'JamesIves/montezuma',
|
||||||
|
pusher: {
|
||||||
|
name: 'asd',
|
||||||
|
email: 'as@cat'
|
||||||
|
},
|
||||||
|
isTest: TestFlag.HAS_CHANGED_FILES
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deploy(action)
|
||||||
|
} catch (error) {
|
||||||
|
expect(error instanceof Error && error.message).toBe(
|
||||||
|
'The deploy step encountered an error: Attempt limit exceeded ❌'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,8 @@ export enum TestFlag {
|
|||||||
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit.
|
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit.
|
||||||
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits.
|
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits.
|
||||||
UNABLE_TO_REMOVE_ORIGIN = 1 << 3, // Assume we can't remove origin.
|
UNABLE_TO_REMOVE_ORIGIN = 1 << 3, // Assume we can't remove origin.
|
||||||
UNABLE_TO_UNSET_GIT_CONFIG = 1 << 4 // Assume we can't remove previously set git configs.
|
UNABLE_TO_UNSET_GIT_CONFIG = 1 << 4, // Assume we can't remove previously set git configs.
|
||||||
|
HAS_REJECTED_COMMIT = 1 << 5 // Assume commit rejection.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
|
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
|
||||||
|
14
src/git.ts
14
src/git.ts
@ -240,27 +240,30 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
|||||||
action.silent
|
action.silent
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
const ATTEMPT_LIMIT = 3
|
||||||
// Attempt to push our changes, but fetch + rebase if there were
|
// Attempt to push our changes, but fetch + rebase if there were
|
||||||
// other changes added in the meantime
|
// other changes added in the meantime
|
||||||
const ATTEMPT_LIMIT = 3
|
|
||||||
let attempt = 0
|
let attempt = 0
|
||||||
|
|
||||||
// Keep track of whether the most recent attempt was rejected
|
// Keep track of whether the most recent attempt was rejected
|
||||||
let rejected = false
|
let rejected = false
|
||||||
|
|
||||||
do {
|
do {
|
||||||
attempt++
|
attempt++
|
||||||
|
|
||||||
if (attempt > ATTEMPT_LIMIT) throw new Error(`Attempt limit exceeded`)
|
if (attempt > ATTEMPT_LIMIT) throw new Error(`Attempt limit exceeded`)
|
||||||
|
|
||||||
// Handle rejection for the previous attempt first such that, on
|
// Handle rejection for the previous attempt first such that, on
|
||||||
// the final attempt, time is not wasted rebasing it when it will
|
// the final attempt, time is not wasted rebasing it when it will
|
||||||
// not be pushed
|
// not be pushed
|
||||||
if (rejected) {
|
if (rejected) {
|
||||||
info(`Fetching upstream ${action.branch}...`)
|
info(`Fetching upstream ${action.branch}…`)
|
||||||
await execute(
|
await execute(
|
||||||
`git fetch ${action.repositoryPath} ${action.branch}:${action.branch}`,
|
`git fetch ${action.repositoryPath} ${action.branch}:${action.branch}`,
|
||||||
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
||||||
action.silent
|
action.silent
|
||||||
)
|
)
|
||||||
info(`Rebasing this deployment onto ${action.branch}...`)
|
info(`Rebasing this deployment onto ${action.branch}…`)
|
||||||
await execute(
|
await execute(
|
||||||
`git rebase ${action.branch} ${temporaryDeploymentBranch}`,
|
`git rebase ${action.branch} ${temporaryDeploymentBranch}`,
|
||||||
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
||||||
@ -268,7 +271,8 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
info(`Pushing changes... (attempt ${attempt} of ${ATTEMPT_LIMIT})`)
|
info(`Pushing changes… (attempt ${attempt} of ${ATTEMPT_LIMIT})`)
|
||||||
|
|
||||||
const pushResult = await execute(
|
const pushResult = await execute(
|
||||||
`git push --porcelain ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`,
|
`git push --porcelain ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`,
|
||||||
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
||||||
@ -277,8 +281,10 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
rejected =
|
rejected =
|
||||||
|
Boolean(action.isTest) ||
|
||||||
pushResult.stdout.includes(`[rejected]`) ||
|
pushResult.stdout.includes(`[rejected]`) ||
|
||||||
pushResult.stdout.includes(`[remote rejected]`)
|
pushResult.stdout.includes(`[remote rejected]`)
|
||||||
|
|
||||||
if (rejected) info('Updates were rejected')
|
if (rejected) info('Updates were rejected')
|
||||||
|
|
||||||
// If the push failed for any reason other than being rejected,
|
// If the push failed for any reason other than being rejected,
|
||||||
|
Loading…
Reference in New Issue
Block a user