Skip to content

Commit

Permalink
Merge pull request #284 from crazy-max/fix-git-auth-token
Browse files Browse the repository at this point in the history
set GIT_AUTH_TOKEN secret if Git context used
  • Loading branch information
crazy-max authored Jan 14, 2025
2 parents ded8f8f + a23a0ce commit 5a1b7c9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ jobs:
name: Build
uses: ./
with:
source: .
files: |
./test/config.hcl
allow: network.host
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export function sanitizeInputs(inputs: Inputs) {
return res;
}

export function getGitAuthToken(inputs: Inputs): string {
return process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs['github-token'];
}

export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
// prettier-ignore
return [
Expand Down Expand Up @@ -97,6 +101,15 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
await Util.asyncForEach(inputs.set, async set => {
args.push('--set', set);
});
if (await toolkit.buildx.versionSatisfies('<0.20.0')) {
// For buildx versions < 0.20.0, we need to set GIT_AUTH_TOKEN secret as it
// doesn't infer BUILDX_BAKE_GIT_AUTH_TOKEN environment variable for build
// request: https://github.com/docker/buildx/pull/2905
const gitAuthToken = getGitAuthToken(inputs);
if (gitAuthToken && !Bake.hasGitAuthTokenSecret(definition) && inputs.source.startsWith(Context.gitContext())) {
args.push('--set', `*.secrets=${Build.resolveSecretString(`GIT_AUTH_TOKEN=${gitAuthToken}`)}`);
}
}
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
args.push('--metadata-file', toolkit.buildxBake.getMetadataFilePath());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ actionsToolkit.run(
stateHelper.setInputs(inputs);

const toolkit = new Toolkit();
const gitAuthToken = process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs['github-token'];
const gitAuthToken = context.getGitAuthToken(inputs);

await core.group(`GitHub Actions runtime token ACs`, async () => {
try {
Expand Down

0 comments on commit 5a1b7c9

Please sign in to comment.