Merge pull request #390 from crazy-max/buildx-cloud-latest
Some checks failed
ci / main () (push) Has been cancelled
ci / main (cloud:latest) (push) Has been cancelled
ci / main (cloud:v0.11.2-desktop.2) (push) Has been cancelled
ci / main (lab:latest) (push) Has been cancelled
ci / main (latest) (push) Has been cancelled
ci / main (v0.4.1) (push) Has been cancelled
ci / multi (push) Has been cancelled
ci / error (push) Has been cancelled
ci / debug (push) Has been cancelled
ci / install (push) Has been cancelled
ci / use (false) (push) Has been cancelled
ci / use (true) (push) Has been cancelled
ci / driver (image=moby/buildkit:latest) (push) Has been cancelled
ci / driver (image=moby/buildkit:master network=host ) (push) Has been cancelled
ci / docker-driver (push) Has been cancelled
ci / endpoint (push) Has been cancelled
ci / config (push) Has been cancelled
ci / config-inline (push) Has been cancelled
ci / with-qemu (, all) (push) Has been cancelled
ci / with-qemu (, arm64,riscv64,arm) (push) Has been cancelled
ci / with-qemu (v0.9.1, all) (push) Has been cancelled
ci / with-qemu (v0.9.1, arm64,riscv64,arm) (push) Has been cancelled
ci / build-ref (cb185f095fd3d9444e0aa605d3789e9e05f2a1e7) (push) Has been cancelled
ci / build-ref (master) (push) Has been cancelled
ci / build-ref (refs/pull/731/head) (push) Has been cancelled
ci / build-ref (refs/tags/v0.5.1) (push) Has been cancelled
ci / standalone-cmd (push) Has been cancelled
ci / standalone-action (push) Has been cancelled
ci / standalone-install-error (push) Has been cancelled
ci / append (push) Has been cancelled
ci / platforms (push) Has been cancelled
ci / docker-context (push) Has been cancelled
ci / cleanup (false) (push) Has been cancelled
ci / cleanup (true) (push) Has been cancelled
ci / k3s (v0.10.5) (push) Has been cancelled
ci / k3s (v0.11.0) (push) Has been cancelled
ci / cache-binary (false) (push) Has been cancelled
ci / cache-binary (true) (push) Has been cancelled
test / test (push) Has been cancelled
validate / prepare (push) Has been cancelled
validate / validate (push) Has been cancelled

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" - "latest"
- "v0.4.1" - "v0.4.1"
- "cloud:latest"
- "cloud:v0.11.2-desktop.2"
- "lab:latest" - "lab:latest"
- "lab:v0.11.2-desktop.2"
steps: steps:
- -
name: Checkout 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 // See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
function getInputName(name: string): string { function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; 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 { function driverSupportsBuildkitdFlags(driver: string): boolean {
return driver == '' || driver == 'docker-container' || driver == 'docker' || driver == 'kubernetes'; 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 () => { async () => {
const inputs: context.Inputs = await context.getInputs(); const inputs: context.Inputs = await context.getInputs();
stateHelper.setCleanup(inputs.cleanup); stateHelper.setCleanup(inputs.cleanup);
const version = context.getVersion(inputs);
const toolkit = new Toolkit(); const toolkit = new Toolkit();
const standalone = await toolkit.buildx.isStandalone(); const standalone = await toolkit.buildx.isStandalone();
@ -37,16 +38,16 @@ actionsToolkit.run(
}); });
let toolPath; let toolPath;
if (Util.isValidRef(inputs.version)) { if (Util.isValidRef(version)) {
if (standalone) { if (standalone) {
throw new Error(`Cannot build from source without the Docker CLI`); throw new Error(`Cannot build from source without the Docker CLI`);
} }
await core.group(`Build buildx from source`, async () => { 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 () => { 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) { if (toolPath) {