Merge pull request #390 from crazy-max/buildx-cloud-latest

make cloud prefix optional to download buildx if driver is cloud
This commit is contained in:
Tõnis Tiigi 2024-12-12 10:30:19 -08:00 committed by GitHub
commit 6524bf65af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 157 additions and 7 deletions

View File

@ -25,8 +25,9 @@ jobs:
- ""
- "latest"
- "v0.4.1"
- "cloud:latest"
- "cloud:v0.11.2-desktop.2"
- "lab:latest"
- "lab:v0.11.2-desktop.2"
steps:
-
name: Checkout

View File

@ -323,6 +323,140 @@ describe('getAppendArgs', () => {
);
});
describe('getVersion', () => {
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
if (!key.startsWith('INPUT_')) {
object[key] = process.env[key];
}
return object;
}, {});
});
// prettier-ignore
test.each([
[
0,
new Map<string, string>([
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
''
],
[
1,
new Map<string, string>([
['version', 'latest'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true']
]),
'latest'
],
[
2,
new Map<string, string>([
['version', 'edge'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true']
]),
'edge'
],
[
3,
new Map<string, string>([
['version', 'v0.19.2'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true']
]),
'v0.19.2'
],
[
4,
new Map<string, string>([
['version', 'latest'],
['driver', 'cloud'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true']
]),
'cloud:latest'
],
[
5,
new Map<string, string>([
['version', 'edge'],
['driver', 'cloud'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true']
]),
'cloud:edge'
],
[
6,
new Map<string, string>([
['driver', 'cloud'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
'cloud:latest'
],
[
7,
new Map<string, string>([
['version', 'cloud:v0.11.2-desktop.2'],
['driver', 'cloud'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
'cloud:v0.11.2-desktop.2'
],
[
8,
new Map<string, string>([
['version', 'cloud:v0.11.2-desktop.2'],
// defaults
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
'cloud:v0.11.2-desktop.2'
],
])(
'[%d] given %p as inputs, returns version %p',
async (num: number, inputs: Map<string, string>, expected: string) => {
inputs.forEach((value: string, name: string) => {
setInput(name, value);
});
const inp = await context.getInputs();
expect(context.getVersion(inp)).toEqual(expected);
}
);
});
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -116,3 +116,17 @@ export async function getInspectArgs(inputs: Inputs, toolkit: Toolkit): Promise<
function driverSupportsBuildkitdFlags(driver: string): boolean {
return driver == '' || driver == 'docker-container' || driver == 'docker' || driver == 'kubernetes';
}
export function getVersion(inputs: Inputs): string {
const version = inputs.version;
if (inputs.driver === 'cloud') {
if (!version || version === 'latest') {
return 'cloud:latest';
}
if (version.startsWith('cloud:') || version.startsWith('lab:')) {
return version;
}
return `cloud:${version}`;
}
return version;
}

View File

@ -22,6 +22,7 @@ actionsToolkit.run(
async () => {
const inputs: context.Inputs = await context.getInputs();
stateHelper.setCleanup(inputs.cleanup);
const version = context.getVersion(inputs);
const toolkit = new Toolkit();
const standalone = await toolkit.buildx.isStandalone();
@ -37,16 +38,16 @@ actionsToolkit.run(
});
let toolPath;
if (Util.isValidRef(inputs.version)) {
if (Util.isValidRef(version)) {
if (standalone) {
throw new Error(`Cannot build from source without the Docker CLI`);
}
await core.group(`Build buildx from source`, async () => {
toolPath = await toolkit.buildxInstall.build(inputs.version, !inputs.cacheBinary);
toolPath = await toolkit.buildxInstall.build(version, !inputs.cacheBinary);
});
} else if (!(await toolkit.buildx.isAvailable()) || inputs.version) {
} else if (!(await toolkit.buildx.isAvailable()) || version) {
await core.group(`Download buildx from GitHub Releases`, async () => {
toolPath = await toolkit.buildxInstall.download(inputs.version || 'latest', !inputs.cacheBinary);
toolPath = await toolkit.buildxInstall.download(version || 'latest', !inputs.cacheBinary);
});
}
if (toolPath) {