diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2a8c963..977329b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -472,6 +472,31 @@ jobs: DOCKER_METADATA_OUTPUT_ANNOTATIONS 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: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 379bfa67..a20c492b 100644 --- a/README.md +++ b/README.md @@ -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-annotations` | String | Separator to use for annotations output (default `\n`) | | `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 @@ -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-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_TAGS` diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 6bd141ba..28698ef3 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -47,6 +47,7 @@ describe('getInputs', () => { sepTags: '\n', sepAnnotations: '\n', tags: [], + outputEnv: true, } as Inputs ], [ @@ -70,6 +71,7 @@ describe('getInputs', () => { sepTags: ',', sepAnnotations: ',', tags: [], + outputEnv: true, } as Inputs ], [ @@ -89,6 +91,7 @@ describe('getInputs', () => { sepTags: '\n', sepAnnotations: '\n', tags: [], + outputEnv: true, } as Inputs ], ])( diff --git a/action.yml b/action.yml index 35472d9d..dc772c10 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: bake-target: description: 'Bake target name (default docker-metadata-action)' required: false + output-env: + description: + default: 'true' + required: true github-token: description: 'GitHub Token as provided by secrets' default: ${{ github.token }} diff --git a/src/context.ts b/src/context.ts index 7d69c531..4436c856 100644 --- a/src/context.ts +++ b/src/context.ts @@ -20,6 +20,7 @@ export interface Inputs { sepLabels: string; sepAnnotations: string; bakeTarget: string; + outputEnv: boolean; githubToken: string; } @@ -35,6 +36,7 @@ export function getInputs(): Inputs { sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`, sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`, bakeTarget: core.getInput('bake-target') || `docker-metadata-action`, + outputEnv: (core.getInput('output-env') || 'true') === 'true', githubToken: core.getInput('github-token') }; } diff --git a/src/main.ts b/src/main.ts index 9d341a27..4278e981 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,6 +13,7 @@ actionsToolkit.run( const toolkit = new Toolkit({githubToken: inputs.githubToken}); const context = await getContext(inputs.context, toolkit); const repo = await toolkit.github.repoData(); + const setOutput = inputs.outputEnv ? setOutputAndEnv : core.setOutput; await core.group(`Context info`, async () => { 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.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value); }