Skip to content

Commit 9482720

Browse files
committed
Handle git sha version of buildx
Signed-off-by: CrazyMax <[email protected]>
1 parent 128f05c commit 9482720

File tree

7 files changed

+39
-38
lines changed

7 files changed

+39
-38
lines changed

.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 120,
2+
"printWidth": 240,
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,

__tests__/buildx.test.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,20 @@ describe('parseVersion', () => {
128128
test.each([
129129
['github.com/docker/buildx 0.4.1+azure bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
130130
['github.com/docker/buildx v0.4.1 bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
131-
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2']
131+
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2'],
132+
['github.com/docker/buildx f117971 f11797113e5a9b86bd976329c5dbb8a8bfdfadfa', 'f117971']
132133
])('given %p', async (stdout, expected) => {
133-
expect(await buildx.parseVersion(stdout)).toEqual(expected);
134+
expect(buildx.parseVersion(stdout)).toEqual(expected);
135+
});
136+
});
137+
138+
describe('satisfies', () => {
139+
test.each([
140+
['0.4.1', '>=0.3.2', true],
141+
['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false],
142+
['f117971', '>0.6.0', true]
143+
])('given %p', async (version, range, expected) => {
144+
expect(buildx.satisfies(version, range)).toBe(expected);
134145
});
135146
});
136147

@@ -142,13 +153,7 @@ describe('getSecret', () => {
142153
['aaaaaaaa', false, '', '', true],
143154
['aaaaaaaa=', false, '', '', true],
144155
['=bbbbbbb', false, '', '', true],
145-
[
146-
`foo=${path.join(__dirname, 'fixtures', 'secret.txt').split(path.sep).join(path.posix.sep)}`,
147-
true,
148-
'foo',
149-
'bar',
150-
false
151-
],
156+
[`foo=${path.join(__dirname, 'fixtures', 'secret.txt').split(path.sep).join(path.posix.sep)}`, true, 'foo', 'bar', false],
152157
[`notfound=secret`, true, '', '', true]
153158
])('given %p key and %p secret', async (kvp, file, exKey, exValue, invalid) => {
154159
try {

__tests__/context.test.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,7 @@ FOO=bar`
565565
);
566566
const res = await context.getInputList('secrets', true);
567567
console.log(res);
568-
expect(res).toEqual([
569-
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
570-
'MYSECRET=aaaaaaaa',
571-
'bbbbbbb',
572-
'ccccccccc',
573-
'FOO=bar'
574-
]);
568+
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
575569
});
576570

577571
it('large multiline values', async () => {

codecov.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment: false
2+
github_checks:
3+
annotations: false

dist/index.js

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildx.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ export async function getVersion(): Promise<string> {
107107
});
108108
}
109109

110-
export async function parseVersion(stdout: string): Promise<string> {
111-
const matches = /\sv?([0-9.]+)/.exec(stdout);
110+
export function parseVersion(stdout: string): string {
111+
const matches = /\sv?([0-9a-f]{7}|[0-9.]+)/.exec(stdout);
112112
if (!matches) {
113113
throw new Error(`Cannot parse buildx version`);
114114
}
115-
return semver.clean(matches[1]);
115+
return matches[1];
116+
}
117+
118+
export function satisfies(version: string, range: string): boolean {
119+
return semver.satisfies(version, range) || /^[0-9a-f]{7}$/.exec(version) !== null;
116120
}

src/context.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ export function defaultContext(): string {
4646
if (github.context.sha && !ref.startsWith(`refs/pull/`)) {
4747
ref = github.context.sha;
4848
}
49-
_defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${
50-
github.context.repo.repo
51-
}.git#${ref}`;
49+
_defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${github.context.repo.repo}.git#${ref}`;
5250
}
5351
return _defaultContext;
5452
}
@@ -121,10 +119,7 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
121119
await asyncForEach(inputs.outputs, async output => {
122120
args.push('--output', output);
123121
});
124-
if (
125-
!buildx.isLocalOrTarExporter(inputs.outputs) &&
126-
(inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2'))
127-
) {
122+
if (!buildx.isLocalOrTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || buildx.satisfies(buildxVersion, '>=0.4.2'))) {
128123
args.push('--iidfile', await buildx.getImageIDFile());
129124
}
130125
await asyncForEach(inputs.cacheFrom, async cacheFrom => {

0 commit comments

Comments
 (0)