Skip to content

Commit f66192e

Browse files
committed
Add output-env option
1 parent 8e1d546 commit f66192e

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

.github/workflows/ci.yml

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

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ The following inputs can be used as `step.with` keys:
303303
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
304304
| `sep-annotations` | String | Separator to use for annotations output (default `\n`) |
305305
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
306+
| `output-env` | Bool | If `true`, sets each output as an environmental variable (default `true`) |
306307

307308
### outputs
308309

@@ -319,7 +320,7 @@ The following outputs are available:
319320
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
320321
| `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) |
321322

322-
Alternatively, each output is also exported as an environment variable:
323+
Alternatively, each output is also exported as an environment variable when `output-env` is `true`:
323324

324325
* `DOCKER_METADATA_OUTPUT_VERSION`
325326
* `DOCKER_METADATA_OUTPUT_TAGS`

__tests__/context.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('getInputs', () => {
4747
sepTags: '\n',
4848
sepAnnotations: '\n',
4949
tags: [],
50+
outputEnv: true,
5051
} as Inputs
5152
],
5253
[
@@ -70,6 +71,7 @@ describe('getInputs', () => {
7071
sepTags: ',',
7172
sepAnnotations: ',',
7273
tags: [],
74+
outputEnv: true,
7375
} as Inputs
7476
],
7577
[
@@ -89,6 +91,7 @@ describe('getInputs', () => {
8991
sepTags: '\n',
9092
sepAnnotations: '\n',
9193
tags: [],
94+
outputEnv: true,
9295
} as Inputs
9396
],
9497
])(

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ inputs:
3838
bake-target:
3939
description: 'Bake target name (default docker-metadata-action)'
4040
required: false
41+
output-env:
42+
description:
43+
default: 'true'
44+
required: true
4145
github-token:
4246
description: 'GitHub Token as provided by secrets'
4347
default: ${{ github.token }}

src/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Inputs {
2020
sepLabels: string;
2121
sepAnnotations: string;
2222
bakeTarget: string;
23+
outputEnv: boolean;
2324
githubToken: string;
2425
}
2526

@@ -35,6 +36,7 @@ export function getInputs(): Inputs {
3536
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
3637
sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`,
3738
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
39+
outputEnv: (core.getInput('output-env') || 'true') === 'true',
3840
githubToken: core.getInput('github-token')
3941
};
4042
}

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ actionsToolkit.run(
1313
const toolkit = new Toolkit({githubToken: inputs.githubToken});
1414
const context = await getContext(inputs.context, toolkit);
1515
const repo = await toolkit.github.repoData();
16+
const setOutput = inputs.outputEnv ? setOutputAndEnv : core.setOutput;
1617

1718
await core.group(`Context info`, async () => {
1819
core.info(`eventName: ${context.eventName}`);
@@ -105,7 +106,7 @@ actionsToolkit.run(
105106
}
106107
);
107108

108-
function setOutput(name: string, value: string) {
109+
function setOutputAndEnv(name: string, value: string) {
109110
core.setOutput(name, value);
110111
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
111112
}

0 commit comments

Comments
 (0)