Skip to content

Commit 95438bc

Browse files
authored
Merge pull request #497 from omus/cv/output-env
Support disabling `DOCKER_METADATA_OUTPUT_*` environment variables
2 parents 8e1d546 + 0e4a06e commit 95438bc

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,32 @@ jobs:
472472
DOCKER_METADATA_OUTPUT_ANNOTATIONS
473473
DOCKER_METADATA_OUTPUT_JSON
474474
475+
no-output-env:
476+
runs-on: ubuntu-latest
477+
env:
478+
DOCKER_METADATA_SET_OUTPUT_ENV: false
479+
steps:
480+
-
481+
name: Checkout
482+
uses: actions/checkout@v4
483+
-
484+
name: Docker meta
485+
id: meta
486+
uses: ./
487+
with:
488+
images: |
489+
${{ env.DOCKER_IMAGE }}
490+
ghcr.io/name/app
491+
labels: |
492+
maintainer=CrazyMax
493+
annotations: |
494+
maintainer=Foo
495+
-
496+
name: No output environment variables set
497+
shell: bash
498+
run: |
499+
[[ "$(printenv | grep "^DOCKER_METADATA_OUTPUT_" | wc -l)" -eq 0 ]] || exit 1
500+
475501
bake-annotations:
476502
runs-on: ubuntu-latest
477503
steps:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ The following outputs are available:
319319
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
320320
| `bake-file-annotations` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
321321

322-
Alternatively, each output is also exported as an environment variable:
322+
Alternatively, each output is also exported as an environment variable when `DOCKER_METADATA_SET_OUTPUT_ENV` is `true`:
323323

324324
* `DOCKER_METADATA_OUTPUT_VERSION`
325325
* `DOCKER_METADATA_OUTPUT_TAGS`
@@ -346,6 +346,7 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/
346346
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
347347
| `DOCKER_METADATA_SHORT_SHA_LENGTH` | Number | Specifies the length of the [short commit SHA](#typesha) to ensure uniqueness. Default is `7`, but can be increased for larger repositories. |
348348
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
349+
| `DOCKER_METADATA_SET_OUTPUT_ENV` | Bool | If `true`, sets each output as an environment variable (default `true`) |
349350

350351
## `context` input
351352

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs';
22
import * as core from '@actions/core';
33
import * as actionsToolkit from '@docker/actions-toolkit';
44
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
5+
import {Util} from '@docker/actions-toolkit/lib/util';
56

67
import {getContext, getInputs, Inputs} from './context';
78
import {Meta, Version} from './meta';
@@ -13,6 +14,7 @@ actionsToolkit.run(
1314
const toolkit = new Toolkit({githubToken: inputs.githubToken});
1415
const context = await getContext(inputs.context, toolkit);
1516
const repo = await toolkit.github.repoData();
17+
const setOutput = outputEnvEnabled() ? setOutputAndEnv : core.setOutput;
1618

1719
await core.group(`Context info`, async () => {
1820
core.info(`eventName: ${context.eventName}`);
@@ -105,7 +107,14 @@ actionsToolkit.run(
105107
}
106108
);
107109

108-
function setOutput(name: string, value: string) {
110+
function setOutputAndEnv(name: string, value: string) {
109111
core.setOutput(name, value);
110112
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
111113
}
114+
115+
function outputEnvEnabled(): boolean {
116+
if (process.env.DOCKER_METADATA_SET_OUTPUT_ENV) {
117+
return Util.parseBool(process.env.DOCKER_METADATA_SET_OUTPUT_ENV);
118+
}
119+
return true;
120+
}

0 commit comments

Comments
 (0)