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.
pull/729/head
Frostebite 2025-04-14 06:46:51 +01:00
parent 10fc07a79b
commit 1815c3c880
3 changed files with 35 additions and 15 deletions

23
dist/index.js vendored
View File

@ -4632,9 +4632,14 @@ class RemoteClient {
if (!gitPrivateToken) { if (!gitPrivateToken) {
throw new Error('GIT_PRIVATE_TOKEN is not available'); throw new Error('GIT_PRIVATE_TOKEN is not available');
} }
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --replace-all url."https://token:${gitPrivateToken}@github.com/".insteadOf ssh://git@github.com/`); // Clear any existing URL configurations
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --add url."https://token:${gitPrivateToken}@github.com/".insteadOf git@github.com`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --add url."https://token:${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`);
// Set new URL configuration with token
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "ssh://git@github.com/"`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "git@github.com"`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs pull`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs pull`);
remote_client_logger_1.RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`); remote_client_logger_1.RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`);
(0, node_console_1.assert)(node_fs_1.default.existsSync(cloud_runner_folders_1.CloudRunnerFolders.lfsFolderAbsolute)); (0, node_console_1.assert)(node_fs_1.default.existsSync(cloud_runner_folders_1.CloudRunnerFolders.lfsFolderAbsolute));
@ -4648,10 +4653,14 @@ class RemoteClient {
if (!githubToken) { if (!githubToken) {
throw new Error('GITHUB_TOKEN is not available as fallback'); throw new Error('GITHUB_TOKEN is not available as fallback');
} }
// Configure git to use GITHUB_TOKEN // Clear any existing URL configurations
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --replace-all url."https://token:${githubToken}@github.com/".insteadOf ssh://git@github.com/`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf git@github.com`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf "https://github.com/"`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`);
// Set new URL configuration with token
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global url."https://${githubToken}@github.com/".insteadOf "https://github.com/"`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global url."https://${githubToken}@github.com/".insteadOf "ssh://git@github.com/"`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git config --global url."https://${githubToken}@github.com/".insteadOf "git@github.com"`);
await cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs pull`); await cloud_runner_system_1.CloudRunnerSystem.Run(`git lfs pull`);
remote_client_logger_1.RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN fallback`); remote_client_logger_1.RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN fallback`);
(0, node_console_1.assert)(node_fs_1.default.existsSync(cloud_runner_folders_1.CloudRunnerFolders.lfsFolderAbsolute)); (0, node_console_1.assert)(node_fs_1.default.existsSync(cloud_runner_folders_1.CloudRunnerFolders.lfsFolderAbsolute));

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -231,14 +231,20 @@ export class RemoteClient {
throw new Error('GIT_PRIVATE_TOKEN is not available'); 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( 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( 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( 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`); await CloudRunnerSystem.Run(`git lfs pull`);
@ -255,15 +261,20 @@ export class RemoteClient {
throw new Error('GITHUB_TOKEN is not available as fallback'); 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( 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( 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( 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`); await CloudRunnerSystem.Run(`git lfs pull`);