Update detsys-ts

This commit is contained in:
Luc Perkins
2024-05-23 19:19:07 -03:00
parent c16b76233e
commit dccc3175bf
6 changed files with 89 additions and 134 deletions

View File

@ -1,4 +1,3 @@
import { determineFlakeDirectories } from "./inputs.js";
import { makeNixCommandArgs } from "./nix.js";
import * as actionsCore from "@actions/core";
import * as actionsExec from "@actions/exec";
@ -25,13 +24,7 @@ class UpdateFlakeLockAction extends DetSysAction {
this.flakeInputs = inputs.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
const flakeDirsInput = inputs.getStringOrNull("flake-dirs");
if (flakeDirsInput !== null) {
this.flakeDirs = determineFlakeDirectories(flakeDirsInput);
} else {
this.flakeDirs = null;
}
this.flakeDirs = inputs.getArrayOfStringsOrNull("flake-dirs", "space");
this.validateInputs();
}

View File

@ -1,10 +0,0 @@
// Helper function for nullable input fields into an array of strings
export function determineFlakeDirectories(input: string): string[] {
const sepChar = /\s+/;
const trimmed = input.trim();
if (trimmed === "") {
return [];
} else {
return trimmed.split(sepChar).map((s: string) => s.trim());
}
}

View File

@ -1,4 +1,3 @@
import { determineFlakeDirectories } from "./inputs.js";
import { makeNixCommandArgs } from "./nix.js";
import { expect, test } from "vitest";
@ -73,23 +72,3 @@ test("Nix command arguments", () => {
expect(args).toStrictEqual(expected);
});
});
test("Flake directory parsing", () => {
type TestCase = {
input: string;
outputs: string[];
};
const testCases: TestCase[] = [
{ input: "", outputs: [] },
{ input: "one two three", outputs: ["one", "two", "three"] },
{
input: ` one two three `,
outputs: ["one", "two", "three"],
},
];
testCases.forEach(({ input, outputs }) => {
expect(determineFlakeDirectories(input)).toStrictEqual(outputs);
});
});