From 20e79f657ab83054b492763f070068c6ae793c40 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Mon, 4 Mar 2024 08:44:17 -0600 Subject: [PATCH 1/2] feat: add option to save bake targets to ephemeral registry Signed-off-by: Chris Goller --- README.md | 24 ++++++++++++++---------- action.yml | 4 ++++ src/context.ts | 2 ++ src/depot.ts | 1 + src/index.ts | 13 +++++++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 88ffc01..b3231e0 100644 --- a/README.md +++ b/README.md @@ -83,13 +83,14 @@ This action needs a Depot API token to communicate with your project's builders. ### Depot-specific inputs -| Name | Type | Description | -| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `project` | String | Depot [project](https://depot.dev/docs/core-concepts#projects) ID to route the image build to your projects builders (default: the `depot.json` file at the root of your repo) | -| `token` | String | You must authenticate with the Depot API to communicate with your projects builders ([see Authentication above](#authentication)) | -| `build-platform` | String | The platform to use for the build ( `linux/amd64` or `linux/arm64`) | -| `lint` | Bool | Lint dockerfiles and fail build if any issues are of `error` severity. (default `false`) | -| `lint-fail-on` | String | Severity of linter issue to cause the build to fail. (`error`, `warn`, `info`, `none`) | +| Name | Type | Description | +| ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `project` | String | Depot [project](https://depot.dev/docs/core-concepts#projects) ID to route the image build to your projects builders (default: the `depot.json` file at the root of your repo) | +| `token` | String | You must authenticate with the Depot API to communicate with your projects builders ([see Authentication above](#authentication)) | +| `build-platform` | String | The platform to use for the build ( `linux/amd64` or `linux/arm64`) | +| `lint` | Bool | Lint dockerfiles and fail build if any issues are of `error` severity. (default `false`) | +| `lint-fail-on` | String | Severity of linter issue to cause the build to fail. (`error`, `warn`, `info`, `none`) | +| `save` | Boolean | Save the image to the Depot ephemeral registry (for use with the [depot/pull-action](https://github.com/depot/pull-action)) | ### General inputs @@ -111,9 +112,12 @@ The following inputs can be used as `step.with` keys and match the inputs from [ ## Outputs -| Name | Type | Description | -| ---------- | ---- | --------------------- | -| `metadata` | JSON | Build result metadata | +| Name | Type | Description | +| ------------ | ------ | --------------------- | +| `metadata` | JSON | Build result metadata | +| `project-id` | String | Depot Project ID | +| `build-id` | String | Depot Build ID | +| `targets` | Array | Saved Bake Targets | ## License diff --git a/action.yml b/action.yml index 4ec93f6..c878495 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,10 @@ inputs: description: 'Push is a shorthand for --set=*.output=type=registry' required: false default: 'false' + save: + description: 'Save the image to the Depot ephemeral registry' + required: false + default: 'false' sbom: description: 'SBOM is a shorthand for --set=*.attest=type=sbom' required: false diff --git a/src/context.ts b/src/context.ts index 17473ae..4aa3bdd 100644 --- a/src/context.ts +++ b/src/context.ts @@ -17,6 +17,7 @@ export interface Inputs { load: boolean provenance: string push: boolean + save: boolean sbom: string sbomDir: string set: string[] @@ -39,6 +40,7 @@ export function getInputs(): Inputs { load: core.getBooleanInput('load'), provenance: getProvenanceInput(), push: core.getBooleanInput('push'), + save: core.getBooleanInput('save'), sbom: core.getInput('sbom'), sbomDir: core.getInput('sbom-dir'), set: Util.getInputList('set', {ignoreComma: true, quote: false}), diff --git a/src/depot.ts b/src/depot.ts index d3e564b..ef1689c 100644 --- a/src/depot.ts +++ b/src/depot.ts @@ -100,6 +100,7 @@ export async function bake(inputs: Inputs) { ...flag('--build-platform', inputs.buildPlatform), ...flag('--lint', inputs.lint), ...flag('--lint-fail-on', inputs.lintFailOn), + ...flag('--save', inputs.save), ] const args = [...bakeArgs, ...depotArgs, ...targets] diff --git a/src/index.ts b/src/index.ts index 7daf513..7ecfc39 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,19 @@ async function main() { await core.group(`Metadata`, async () => { core.info(metadata) core.setOutput('metadata', metadata) + + try { + const parsed = JSON.parse(metadata) + if (parsed?.['depot.build']?.buildID) { + core.setOutput('build-id', parsed['depot.build'].buildID) + } + if (parsed?.['depot.build']?.projectID) { + core.setOutput('project-id', parsed['depot.build'].projectID) + } + if (parsed?.['depot.build']?.targets) { + core.setOutput('targets', parsed['depot.build'].targets) + } + } catch {} }) } } From d9ac2b7217c266fa4fe7ba8832bbd61a75bfd9fb Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Mon, 4 Mar 2024 08:58:57 -0600 Subject: [PATCH 2/2] fix: add built module Signed-off-by: Chris Goller --- dist/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 2be6c56..cf58d61 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74336,6 +74336,7 @@ function getInputs() { load: core.getBooleanInput("load"), provenance: getProvenanceInput(), push: core.getBooleanInput("push"), + save: core.getBooleanInput("save"), sbom: core.getInput("sbom"), sbomDir: core.getInput("sbom-dir"), set: import_util.Util.getInputList("set", { ignoreComma: true, quote: false }), @@ -76065,7 +76066,8 @@ async function bake(inputs) { ...flag("--project", inputs.project), ...flag("--build-platform", inputs.buildPlatform), ...flag("--lint", inputs.lint), - ...flag("--lint-fail-on", inputs.lintFailOn) + ...flag("--lint-fail-on", inputs.lintFailOn), + ...flag("--save", inputs.save) ]; const args = [...bakeArgs, ...depotArgs, ...targets]; let token = inputs.token ?? process.env.DEPOT_TOKEN; @@ -76149,8 +76151,22 @@ async function main() { const metadata = getMetadata(); if (metadata) { await core3.group(`Metadata`, async () => { + var _a, _b, _c; core3.info(metadata); core3.setOutput("metadata", metadata); + try { + const parsed = JSON.parse(metadata); + if ((_a = parsed == null ? void 0 : parsed["depot.build"]) == null ? void 0 : _a.buildID) { + core3.setOutput("build-id", parsed["depot.build"].buildID); + } + if ((_b = parsed == null ? void 0 : parsed["depot.build"]) == null ? void 0 : _b.projectID) { + core3.setOutput("project-id", parsed["depot.build"].projectID); + } + if ((_c = parsed == null ? void 0 : parsed["depot.build"]) == null ? void 0 : _c.targets) { + core3.setOutput("targets", parsed["depot.build"].targets); + } + } catch { + } }); } }