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
Frostebite 2025-04-13 18:49:33 +01:00
parent 81ed299e10
commit a1f3d9ecd4
4 changed files with 2934 additions and 1588 deletions

3210
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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() {

1270
yarn.lock

File diff suppressed because it is too large Load Diff