Skip to content

Commit

Permalink
Add versions properties to cache (#280)
Browse files Browse the repository at this point in the history
* Add versions properties to cache

* lint fix

npm run format change

* [FIX] unit test

* docs: fix typo in the Readme.md

* docs: update link to the toolkit/cache package

---------

Co-authored-by: Ivan Zosimov <ivan.zosimov@Ivans-MacBook-Pro.local>
  • Loading branch information
Endi327 and Ivan Zosimov committed Jul 21, 2023
1 parent 4fb3975 commit cd89f46
Show file tree
Hide file tree
Showing 5 changed files with 5,198 additions and 5,176 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -113,8 +113,8 @@ Currently, the following distributions are supported:
**NOTE:** For Azul Zulu OpenJDK architectures x64 and arm64 are mapped to x86 / arm with proper hw_bitness.

### Caching packages dependencies
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`
The action has a built-in functionality for caching and restoring dependencies. It uses [toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/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`, `gradle/*.versions.toml`, and `**/versions.properties`
- maven: `**/pom.xml`
- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.scala`, `**/project/**.sbt`

Expand Down
21 changes: 20 additions & 1 deletion __tests__/cache.test.ts
Expand Up @@ -102,7 +102,7 @@ describe('dependency cache', () => {
await expect(restore('gradle')).rejects.toThrow(
`No file in ${projectRoot(
workspace
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml], make sure you have checked out the target repository`
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml,**/versions.properties], make sure you have checked out the target repository`
);
});
it('downloads cache based on build.gradle', async () => {
Expand Down Expand Up @@ -179,6 +179,14 @@ describe('dependency cache', () => {
expect(firstCall).not.toBe(thirdCall);
});
});
it('downloads cache based on versions.properties', async () => {
createFile(join(workspace, 'versions.properties'));

await restore('gradle');
expect(spyCacheRestore).toHaveBeenCalled();
expect(spyWarning).not.toHaveBeenCalled();
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found');
});
});
describe('save', () => {
let spyCacheSave: jest.SpyInstance<
Expand Down Expand Up @@ -333,6 +341,17 @@ describe('dependency cache', () => {
expect.stringMatching(/^Cache saved with the key:.*/)
);
});
it('uploads cache based on versions.properties', async () => {
createFile(join(workspace, 'versions.properties'));
createStateForSuccessfulRestore();

await save('gradle');
expect(spyCacheSave).toHaveBeenCalled();
expect(spyWarning).not.toHaveBeenCalled();
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
);
});
});
});
});
Expand Down

1 comment on commit cd89f46

@a2425rdl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export class SemeruDistribution extends JavaBase {

Please sign in to comment.