Skip to content

Commit 5a1b7c9

Browse files
authored
Merge pull request #284 from crazy-max/fix-git-auth-token
set GIT_AUTH_TOKEN secret if Git context used
2 parents ded8f8f + a23a0ce commit 5a1b7c9

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ jobs:
729729
name: Build
730730
uses: ./
731731
with:
732+
source: .
732733
files: |
733734
./test/config.hcl
734735
allow: network.host

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export function sanitizeInputs(inputs: Inputs) {
6868
return res;
6969
}
7070

71+
export function getGitAuthToken(inputs: Inputs): string {
72+
return process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs['github-token'];
73+
}
74+
7175
export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
7276
// prettier-ignore
7377
return [
@@ -97,6 +101,15 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
97101
await Util.asyncForEach(inputs.set, async set => {
98102
args.push('--set', set);
99103
});
104+
if (await toolkit.buildx.versionSatisfies('<0.20.0')) {
105+
// For buildx versions < 0.20.0, we need to set GIT_AUTH_TOKEN secret as it
106+
// doesn't infer BUILDX_BAKE_GIT_AUTH_TOKEN environment variable for build
107+
// request: https://github.com/docker/buildx/pull/2905
108+
const gitAuthToken = getGitAuthToken(inputs);
109+
if (gitAuthToken && !Bake.hasGitAuthTokenSecret(definition) && inputs.source.startsWith(Context.gitContext())) {
110+
args.push('--set', `*.secrets=${Build.resolveSecretString(`GIT_AUTH_TOKEN=${gitAuthToken}`)}`);
111+
}
112+
}
100113
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
101114
args.push('--metadata-file', toolkit.buildxBake.getMetadataFilePath());
102115
}

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ actionsToolkit.run(
3030
stateHelper.setInputs(inputs);
3131

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

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

0 commit comments

Comments
 (0)