Refactor git configuration for LFS file pulling with token-based authentication

- Enhanced the process of configuring git to use GIT_PRIVATE_TOKEN and GITHUB_TOKEN by clearing existing URL configurations before setting new ones.
- Improved the clarity of the URL replacement commands for better readability and maintainability.
- This change ensures a more robust setup for pulling LFS files in environments requiring token authentication.
This commit is contained in:
Frostebite 2025-04-14 06:46:51 +01:00
parent 10fc07a79b
commit 1815c3c880
3 changed files with 18 additions and 7 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -231,14 +231,20 @@ export class RemoteClient {
throw new Error('GIT_PRIVATE_TOKEN is not available');
}
// Clear any existing URL configurations
await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`);
// Set new URL configuration with token
await CloudRunnerSystem.Run(
`git config --global --replace-all url."https://token:${gitPrivateToken}@github.com/".insteadOf ssh://git@github.com/`,
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`,
);
await CloudRunnerSystem.Run(
`git config --global --add url."https://token:${gitPrivateToken}@github.com/".insteadOf git@github.com`,
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "ssh://git@github.com/"`,
);
await CloudRunnerSystem.Run(
`git config --global --add url."https://token:${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`,
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "git@github.com"`,
);
await CloudRunnerSystem.Run(`git lfs pull`);
@ -255,15 +261,20 @@ export class RemoteClient {
throw new Error('GITHUB_TOKEN is not available as fallback');
}
// Configure git to use GITHUB_TOKEN
// Clear any existing URL configurations
await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`);
await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`);
// Set new URL configuration with token
await CloudRunnerSystem.Run(
`git config --global --replace-all url."https://token:${githubToken}@github.com/".insteadOf ssh://git@github.com/`,
`git config --global url."https://${githubToken}@github.com/".insteadOf "https://github.com/"`,
);
await CloudRunnerSystem.Run(
`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf git@github.com`,
`git config --global url."https://${githubToken}@github.com/".insteadOf "ssh://git@github.com/"`,
);
await CloudRunnerSystem.Run(
`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf "https://github.com/"`,
`git config --global url."https://${githubToken}@github.com/".insteadOf "git@github.com"`,
);
await CloudRunnerSystem.Run(`git lfs pull`);