Skip to content

Commit

Permalink
PLA-292 Use cache for rust test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
quesabe committed Jan 26, 2024
1 parent 0b981d6 commit 553e9f1
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"Println",
"projen",
"projenrc",
"rustc",
"rustfmt",
"testid",
"timestamptz",
Expand Down
40 changes: 40 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.

40 changes: 40 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.

23 changes: 21 additions & 2 deletions src/common/github/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,38 @@ describe('GitHub utils', () => {
const {toolchain: toolchainSetup, components} = job.steps[1]!.with!
expect(toolchainSetup).toEqual('nightly')
expect(components).toEqual('rustfmt, clippy')
const toolchainUse = job.steps[2]!.with!.toolchain
const toolchainUse = job.steps[3]!.with!.toolchain
expect(toolchainUse).toEqual('nightly')
})
})

test('Caches cargo home and target folders', () => {
const project = new TestProject()
new RustTestWorkflow(project.github!)
const snapshot = synthSnapshot(project)
const workflow = YAML.parse(snapshot[workflowPath])
const jobs = Object.values<projen.github.workflows.Job>(workflow.jobs)

jobs.forEach((job) => {
const cacheStep = job.steps[2]
expect(cacheStep.uses).toEqual('actions/cache@v3')
const {path, key} = cacheStep.with!
expect(path).toContain('\n~/.cargo')
expect(path).toContain('\ntarget/')
expect(key).toContain('runner.os')
expect(key).toContain('steps.toolchain.outputs.rustc_hash')
expect(key).toContain("hashFiles('**/Cargo.lock')")
})
})

test('adds four checks to the workflow', () => {
const project = new TestProject()
new RustTestWorkflow(project.github!)
const snapshot = synthSnapshot(project)
const workflow = YAML.parse(snapshot[workflowPath])
const jobs = Object.values<projen.github.workflows.Job>(workflow.jobs)
expect(jobs).toHaveLength(4)
const commands = jobs.map((j) => j.steps[2]!.with!.command)
const commands = jobs.map((j) => j.steps[3]!.with!.command)
expect(commands).toContain('clippy')
expect(commands).toContain('check')
expect(commands).toContain('fmt')
Expand Down
20 changes: 20 additions & 0 deletions src/common/github/rust-test-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,29 @@ export class RustTestWorkflow extends GithubWorkflow {
{uses: 'actions/checkout@v3'},
{
name: 'Install latest nightly',
id: 'toolchain',
uses: 'actions-rs/toolchain@v1',
with: {toolchain, components: 'rustfmt, clippy'},
},
{
uses: 'actions/cache@v3',
with: {
path: [
'~/.cargo/bin/',
'~/.cargo/registry/index/',
'~/.cargo/registry/cache/',
'~/.cargo/git/db/',
'target/',
].join('\n'),
key: [
'cargo',
'${{ runner.os }}',
'${{ steps.toolchain.outputs.rustc_hash }}',
"${{ hashFiles('**/Cargo.lock') }}",
command,
].join('-'),
},
},
{
name: `Run ${command}`,
uses: 'actions-rs/cargo@v1',
Expand Down

0 comments on commit 553e9f1

Please sign in to comment.