I hate the way GitHub Actions process inputs

This commit is contained in:
Kir_Antipov 2021-12-11 15:21:24 +03:00
parent 8c7eeb8fd9
commit af38f88370
3 changed files with 31 additions and 0 deletions

View file

@ -8,66 +8,85 @@ inputs:
modrinth-id: modrinth-id:
description: The ID of the Modrinth project to upload to description: The ID of the Modrinth project to upload to
required: false required: false
default: ${undefined}
modrinth-token: modrinth-token:
description: A valid token for the Modrinth API description: A valid token for the Modrinth API
required: false required: false
default: ${undefined}
curseforge-id: curseforge-id:
description: The ID of the CurseForge project to upload to description: The ID of the CurseForge project to upload to
required: false required: false
default: ${undefined}
curseforge-token: curseforge-token:
description: A valid token for the CurseForge API description: A valid token for the CurseForge API
required: false required: false
default: ${undefined}
github-tag: github-tag:
description: The tag name of the release to upload assets to description: The tag name of the release to upload assets to
required: false required: false
default: ${undefined}
github-token: github-token:
description: A valid token for the GitHub API description: A valid token for the GitHub API
required: false required: false
default: ${undefined}
files: files:
description: A glob of the files to upload description: A glob of the files to upload
required: false required: false
default: ${undefined}
files-primary: files-primary:
description: A glob of the primary files to upload description: A glob of the primary files to upload
required: false required: false
default: ${undefined}
files-secondary: files-secondary:
description: A glob of the secondary files to upload description: A glob of the secondary files to upload
required: false required: false
default: ${undefined}
name: name:
description: The name of the version description: The name of the version
required: false required: false
default: ${undefined}
version: version:
description: The version number description: The version number
required: false required: false
default: ${undefined}
version-type: version-type:
description: The type of the release - alpha, beta, or release description: The type of the release - alpha, beta, or release
required: false required: false
default: ${undefined}
changelog: changelog:
description: The changelog for this version description: The changelog for this version
required: false required: false
default: ${undefined}
changelog-file: changelog-file:
description: A glob of the changelog file description: A glob of the changelog file
required: false required: false
default: ${undefined}
loaders: loaders:
description: A list of supported mod loaders description: A list of supported mod loaders
required: false required: false
default: ${undefined}
game-versions: game-versions:
description: A list of supported Minecraft versions description: A list of supported Minecraft versions
required: false required: false
default: ${undefined}
dependencies: dependencies:
description: A list of dependencies description: A list of dependencies
required: false required: false
default: ${undefined}
version-resolver: version-resolver:
description: Determines the way automatic game-versions resolvement works description: Determines the way automatic game-versions resolvement works
required: false required: false
default: ${undefined}
java: java:
description: A list of supported Java versions description: A list of supported Java versions
required: false required: false
default: ${undefined}
runs: runs:
using: node12 using: node12
main: dist/index.js main: dist/index.js

View file

@ -3,6 +3,8 @@ import process from "process";
// eslint-disable-next-line @typescript-eslint/no-empty-interface // eslint-disable-next-line @typescript-eslint/no-empty-interface
interface InputObject extends Record<string, string | InputObject> { } interface InputObject extends Record<string, string | InputObject> { }
const undefinedValue = "${undefined}";
export function getInputAsObject(): Record<string, InputObject> { export function getInputAsObject(): Record<string, InputObject> {
const inputs = Object.entries(process.env).filter(([key, _]) => key.startsWith("INPUT_")); const inputs = Object.entries(process.env).filter(([key, _]) => key.startsWith("INPUT_"));
const input = {}; const input = {};
@ -14,6 +16,10 @@ export function getInputAsObject(): Record<string, InputObject> {
} }
function init(root: InputObject, path: string[], value: string): void { 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))), ""); const name = path.reduce((a, b, i) => a + (i === 0 ? b : (b.substring(0, 1).toUpperCase() + b.substring(1))), "");
root[name] = value; root[name] = value;
if (path.length === 1) { if (path.length === 1) {

View file

@ -8,6 +8,7 @@ describe("getInputAsObject", () => {
"object": { foo: "bar" }, "object": { foo: "bar" },
"number": 1, "number": 1,
"array": ["foo", "bar"], "array": ["foo", "bar"],
"undefined": "${undefined}",
"files-primary": "primaryPath", "files-primary": "primaryPath",
"files-secondary": "secondaryPath", "files-secondary": "secondaryPath",
@ -64,4 +65,9 @@ describe("getInputAsObject", () => {
expect(input).toHaveProperty("this.is.a.very.long.name", "foo"); expect(input).toHaveProperty("this.is.a.very.long.name", "foo");
expect(input).toHaveProperty("thisIsAVeryLongName", "foo"); expect(input).toHaveProperty("thisIsAVeryLongName", "foo");
}); });
test("special case for GitHub Actions: ${undefined} transforms into undefined", () => {
const input = getInputAsObject();
expect(input.undefined).toBeUndefined();
});
}); });