Add support for reading toml files

This commit is contained in:
Justin Bennett 2022-01-08 00:08:21 -05:00
parent 5613870e6d
commit cebe54f42a
4 changed files with 10181 additions and 19 deletions

10170
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,8 @@
"@actions-rs/core": "^0.1.6",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2"
"@actions/io": "^1.0.2",
"fast-toml": "^0.5.4"
},
"devDependencies": {
"@types/jest": "^26.0.15",

View File

@ -1,6 +1,7 @@
import { input } from "@actions-rs/core";
import { debug } from "@actions/core";
import { existsSync, readFileSync } from "fs";
import { parse } from "fast-toml";
export interface ToolchainOptions {
name: string;
@ -36,6 +37,15 @@ function determineToolchain(overrideFile: string): string {
flag: "r",
}).trim();
const toolchain = rustToolchainFile.includes("[toolchain]")
? parse<{ toolchain?: { channel?: string } }>(rustToolchainFile)
?.toolchain?.channel
: rustToolchainFile;
if (!toolchain) {
throw new Error(`channel is not specified in ${toolchainPath}`);
}
debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
return rustToolchainFile;

9
types/fast-toml/index.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
declare module "fast-toml" {
export function parse<R extends Record<string, unknown>>(input: string): R;
export function parseFile<R extends Record<string, unknown>>(
file: string
): Promise<R>;
export function parseFileSync<R extends Record<string, unknown>>(
file: string
): R;
}