From af38f88370c2a7936cd3476fb4db39286317802c Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sat, 11 Dec 2021 15:21:24 +0300 Subject: [PATCH] I hate the way GitHub Actions process inputs --- action.yml | 19 +++++++++++++++++++ src/utils/input-utils.ts | 6 ++++++ test/input-utils.test.ts | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/action.yml b/action.yml index da9f689..df33086 100644 --- a/action.yml +++ b/action.yml @@ -8,66 +8,85 @@ inputs: modrinth-id: description: The ID of the Modrinth project to upload to required: false + default: ${undefined} modrinth-token: description: A valid token for the Modrinth API required: false + default: ${undefined} curseforge-id: description: The ID of the CurseForge project to upload to required: false + default: ${undefined} curseforge-token: description: A valid token for the CurseForge API required: false + default: ${undefined} github-tag: description: The tag name of the release to upload assets to required: false + default: ${undefined} github-token: description: A valid token for the GitHub API required: false + default: ${undefined} files: description: A glob of the files to upload required: false + default: ${undefined} files-primary: description: A glob of the primary files to upload required: false + default: ${undefined} files-secondary: description: A glob of the secondary files to upload required: false + default: ${undefined} name: description: The name of the version required: false + default: ${undefined} version: description: The version number required: false + default: ${undefined} version-type: description: The type of the release - alpha, beta, or release required: false + default: ${undefined} changelog: description: The changelog for this version required: false + default: ${undefined} changelog-file: description: A glob of the changelog file required: false + default: ${undefined} loaders: description: A list of supported mod loaders required: false + default: ${undefined} game-versions: description: A list of supported Minecraft versions required: false + default: ${undefined} dependencies: description: A list of dependencies required: false + default: ${undefined} version-resolver: description: Determines the way automatic game-versions resolvement works required: false + default: ${undefined} java: description: A list of supported Java versions required: false + default: ${undefined} runs: using: node12 main: dist/index.js \ No newline at end of file diff --git a/src/utils/input-utils.ts b/src/utils/input-utils.ts index f3df1ae..2494942 100644 --- a/src/utils/input-utils.ts +++ b/src/utils/input-utils.ts @@ -3,6 +3,8 @@ import process from "process"; // eslint-disable-next-line @typescript-eslint/no-empty-interface interface InputObject extends Record { } +const undefinedValue = "${undefined}"; + export function getInputAsObject(): Record { const inputs = Object.entries(process.env).filter(([key, _]) => key.startsWith("INPUT_")); const input = {}; @@ -14,6 +16,10 @@ export function getInputAsObject(): Record { } function init(root: InputObject, path: string[], value: string): void { + if (value === undefinedValue) { + return; + } + const name = path.reduce((a, b, i) => a + (i === 0 ? b : (b.substring(0, 1).toUpperCase() + b.substring(1))), ""); root[name] = value; if (path.length === 1) { diff --git a/test/input-utils.test.ts b/test/input-utils.test.ts index d469b40..e766968 100644 --- a/test/input-utils.test.ts +++ b/test/input-utils.test.ts @@ -8,6 +8,7 @@ describe("getInputAsObject", () => { "object": { foo: "bar" }, "number": 1, "array": ["foo", "bar"], + "undefined": "${undefined}", "files-primary": "primaryPath", "files-secondary": "secondaryPath", @@ -64,4 +65,9 @@ describe("getInputAsObject", () => { expect(input).toHaveProperty("this.is.a.very.long.name", "foo"); expect(input).toHaveProperty("thisIsAVeryLongName", "foo"); }); + + test("special case for GitHub Actions: ${undefined} transforms into undefined", () => { + const input = getInputAsObject(); + expect(input.undefined).toBeUndefined(); + }); });