Skip to content

Commit c6c363b

Browse files
authored
Merge pull request #979 from crazy-max/git-auth-token-domain
buildx(build): handle domain when checking git auth token secret
2 parents 57aacc3 + c790a5b commit c6c363b

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

__tests__/buildx/build.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,11 @@ describe('resolveAttestationAttrs', () => {
348348
describe('hasGitAuthTokenSecret', () => {
349349
// prettier-ignore
350350
test.each([
351-
[['A_SECRET=abcdef0123456789'], false],
352-
[['GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'], true],
353-
])('given %p secret', async (kvp: Array<string>, expected: boolean) => {
354-
expect(Build.hasGitAuthTokenSecret(kvp)).toBe(expected);
351+
[['A_SECRET=abcdef0123456789'], undefined, false],
352+
[['GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'], undefined, true],
353+
[['GIT_AUTH_TOKEN.github.com=abcdefghijklmno=0123456789'], 'github.com', true],
354+
])('given %p secret', async (kvp: Array<string>, domain: string | undefined, expected: boolean) => {
355+
expect(Build.hasGitAuthTokenSecret(kvp, domain)).toBe(expected);
355356
});
356357
});
357358

src/buildx/build.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ export class Build {
310310
return res.join(',');
311311
}
312312

313-
public static hasGitAuthTokenSecret(secrets: string[]): boolean {
313+
public static hasGitAuthTokenSecret(secrets: string[], domain?: string): boolean {
314314
for (const secret of secrets) {
315-
if (secret.startsWith('GIT_AUTH_TOKEN=')) {
315+
if (domain && secret.startsWith(`GIT_AUTH_TOKEN.${domain}=`)) {
316+
return true;
317+
} else if (secret.startsWith('GIT_AUTH_TOKEN=')) {
316318
return true;
317319
}
318320
}

0 commit comments

Comments
 (0)