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

fix sbt/scala cache key #478

Merged
merged 1 commit into from
Apr 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Currently, the following distributions are supported:
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle, maven and sbt. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files:
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/Versions.kt`, `buildSrc/**/Dependencies.kt`, and `gradle/*.versions.toml`
- maven: `**/pom.xml`
- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.{scala,sbt}`
- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.scala`, `**/project/**.sbt`

The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs).

Expand Down
24 changes: 23 additions & 1 deletion __tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('dependency cache', () => {
await expect(restore('sbt')).rejects.toThrow(
`No file in ${projectRoot(
workspace
)} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository`
)} matched to [**/*.sbt,**/project/build.properties,**/project/**.scala,**/project/**.sbt], make sure you have checked out the target repository`
);
});
it('downloads cache', async () => {
Expand All @@ -156,6 +156,28 @@ describe('dependency cache', () => {
expect(spyWarning).not.toHaveBeenCalled();
expect(spyInfo).toHaveBeenCalledWith('sbt cache is not found');
});
it('detects scala and sbt changes under **/project/ folder', async () => {
createFile(join(workspace, 'build.sbt'));
createDirectory(join(workspace, 'project'));
createFile(join(workspace, 'project/DependenciesV1.scala'));

await restore('sbt');
const firstCall = spySaveState.mock.calls.toString();

spySaveState.mockClear();
await restore('sbt');
const secondCall = spySaveState.mock.calls.toString();

// Make sure multiple restores produce the same cache
expect(firstCall).toBe(secondCall);

spySaveState.mockClear();
createFile(join(workspace, 'project/DependenciesV2.scala'));
await restore('sbt');
const thirdCall = spySaveState.mock.calls.toString();

expect(firstCall).not.toBe(thirdCall);
});
});
});
describe('save', () => {
Expand Down
3 changes: 2 additions & 1 deletion dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68416,7 +68416,8 @@ const supportedPackageManager = [
pattern: [
'**/*.sbt',
'**/project/build.properties',
'**/project/**.{scala,sbt}'
'**/project/**.scala',
'**/project/**.sbt'
]
}
];
Expand Down
3 changes: 2 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103621,7 +103621,8 @@ const supportedPackageManager = [
pattern: [
'**/*.sbt',
'**/project/build.properties',
'**/project/**.{scala,sbt}'
'**/project/**.scala',
'**/project/**.sbt'
]
}
];
Expand Down
3 changes: 2 additions & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const supportedPackageManager: PackageManager[] = [
pattern: [
'**/*.sbt',
'**/project/build.properties',
'**/project/**.{scala,sbt}'
'**/project/**.scala',
'**/project/**.sbt'
]
}
];
Expand Down