diff --git a/src/common/github/__tests__/index.ts b/src/common/github/__tests__/index.ts index 843483b5..10e8dd7c 100644 --- a/src/common/github/__tests__/index.ts +++ b/src/common/github/__tests__/index.ts @@ -498,6 +498,40 @@ describe('GitHub utils', () => { expect(env!.RUSTFLAGS).toEqual('-D unused_crate_dependencies') }) + test('runs at root if no outdir is configured', () => { + const project = new TestProject() + new RustTestWorkflow(project.github!) + const snapshot = synthSnapshot(project) + const workflow = YAML.parse(snapshot[workflowPath]) + const noArgsJobs = ['check', 'test'] + + noArgsJobs.forEach((job) => { + const {args} = workflow.jobs[job].steps.at(-1)!.with + expect(args).toBeUndefined() + }) + + const jobsWithArgs = ['clippy', 'format'] + + jobsWithArgs.forEach((job) => { + const {args} = workflow.jobs[job].steps.at(-1)!.with + expect(args).not.toContain(`--manifest-path`) + }) + }) + + test('runs for a nested project if outdir is configured', () => { + const project = new TestProject() + const outdir = 'inner-project' + new RustTestWorkflow(project.github!, {rootdir: outdir}) + const snapshot = synthSnapshot(project) + const workflow = YAML.parse(snapshot[workflowPath]) + const jobs = ['clippy', 'check', 'format', 'test'] + + jobs.forEach((job) => { + const {args} = workflow.jobs[job].steps.at(-1)!.with + expect(args).toContain(`--manifest-path=${outdir}/Cargo.toml`) + }) + }) + describe('addToProject', () => { test('does nothing by default', () => { const project = new TestProjectWithRustTestWorkflow({}) diff --git a/src/common/github/rust-test-workflow.ts b/src/common/github/rust-test-workflow.ts index 3c30125c..dfac4b42 100644 --- a/src/common/github/rust-test-workflow.ts +++ b/src/common/github/rust-test-workflow.ts @@ -27,6 +27,15 @@ export interface RustTestWorkflowOptions extends GithubWorkflowOptions { */ readonly name?: string + /** + * The root directory of the rust project. + * + * This directory is expected to contain the manifest file. + * + * @default "." + */ + readonly rootdir?: string + /** * A list of paths on pushes to which the workflow will run. * @default ['.'] @@ -76,6 +85,8 @@ export class RustTestWorkflow extends GithubWorkflow { const paths = options.triggerOnPaths const branches = options.triggerOnBranches ?? ['main'] + const {rootdir} = options + const manifestPath = rootdir ? `--manifest-path=${rootdir}/Cargo.toml` : undefined this.on({ pullRequest: {paths, types: ['opened', 'synchronize']}, @@ -114,7 +125,11 @@ export class RustTestWorkflow extends GithubWorkflow { { name: `Run ${command}`, uses: 'actions-rs/cargo@v1', - with: {command, args, toolchain}, + with: { + command, + args: [manifestPath, args].filter(Boolean).join(' ') || undefined, + toolchain, + }, env, }, ],