This commit is contained in:
eric sciple
2025-10-14 18:39:36 +00:00
parent bcc5319a0b
commit d9b320ec70

View File

@@ -318,33 +318,37 @@ class GitAuthHelper {
} else { } else {
// For local config, use includeIf.gitdir to match the .git directory. // For local config, use includeIf.gitdir to match the .git directory.
// Configure for both host and container paths to support Docker container actions. // Configure for both host and container paths to support Docker container actions.
const gitDir = path.join(this.git.getWorkingDirectory(), '.git') let gitDir = path.join(this.git.getWorkingDirectory(), '.git')
// Use forward slashes for git config, even on Windows
gitDir = gitDir.replace(/\\/g, '/')
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path` const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`
await this.git.config(hostIncludeKey, credentialsConfigPath) await this.git.config(hostIncludeKey, credentialsConfigPath)
this.credentialsIncludeKeys.push(hostIncludeKey) this.credentialsIncludeKeys.push(hostIncludeKey)
// Configure for container scenario where paths are mapped to fixed locations // Configure for container scenario where paths are mapped to fixed locations
const githubWorkspace = process.env['GITHUB_WORKSPACE'] const githubWorkspace = process.env['GITHUB_WORKSPACE']
if (githubWorkspace) { assert.ok(githubWorkspace, 'GITHUB_WORKSPACE is not defined')
// Calculate the relative path of the working directory from GITHUB_WORKSPACE
const workingDirectory = this.git.getWorkingDirectory() // Calculate the relative path of the working directory from GITHUB_WORKSPACE
const relativePath = path.relative(githubWorkspace, workingDirectory) const workingDirectory = this.git.getWorkingDirectory()
let relativePath = path.relative(githubWorkspace, workingDirectory)
// Container paths: GITHUB_WORKSPACE -> /github/workspace, RUNNER_TEMP -> /github/runner_temp // Container paths: GITHUB_WORKSPACE -> /github/workspace, RUNNER_TEMP -> /github/runner_temp
const containerGitDir = path.posix.join( // Use forward slashes for git config
'/github/workspace', relativePath = relativePath.replace(/\\/g, '/')
relativePath, const containerGitDir = path.posix.join(
'.git' '/github/workspace',
) relativePath,
const containerCredentialsPath = path.posix.join( '.git'
'/github/runner_temp', )
path.basename(credentialsConfigPath) const containerCredentialsPath = path.posix.join(
) '/github/runner_temp',
path.basename(credentialsConfigPath)
)
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path` const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`
await this.git.config(containerIncludeKey, containerCredentialsPath) await this.git.config(containerIncludeKey, containerCredentialsPath)
this.credentialsIncludeKeys.push(containerIncludeKey) this.credentialsIncludeKeys.push(containerIncludeKey)
}
} }
} }