mirror of
https://github.com/docker/metadata-action.git
synced 2026-01-15 00:43:08 +08:00
Add output-env option
Signed-off-by: Curtis Vogt <curtis.vogt@gmail.com>
This commit is contained in:
parent
8e1d5461f0
commit
a28e9ede38
25
.github/workflows/ci.yml
vendored
25
.github/workflows/ci.yml
vendored
@ -472,6 +472,31 @@ jobs:
|
|||||||
DOCKER_METADATA_OUTPUT_ANNOTATIONS
|
DOCKER_METADATA_OUTPUT_ANNOTATIONS
|
||||||
DOCKER_METADATA_OUTPUT_JSON
|
DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
|
||||||
|
no-output-env:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.DOCKER_IMAGE }}
|
||||||
|
ghcr.io/name/app
|
||||||
|
labels: |
|
||||||
|
maintainer=CrazyMax
|
||||||
|
annotations: |
|
||||||
|
maintainer=Foo
|
||||||
|
output-env: false
|
||||||
|
-
|
||||||
|
name: No output environment variables set
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
[[ "$(printenv | grep "^DOCKER_METADATA_OUTPUT_" | wc -l)" -eq 0 ]] || exit 1
|
||||||
|
|
||||||
bake-annotations:
|
bake-annotations:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@ -303,6 +303,7 @@ The following inputs can be used as `step.with` keys:
|
|||||||
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
||||||
| `sep-annotations` | String | Separator to use for annotations output (default `\n`) |
|
| `sep-annotations` | String | Separator to use for annotations output (default `\n`) |
|
||||||
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
|
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
|
||||||
|
| `output-env` | Bool | If `true`, sets each output as an environmental variable (default `true`) |
|
||||||
|
|
||||||
### outputs
|
### outputs
|
||||||
|
|
||||||
@ -319,7 +320,7 @@ The following outputs are available:
|
|||||||
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
|
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
|
||||||
| `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) |
|
| `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) |
|
||||||
|
|
||||||
Alternatively, each output is also exported as an environment variable:
|
Alternatively, each output is also exported as an environment variable when `output-env` is `true`:
|
||||||
|
|
||||||
* `DOCKER_METADATA_OUTPUT_VERSION`
|
* `DOCKER_METADATA_OUTPUT_VERSION`
|
||||||
* `DOCKER_METADATA_OUTPUT_TAGS`
|
* `DOCKER_METADATA_OUTPUT_TAGS`
|
||||||
|
|||||||
@ -47,6 +47,7 @@ describe('getInputs', () => {
|
|||||||
sepTags: '\n',
|
sepTags: '\n',
|
||||||
sepAnnotations: '\n',
|
sepAnnotations: '\n',
|
||||||
tags: [],
|
tags: [],
|
||||||
|
outputEnv: true,
|
||||||
} as Inputs
|
} as Inputs
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -70,6 +71,7 @@ describe('getInputs', () => {
|
|||||||
sepTags: ',',
|
sepTags: ',',
|
||||||
sepAnnotations: ',',
|
sepAnnotations: ',',
|
||||||
tags: [],
|
tags: [],
|
||||||
|
outputEnv: true,
|
||||||
} as Inputs
|
} as Inputs
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -89,6 +91,7 @@ describe('getInputs', () => {
|
|||||||
sepTags: '\n',
|
sepTags: '\n',
|
||||||
sepAnnotations: '\n',
|
sepAnnotations: '\n',
|
||||||
tags: [],
|
tags: [],
|
||||||
|
outputEnv: true,
|
||||||
} as Inputs
|
} as Inputs
|
||||||
],
|
],
|
||||||
])(
|
])(
|
||||||
|
|||||||
@ -38,6 +38,10 @@ inputs:
|
|||||||
bake-target:
|
bake-target:
|
||||||
description: 'Bake target name (default docker-metadata-action)'
|
description: 'Bake target name (default docker-metadata-action)'
|
||||||
required: false
|
required: false
|
||||||
|
output-env:
|
||||||
|
description:
|
||||||
|
default: 'true'
|
||||||
|
required: true
|
||||||
github-token:
|
github-token:
|
||||||
description: 'GitHub Token as provided by secrets'
|
description: 'GitHub Token as provided by secrets'
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ export interface Inputs {
|
|||||||
sepLabels: string;
|
sepLabels: string;
|
||||||
sepAnnotations: string;
|
sepAnnotations: string;
|
||||||
bakeTarget: string;
|
bakeTarget: string;
|
||||||
|
outputEnv: boolean;
|
||||||
githubToken: string;
|
githubToken: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ export function getInputs(): Inputs {
|
|||||||
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
||||||
sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`,
|
sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`,
|
||||||
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
||||||
|
outputEnv: (core.getInput('output-env') || 'true') === 'true',
|
||||||
githubToken: core.getInput('github-token')
|
githubToken: core.getInput('github-token')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ actionsToolkit.run(
|
|||||||
const toolkit = new Toolkit({githubToken: inputs.githubToken});
|
const toolkit = new Toolkit({githubToken: inputs.githubToken});
|
||||||
const context = await getContext(inputs.context, toolkit);
|
const context = await getContext(inputs.context, toolkit);
|
||||||
const repo = await toolkit.github.repoData();
|
const repo = await toolkit.github.repoData();
|
||||||
|
const setOutput = inputs.outputEnv ? setOutputAndEnv : core.setOutput;
|
||||||
|
|
||||||
await core.group(`Context info`, async () => {
|
await core.group(`Context info`, async () => {
|
||||||
core.info(`eventName: ${context.eventName}`);
|
core.info(`eventName: ${context.eventName}`);
|
||||||
@ -105,7 +106,7 @@ actionsToolkit.run(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
function setOutput(name: string, value: string) {
|
function setOutputAndEnv(name: string, value: string) {
|
||||||
core.setOutput(name, value);
|
core.setOutput(name, value);
|
||||||
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
|
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user