Enhance LFS file pulling with token fallback mechanism
- Implemented a primary attempt to pull LFS files using GIT_PRIVATE_TOKEN. - Added a fallback mechanism to use GITHUB_TOKEN if the initial attempt fails. - Configured git to replace SSH and HTTPS URLs with token-based authentication for the fallback. - Improved error handling to log specific failure messages for both token attempts. This change ensures more robust handling of LFS file retrieval in various authentication scenarios.pull/729/head
parent
81ed299e10
commit
a1f3d9ecd4
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -222,9 +222,43 @@ export class RemoteClient {
|
|||
await CloudRunnerSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge -- %f"`);
|
||||
await CloudRunnerSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process"`);
|
||||
if (!CloudRunner.buildParameters.skipLfs) {
|
||||
await CloudRunnerSystem.Run(`git lfs pull`);
|
||||
RemoteClientLogger.log(`pulled latest LFS files`);
|
||||
assert(fs.existsSync(CloudRunnerFolders.lfsFolderAbsolute));
|
||||
try {
|
||||
RemoteClientLogger.log(`Attempting to pull LFS files with GIT_PRIVATE_TOKEN...`);
|
||||
await CloudRunnerSystem.Run(`git lfs pull`);
|
||||
RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`);
|
||||
assert(fs.existsSync(CloudRunnerFolders.lfsFolderAbsolute));
|
||||
} catch (error: any) {
|
||||
RemoteClientLogger.logCliError(`Failed to pull LFS files with GIT_PRIVATE_TOKEN: ${error.message}`);
|
||||
|
||||
// Try with GITHUB_TOKEN as fallback
|
||||
try {
|
||||
RemoteClientLogger.log(`Attempting to pull LFS files with GITHUB_TOKEN as fallback...`);
|
||||
const githubToken = process.env.GITHUB_TOKEN;
|
||||
if (!githubToken) {
|
||||
throw new Error('GITHUB_TOKEN is not available as fallback');
|
||||
}
|
||||
|
||||
// Configure git to use GITHUB_TOKEN
|
||||
await CloudRunnerSystem.Run(
|
||||
`git config --global --replace-all url."https://token:${githubToken}@github.com/".insteadOf ssh://git@github.com/`,
|
||||
);
|
||||
await CloudRunnerSystem.Run(
|
||||
`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf git@github.com`,
|
||||
);
|
||||
await CloudRunnerSystem.Run(
|
||||
`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf "https://github.com/"`,
|
||||
);
|
||||
|
||||
await CloudRunnerSystem.Run(`git lfs pull`);
|
||||
RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN fallback`);
|
||||
assert(fs.existsSync(CloudRunnerFolders.lfsFolderAbsolute));
|
||||
} catch (fallbackError: any) {
|
||||
RemoteClientLogger.logCliError(
|
||||
`Failed to pull LFS files with GITHUB_TOKEN fallback: ${fallbackError.message}`,
|
||||
);
|
||||
throw new Error(`Failed to pull LFS files with both tokens. Last error: ${fallbackError.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static async handleRetainedWorkspace() {
|
||||
|
|
Loading…
Reference in New Issue