Merge 6bbb331ffc
into 88dc235639
This commit is contained in:
commit
b70a5cb9c1
|
@ -71,4 +71,17 @@ describe("actions-rs/toolchain", () => {
|
||||||
|
|
||||||
expect(args.name).toBe("1.39.0");
|
expect(args.name).toBe("1.39.0");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("supports toml override file", function () {
|
||||||
|
const rustToolchainFile = tempWriteSync(`
|
||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
`);
|
||||||
|
|
||||||
|
const args = morph(() => {
|
||||||
|
return getToolchainArgs(rustToolchainFile);
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
expect(args.name).toBe("stable");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -35,7 +35,8 @@
|
||||||
"@actions-rs/core": "^0.1.6",
|
"@actions-rs/core": "^0.1.6",
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"@actions/io": "^1.0.2"
|
"@actions/io": "^1.0.2",
|
||||||
|
"fast-toml": "^0.5.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.15",
|
"@types/jest": "^26.0.15",
|
||||||
|
|
24
src/args.ts
24
src/args.ts
|
@ -1,6 +1,7 @@
|
||||||
import { input } from "@actions-rs/core";
|
import { input } from "@actions-rs/core";
|
||||||
import { debug } from "@actions/core";
|
import { debug } from "@actions/core";
|
||||||
import { existsSync, readFileSync } from "fs";
|
import { existsSync, readFileSync } from "fs";
|
||||||
|
import { parse } from "fast-toml";
|
||||||
|
|
||||||
export interface ToolchainOptions {
|
export interface ToolchainOptions {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -19,20 +20,35 @@ function determineToolchain(overrideFile: string): string {
|
||||||
return toolchainInput;
|
return toolchainInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existsSync(overrideFile)) {
|
const toolchainPath = existsSync(overrideFile)
|
||||||
|
? overrideFile
|
||||||
|
: existsSync(`${overrideFile}.toml`)
|
||||||
|
? `${overrideFile}.toml`
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (!toolchainPath) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"toolchain input was not given and repository does not have a rust-toolchain file"
|
"toolchain input was not given and repository does not have a rust-toolchain file"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rustToolchainFile = readFileSync(overrideFile, {
|
const rustToolchainFile = readFileSync(toolchainPath, {
|
||||||
encoding: "utf-8",
|
encoding: "utf-8",
|
||||||
flag: "r",
|
flag: "r",
|
||||||
}).trim();
|
}).trim();
|
||||||
|
|
||||||
debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
|
const toolchain = rustToolchainFile.includes("[toolchain]")
|
||||||
|
? parse<{ toolchain?: { channel?: string } }>(rustToolchainFile)
|
||||||
|
?.toolchain?.channel
|
||||||
|
: rustToolchainFile;
|
||||||
|
|
||||||
return rustToolchainFile;
|
if (!toolchain) {
|
||||||
|
throw new Error(`channel is not specified in ${toolchainPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(`using toolchain from rust-toolchain file: ${toolchain}`);
|
||||||
|
|
||||||
|
return toolchain;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getToolchainArgs(overrideFile: string): ToolchainOptions {
|
export function getToolchainArgs(overrideFile: string): ToolchainOptions {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue