GeezerVison is showing github.com — make cloud prefix optional to download buildx if driver is cloud · docker/setup-buildx-action@7199e57
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/ci.yml +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | - "" | 26 | 26 | - "latest" | 27 | 27 | - "v0.4.1" | | 28 | + - "cloud:latest" | | 29 | + - "cloud:v0.11.2-desktop.2" | 28 | 30 | - "lab:latest" | 29 | | - - "lab:v0.11.2-desktop.2" | 30 | 31 | steps: | 31 | 32 | - | 32 | 33 | name: Checkout | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/context.test.ts +134Lines changed: 134 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -323,6 +323,140 @@ describe('getAppendArgs', () => { | 323 | 323 | ); | 324 | 324 | }); | 325 | 325 |
| | 326 | +describe('getVersion', () => { | | 327 | + beforeEach(() => { | | 328 | + process.env = Object.keys(process.env).reduce((object, key) => { | | 329 | + if (!key.startsWith('INPUT_')) { | | 330 | + object[key] = process.env[key]; | | 331 | + } | | 332 | + return object; | | 333 | + }, {}); | | 334 | + }); | | 335 | + | | 336 | + // prettier-ignore | | 337 | + test.each([ | | 338 | + [ | | 339 | + 0, | | 340 | + new Map<string, string>([ | | 341 | + // defaults | | 342 | + ['install', 'false'], | | 343 | + ['use', 'true'], | | 344 | + ['cache-binary', 'true'], | | 345 | + ['cleanup', 'true'], | | 346 | + ]), | | 347 | + '' | | 348 | + ], | | 349 | + [ | | 350 | + 1, | | 351 | + new Map<string, string>([ | | 352 | + ['version', 'latest'], | | 353 | + // defaults | | 354 | + ['install', 'false'], | | 355 | + ['use', 'true'], | | 356 | + ['cache-binary', 'true'], | | 357 | + ['cleanup', 'true'] | | 358 | + ]), | | 359 | + 'latest' | | 360 | + ], | | 361 | + [ | | 362 | + 2, | | 363 | + new Map<string, string>([ | | 364 | + ['version', 'edge'], | | 365 | + // defaults | | 366 | + ['install', 'false'], | | 367 | + ['use', 'true'], | | 368 | + ['cache-binary', 'true'], | | 369 | + ['cleanup', 'true'] | | 370 | + ]), | | 371 | + 'edge' | | 372 | + ], | | 373 | + [ | | 374 | + 3, | | 375 | + new Map<string, string>([ | | 376 | + ['version', 'v0.19.2'], | | 377 | + // defaults | | 378 | + ['install', 'false'], | | 379 | + ['use', 'true'], | | 380 | + ['cache-binary', 'true'], | | 381 | + ['cleanup', 'true'] | | 382 | + ]), | | 383 | + 'v0.19.2' | | 384 | + ], | | 385 | + [ | | 386 | + 4, | | 387 | + new Map<string, string>([ | | 388 | + ['version', 'latest'], | | 389 | + ['driver', 'cloud'], | | 390 | + // defaults | | 391 | + ['install', 'false'], | | 392 | + ['use', 'true'], | | 393 | + ['cache-binary', 'true'], | | 394 | + ['cleanup', 'true'] | | 395 | + ]), | | 396 | + 'cloud:latest' | | 397 | + ], | | 398 | + [ | | 399 | + 5, | | 400 | + new Map<string, string>([ | | 401 | + ['version', 'edge'], | | 402 | + ['driver', 'cloud'], | | 403 | + // defaults | | 404 | + ['install', 'false'], | | 405 | + ['use', 'true'], | | 406 | + ['cache-binary', 'true'], | | 407 | + ['cleanup', 'true'] | | 408 | + ]), | | 409 | + 'cloud:edge' | | 410 | + ], | | 411 | + [ | | 412 | + 6, | | 413 | + new Map<string, string>([ | | 414 | + ['driver', 'cloud'], | | 415 | + // defaults | | 416 | + ['install', 'false'], | | 417 | + ['use', 'true'], | | 418 | + ['cache-binary', 'true'], | | 419 | + ['cleanup', 'true'], | | 420 | + ]), | | 421 | + 'cloud:latest' | | 422 | + ], | | 423 | + [ | | 424 | + 7, | | 425 | + new Map<string, string>([ | | 426 | + ['version', 'cloud:v0.11.2-desktop.2'], | | 427 | + ['driver', 'cloud'], | | 428 | + // defaults | | 429 | + ['install', 'false'], | | 430 | + ['use', 'true'], | | 431 | + ['cache-binary', 'true'], | | 432 | + ['cleanup', 'true'], | | 433 | + ]), | | 434 | + 'cloud:v0.11.2-desktop.2' | | 435 | + ], | | 436 | + [ | | 437 | + 8, | | 438 | + new Map<string, string>([ | | 439 | + ['version', 'cloud:v0.11.2-desktop.2'], | | 440 | + // defaults | | 441 | + ['install', 'false'], | | 442 | + ['use', 'true'], | | 443 | + ['cache-binary', 'true'], | | 444 | + ['cleanup', 'true'], | | 445 | + ]), | | 446 | + 'cloud:v0.11.2-desktop.2' | | 447 | + ], | | 448 | + ])( | | 449 | + '[%d] given %p as inputs, returns version %p', | | 450 | + async (num: number, inputs: Map<string, string>, expected: string) => { | | 451 | + inputs.forEach((value: string, name: string) => { | | 452 | + setInput(name, value); | | 453 | + }); | | 454 | + const inp = await context.getInputs(); | | 455 | + expect(context.getVersion(inp)).toEqual(expected); | | 456 | + } | | 457 | + ); | | 458 | +}); | | 459 | + | 326 | 460 | // See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67 | 327 | 461 | function getInputName(name: string): string { | 328 | 462 | return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; | |
Collapse file Copy file name to clipboardExpand all lines: src/context.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,3 +116,17 @@ export async function getInspectArgs(inputs: Inputs, toolkit: Toolkit): Promise< | 116 | 116 | function driverSupportsBuildkitdFlags(driver: string): boolean { | 117 | 117 | return driver == '' || driver == 'docker-container' || driver == 'docker' || driver == 'kubernetes'; | 118 | 118 | } | | 119 | + | | 120 | +export function getVersion(inputs: Inputs): string { | | 121 | + const version = inputs.version; | | 122 | + if (inputs.driver === 'cloud') { | | 123 | + if (!version || version === 'latest') { | | 124 | + return 'cloud:latest'; | | 125 | + } | | 126 | + if (version.startsWith('cloud:') || version.startsWith('lab:')) { | | 127 | + return version; | | 128 | + } | | 129 | + return `cloud:${version}`; | | 130 | + } | | 131 | + return version; | | 132 | +} |
Collapse file Copy file name to clipboardExpand all lines: src/main.ts +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,6 +22,7 @@ actionsToolkit.run( | 22 | 22 | async () => { | 23 | 23 | const inputs: context.Inputs = await context.getInputs(); | 24 | 24 | stateHelper.setCleanup(inputs.cleanup); | | 25 | + const version = context.getVersion(inputs); | 25 | 26 |
| 26 | 27 | const toolkit = new Toolkit(); | 27 | 28 | const standalone = await toolkit.buildx.isStandalone(); | @@ -37,16 +38,16 @@ actionsToolkit.run( | 37 | 38 | }); | 38 | 39 |
| 39 | 40 | let toolPath; | 40 | | - if (Util.isValidRef(inputs.version)) { | | 41 | + if (Util.isValidRef(version)) { | 41 | 42 | if (standalone) { | 42 | 43 | throw new Error(`Cannot build from source without the Docker CLI`); | 43 | 44 | } | 44 | 45 | await core.group(`Build buildx from source`, async () => { | 45 | | - toolPath = await toolkit.buildxInstall.build(inputs.version, !inputs.cacheBinary); | | 46 | + toolPath = await toolkit.buildxInstall.build(version, !inputs.cacheBinary); | 46 | 47 | }); | 47 | | - } else if (!(await toolkit.buildx.isAvailable()) || inputs.version) { | | 48 | + } else if (!(await toolkit.buildx.isAvailable()) || version) { | 48 | 49 | await core.group(`Download buildx from GitHub Releases`, async () => { | 49 | | - toolPath = await toolkit.buildxInstall.download(inputs.version || 'latest', !inputs.cacheBinary); | | 50 | + toolPath = await toolkit.buildxInstall.download(version || 'latest', !inputs.cacheBinary); | 50 | 51 | }); | 51 | 52 | } | 52 | 53 | if (toolPath) { | |
|