forked from actions-rs/cargo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update `rs-actions-core` to 5.0.0, run `npm update` * fix: proper support of `toolchain` with `cargo-hack` * chore(ci): test `toolchain` with non-`cargo` tools * chore(ci): do not use rust-cache on CI to test our own caching * chore: add JS tests for `run` * chore: fix `package-lock.json`
- Loading branch information
1 parent
8653300
commit ba11837
Showing
8 changed files
with
187 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Input } from "../src/input"; | ||
import { run } from "../src/run"; | ||
|
||
const SECONDS = 1000; | ||
|
||
describe("run", () => { | ||
it.each([ | ||
{ | ||
name: "rust-tests-working", | ||
input: { | ||
command: "check", | ||
toolchain: "stable", | ||
args: ["--package", "working", "--all-targets", "--all-features"], | ||
}, | ||
}, | ||
{ | ||
name: "rust-tests-not-working-default-features", | ||
input: { | ||
command: "build", | ||
args: ["--package", "not_working"], | ||
}, | ||
}, | ||
{ | ||
name: "rust-tests-not-working-all-features", | ||
input: { | ||
command: "build", | ||
args: ["--package", "not_working", "--all-features"], | ||
}, | ||
shouldThrow: true, | ||
}, | ||
{ | ||
name: "rust-tests-cross", | ||
input: { | ||
command: "build", | ||
toolchain: "stable", | ||
args: ["--target", "aarch64-unknown-linux-gnu"], | ||
workingDirectory: "rust_tests/working", | ||
tool: "cross", | ||
}, | ||
}, | ||
{ | ||
name: "rust-tests-cargo-hack", | ||
input: { | ||
command: "check", | ||
toolchain: "stable", | ||
args: [], | ||
workingDirectory: "rust_tests/working", | ||
tool: "cargo-hack", | ||
}, | ||
}, | ||
{ | ||
name: "rust-clippy-warnings", | ||
input: { | ||
command: "clippy", | ||
args: ["--package", "clippy_warnings"], | ||
}, | ||
}, | ||
{ | ||
name: " rust-fmt-warnings", | ||
input: { | ||
command: "fmt", | ||
args: ["--package", "fmt_warnings", "--check"], | ||
}, | ||
shouldThrow: true, | ||
}, | ||
])( | ||
"$name", | ||
async ({ input, shouldThrow }: { input: Input; shouldThrow?: boolean }) => { | ||
const inputWithoutCache: Input = { | ||
...input, | ||
...(!process.env.CI && { cacheKey: "no-cache" }), | ||
}; | ||
|
||
if (shouldThrow) { | ||
await expect(run(inputWithoutCache)).rejects.toThrow(); | ||
} else { | ||
await expect(run(inputWithoutCache)).resolves.not.toThrow(); | ||
} | ||
}, | ||
240 * SECONDS, | ||
); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import path from "path"; | ||
|
||
import * as exec from "@actions/exec"; | ||
|
||
import * as input from "./input"; | ||
import { | ||
Cargo, | ||
CargoHack, | ||
CargoHackOptions, | ||
Cross, | ||
CrossOptions, | ||
} from "@clechasseur/rs-actions-core"; | ||
|
||
export async function getProgram(actionInput: input.Input) { | ||
switch (actionInput.tool) { | ||
case "cross": { | ||
const options: CrossOptions = { | ||
toolchain: actionInput.toolchain, | ||
primaryKey: actionInput.cacheKey, | ||
}; | ||
return await Cross.getOrInstall(options); | ||
} | ||
case "cargo-hack": { | ||
const options: CargoHackOptions = { | ||
toolchain: actionInput.toolchain, | ||
primaryKey: actionInput.cacheKey, | ||
}; | ||
return await CargoHack.getOrInstall(options); | ||
} | ||
default: | ||
return await Cargo.get(actionInput.toolchain); | ||
} | ||
} | ||
|
||
export async function run(actionInput: input.Input): Promise<void> { | ||
const program = await getProgram(actionInput); | ||
|
||
const args = [actionInput.command, ...actionInput.args]; | ||
|
||
const options: exec.ExecOptions = {}; | ||
if (actionInput.workingDirectory) { | ||
options.cwd = path.join(process.cwd(), actionInput.workingDirectory); | ||
} | ||
|
||
await program.call(args, options); | ||
} |