Skip to content

Commit c84f382

Browse files
authored
Merge pull request #663 from crazy-max/fix-git-token-cond
Fix GitHub token not passed with Git context if subdir defined
2 parents cd5d0b7 + 30a3224 commit c84f382

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

__tests__/context.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,25 @@ nproc=3`],
500500
'https://github.com/docker/build-push-action.git#refs/heads/test-jest:docker'
501501
]
502502
],
503+
[
504+
16,
505+
'0.8.2',
506+
new Map<string, string>([
507+
['github-token', 'abcdefghijklmno0123456789'],
508+
['context', '{{defaultContext}}:subdir'],
509+
['load', 'false'],
510+
['no-cache', 'false'],
511+
['push', 'false'],
512+
['pull', 'false'],
513+
]),
514+
[
515+
'build',
516+
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
517+
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
518+
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
519+
'https://github.com/docker/build-push-action.git#refs/heads/test-jest:subdir'
520+
]
521+
]
503522
])(
504523
'[%d] given %p with %p as inputs, returns %p',
505524
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,16 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
101101
}
102102

103103
export async function getArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise<Array<string>> {
104+
const context = handlebars.compile(inputs.context)({defaultContext});
104105
// prettier-ignore
105106
return [
106-
...await getBuildArgs(inputs, defaultContext, buildxVersion),
107+
...await getBuildArgs(inputs, defaultContext, context, buildxVersion),
107108
...await getCommonArgs(inputs, buildxVersion),
108-
handlebars.compile(inputs.context)({defaultContext})
109+
context
109110
];
110111
}
111112

112-
async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise<Array<string>> {
113+
async function getBuildArgs(inputs: Inputs, defaultContext: string, context: string, buildxVersion: string): Promise<Array<string>> {
113114
const args: Array<string> = ['build'];
114115
await asyncForEach(inputs.addHosts, async addHost => {
115116
args.push('--add-host', addHost);
@@ -166,7 +167,7 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
166167
core.warning(err.message);
167168
}
168169
});
169-
if (inputs.githubToken && !buildx.hasGitAuthToken(inputs.secrets) && inputs.context == defaultContext) {
170+
if (inputs.githubToken && !buildx.hasGitAuthToken(inputs.secrets) && context.startsWith(defaultContext)) {
170171
args.push('--secret', await buildx.getSecretString(`GIT_AUTH_TOKEN=${inputs.githubToken}`));
171172
}
172173
if (inputs.shmSize) {

0 commit comments

Comments
 (0)