mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Merge branch 'releases/v4-init' of https://github.com/JamesIves/github-pages-deploy-action into releases/v4-init
This commit is contained in:
commit
92efb78e2b
38
lib/git.js
38
lib/git.js
@ -26,24 +26,30 @@ function init(action) {
|
|||||||
try {
|
try {
|
||||||
(0, core_1.info)(`Deploying using ${action.tokenType}… 🔑`);
|
(0, core_1.info)(`Deploying using ${action.tokenType}… 🔑`);
|
||||||
(0, core_1.info)('Configuring git…');
|
(0, core_1.info)('Configuring git…');
|
||||||
// Keep trying to configure Git with various different methods until it works with a maximum of 2 attempts.
|
function configureGit(throwOnError) {
|
||||||
const ATTEMPT_LIMIT = 2;
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let attempt = 0;
|
try {
|
||||||
let rejected = false;
|
|
||||||
do {
|
|
||||||
attempt++;
|
|
||||||
if (attempt > ATTEMPT_LIMIT) {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
if (attempt > 1) {
|
|
||||||
yield (0, execute_1.execute)(`git init`, action.workspace, action.silent);
|
|
||||||
yield (0, execute_1.execute)(`git commit -m "Initial commit" --allow-empty`, action.workspace, action.silent);
|
|
||||||
}
|
|
||||||
yield (0, execute_1.execute)(`git config --global --add safe.directory "${action.workspace}"`, action.workspace, action.silent);
|
yield (0, execute_1.execute)(`git config --global --add safe.directory "${action.workspace}"`, action.workspace, action.silent);
|
||||||
yield (0, execute_1.execute)(`git config user.name "${action.name}"`, action.workspace, action.silent);
|
yield (0, execute_1.execute)(`git config user.name "${action.name}"`, action.workspace, action.silent);
|
||||||
yield (0, execute_1.execute)(`git config user.email "${action.email}"`, action.workspace, action.silent);
|
yield (0, execute_1.execute)(`git config user.email "${action.email}"`, action.workspace, action.silent);
|
||||||
yield (0, execute_1.execute)(`git config core.ignorecase false`, action.workspace, action.silent);
|
yield (0, execute_1.execute)(`git config core.ignorecase false`, action.workspace, action.silent);
|
||||||
} while (rejected);
|
}
|
||||||
|
catch (_a) {
|
||||||
|
if (throwOnError) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
yield configureGit(false);
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
// Attempt to re-run if initial configuration failed using git init.
|
||||||
|
yield (0, execute_1.execute)(`git init`, action.workspace, action.silent);
|
||||||
|
yield (0, execute_1.execute)(`git commit -m "Initial commit" --allow-empty`, action.workspace, action.silent);
|
||||||
|
yield configureGit(true);
|
||||||
|
}
|
||||||
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.
|
||||||
@ -55,7 +61,7 @@ function init(action) {
|
|||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (_a) {
|
catch (_b) {
|
||||||
(0, core_1.info)('Unable to unset previous git config authentication as it may not exist, continuing…');
|
(0, core_1.info)('Unable to unset previous git config authentication as it may not exist, continuing…');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -64,7 +70,7 @@ function init(action) {
|
|||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (_b) {
|
catch (_c) {
|
||||||
(0, core_1.info)('Attempted to remove origin but failed, continuing…');
|
(0, core_1.info)('Attempted to remove origin but failed, continuing…');
|
||||||
}
|
}
|
||||||
yield (0, execute_1.execute)(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);
|
yield (0, execute_1.execute)(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);
|
||||||
|
Loading…
Reference in New Issue
Block a user