mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Merge branch 'init-commit' into releases/v4-init
This commit is contained in:
commit
c46739c7bd
67
src/git.ts
67
src/git.ts
@ -21,58 +21,53 @@ export async function init(action: ActionInterface): Promise<void | Error> {
|
|||||||
info(`Deploying using ${action.tokenType}… 🔑`)
|
info(`Deploying using ${action.tokenType}… 🔑`)
|
||||||
info('Configuring git…')
|
info('Configuring git…')
|
||||||
|
|
||||||
// Keep trying to configure Git with various different methods until it works with a maximum of 2 attempts.
|
async function configureGit(throwOnError: boolean) {
|
||||||
const ATTEMPT_LIMIT = 2
|
try {
|
||||||
|
|
||||||
let attempt = 0
|
|
||||||
let rejected = false
|
|
||||||
|
|
||||||
do {
|
|
||||||
attempt++
|
|
||||||
|
|
||||||
if (attempt > ATTEMPT_LIMIT) {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attempt > 1) {
|
|
||||||
await execute(
|
await execute(
|
||||||
`git init`,
|
`git config --global --add safe.directory "${action.workspace}"`,
|
||||||
action.workspace,
|
action.workspace,
|
||||||
action.silent
|
action.silent
|
||||||
)
|
)
|
||||||
|
|
||||||
await execute(
|
await execute(
|
||||||
`git commit -m "Initial commit" --allow-empty`,
|
`git config user.name "${action.name}"`,
|
||||||
action.workspace,
|
action.workspace,
|
||||||
action.silent
|
action.silent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await execute(
|
||||||
|
`git config user.email "${action.email}"`,
|
||||||
|
action.workspace,
|
||||||
|
action.silent
|
||||||
|
)
|
||||||
|
|
||||||
|
await execute(
|
||||||
|
`git config core.ignorecase false`,
|
||||||
|
action.workspace,
|
||||||
|
action.silent
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
if (throwOnError) {
|
||||||
|
throw new Error()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await configureGit(false)
|
||||||
|
} catch {
|
||||||
|
// Attempt to re-run if initial configuration failed using git init.
|
||||||
|
await execute(`git init`, action.workspace, action.silent)
|
||||||
|
|
||||||
await execute(
|
await execute(
|
||||||
`git config --global --add safe.directory "${action.workspace}"`,
|
`git commit -m "Initial commit" --allow-empty`,
|
||||||
action.workspace,
|
action.workspace,
|
||||||
action.silent
|
action.silent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await configureGit(true)
|
||||||
|
}
|
||||||
|
|
||||||
await execute(
|
|
||||||
`git config user.name "${action.name}"`,
|
|
||||||
action.workspace,
|
|
||||||
action.silent
|
|
||||||
)
|
|
||||||
|
|
||||||
await execute(
|
|
||||||
`git config user.email "${action.email}"`,
|
|
||||||
action.workspace,
|
|
||||||
action.silent
|
|
||||||
)
|
|
||||||
|
|
||||||
await execute(
|
|
||||||
`git config core.ignorecase false`,
|
|
||||||
action.workspace,
|
|
||||||
action.silent
|
|
||||||
)
|
|
||||||
} while(rejected)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((process.env.CI && !action.sshKey) || action.isTest) {
|
if ((process.env.CI && !action.sshKey) || action.isTest) {
|
||||||
/* Ensures that previously set Git configs do not interfere with the deployment.
|
/* Ensures that previously set Git configs do not interfere with the deployment.
|
||||||
|
Loading…
Reference in New Issue
Block a user