From a550435c60e0060ad8c1f043e7e754e20e0b9971 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:26:59 +0100 Subject: [PATCH] use Util.parseBool to parse env Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- README.md | 2 +- src/main.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 52bd57a..0f940a3 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/ | `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event | | `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. | | `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) | -| `DOCKER_METADATA_SET_OUTPUT_ENV` | Bool | If `true`, sets each output as an environmental variable (default `true`) | +| `DOCKER_METADATA_SET_OUTPUT_ENV` | Bool | If `true`, sets each output as an environment variable (default `true`) | ## `context` input diff --git a/src/main.ts b/src/main.ts index 7fda700..568e95c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import * as fs from 'fs'; import * as core from '@actions/core'; import * as actionsToolkit from '@docker/actions-toolkit'; import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; +import {Util} from '@docker/actions-toolkit/lib/util'; import {getContext, getInputs, Inputs} from './context'; import {Meta, Version} from './meta'; @@ -13,8 +14,7 @@ actionsToolkit.run( const toolkit = new Toolkit({githubToken: inputs.githubToken}); const context = await getContext(inputs.context, toolkit); const repo = await toolkit.github.repoData(); - const outputEnv = (process.env.DOCKER_METADATA_SET_OUTPUT_ENV || 'true') === 'true'; - const setOutput = outputEnv ? setOutputAndEnv : core.setOutput; + const setOutput = outputEnvEnabled() ? setOutputAndEnv : core.setOutput; await core.group(`Context info`, async () => { core.info(`eventName: ${context.eventName}`); @@ -111,3 +111,10 @@ function setOutputAndEnv(name: string, value: string) { core.setOutput(name, value); core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value); } + +function outputEnvEnabled(): boolean { + if (process.env.DOCKER_METADATA_SET_OUTPUT_ENV) { + return Util.parseBool(process.env.DOCKER_METADATA_SET_OUTPUT_ENV); + } + return true; +}