Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a denial check for unused deps in rust test workflow #520

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cdk/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/common/github/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/common/github/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ describe('GitHub utils', () => {
expect(commands).toContain('test')
})

test.only('enables additional lints in cargo check', () => {
const project = new TestProject()
new RustTestWorkflow(project.github!)
const snapshot = synthSnapshot(project)
const workflow = YAML.parse(snapshot[workflowPath])
const {name, env} = workflow.jobs.check.steps.at(-1)!
expect(name).toEqual('Run check')
expect(env!.RUSTFLAGS).toEqual('-D unused_crate_dependencies')
})

describe('addToProject', () => {
test('does nothing by default', () => {
const project = new TestProjectWithRustTestWorkflow({})
Expand Down
10 changes: 8 additions & 2 deletions src/common/github/rust-test-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ interface CargoActionParams {
* Arguments for the cargo command
*/
args?: string

/**
* Environment variables for the cargo command
*/
env?: Record<string, string>
}

/**
Expand All @@ -77,7 +82,7 @@ export class RustTestWorkflow extends GithubWorkflow {
push: {paths, branches},
})

const cargoJob = ({command, args, toolchain = 'nightly'}: CargoActionParams): Job =>
const cargoJob = ({command, args, env, toolchain = 'nightly'}: CargoActionParams): Job =>
job(
[
{uses: 'actions/checkout@v3'},
Expand All @@ -90,14 +95,15 @@ export class RustTestWorkflow extends GithubWorkflow {
name: `Run ${command}`,
uses: 'actions-rs/cargo@v1',
with: {command, args, toolchain},
env,
},
],
options.runsOn,
)

this.addJobs({
clippy: cargoJob({command: 'clippy', args: '--all-targets --all-features -- -D warnings'}),
check: cargoJob({command: 'check'}),
check: cargoJob({command: 'check', env: {RUSTFLAGS: '-D unused_crate_dependencies'}}),
format: cargoJob({command: 'fmt', args: '--check'}),
test: cargoJob({command: 'test'}),
})
Expand Down
Loading