mirror of
https://github.com/actions/setup-java.git
synced 2026-11-29 07:43:06 +00:00
Compare commits
3 Commits
513edc4f87
...
v5.6.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03ad4de099 | ||
|
|
d229d2e858 | ||
|
|
bbf0f69670 |
9
.github/workflows/e2e-versions.yml
vendored
9
.github/workflows/e2e-versions.yml
vendored
@@ -55,6 +55,15 @@ jobs:
|
||||
- distribution: microsoft
|
||||
os: macos-latest
|
||||
version: 25
|
||||
- distribution: kona
|
||||
os: windows-latest
|
||||
version: 25
|
||||
- distribution: kona
|
||||
os: ubuntu-latest
|
||||
version: 25
|
||||
- distribution: kona
|
||||
os: macos-latest
|
||||
version: 25
|
||||
- distribution: oracle
|
||||
os: macos-15-intel
|
||||
version: 17
|
||||
|
||||
@@ -149,7 +149,7 @@ The workflow output `cache-primary-key` exposes the primary cache key computed b
|
||||
|
||||
The cache input is optional, and caching is turned off by default.
|
||||
|
||||
**Maven Wrapper:** when `cache: 'maven'` is enabled, the action also caches and restores the Maven Wrapper distribution downloaded to `~/.m2/wrapper/dists` (in addition to the local repository), so wrapper-based (`./mvnw`) builds don't re-download the wrapper on every run. This is keyed on `**/.mvn/wrapper/maven-wrapper.properties` as shown above.
|
||||
**Maven Wrapper:** when `cache: 'maven'` is enabled, the action also caches and restores the Maven Wrapper distribution downloaded to `~/.m2/wrapper/dists` (in addition to the local repository), so wrapper-based (`./mvnw`) builds don't re-download the Maven distribution. The wrapper distribution is stored in a **separate** cache entry keyed only on `**/.mvn/wrapper/maven-wrapper.properties`, so it stays cached across the frequent `pom.xml` changes that rotate the main dependency cache key.
|
||||
|
||||
#### Caching gradle dependencies
|
||||
```yaml
|
||||
@@ -167,6 +167,8 @@ steps:
|
||||
```
|
||||
Using the `cache: gradle` provides a simple and effective way to cache Gradle dependencies with minimal configuration.
|
||||
|
||||
**Gradle Wrapper:** when `cache: 'gradle'` is enabled, the action also caches and restores the Gradle Wrapper distribution downloaded to `~/.gradle/wrapper` (in addition to the Gradle caches), so wrapper-based (`./gradlew`) builds don't re-download the Gradle distribution. The wrapper distribution is stored in a **separate** cache entry keyed only on `**/gradle-wrapper.properties`, so it stays cached across the frequent `*.gradle*` changes that rotate the main dependency cache key.
|
||||
|
||||
For projects that require more advanced `Gradle` caching features, such as caching build outputs, support for Gradle configuration cache, encrypted cache storage, fine-grained cache control (including options to enable or disable the cache, set it to read-only or write-only, perform automated cleanup, and define custom cache rules), or optimized performance for complex CI workflows, consider using [`gradle/actions/setup-gradle`](https://github.com/gradle/actions/tree/main/setup-gradle).
|
||||
|
||||
For setup details and a comprehensive overview of all available features, visit the [setup-gradle documentation](https://github.com/gradle/actions/blob/main/docs/setup-gradle.md).
|
||||
|
||||
@@ -113,10 +113,7 @@ describe('dependency cache', () => {
|
||||
|
||||
await restore('maven', '');
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[
|
||||
join(os.homedir(), '.m2', 'repository'),
|
||||
join(os.homedir(), '.m2', 'wrapper', 'dists')
|
||||
],
|
||||
[join(os.homedir(), '.m2', 'repository')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
||||
@@ -143,10 +140,7 @@ describe('dependency cache', () => {
|
||||
|
||||
await restore('maven', '');
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[
|
||||
join(os.homedir(), '.m2', 'repository'),
|
||||
join(os.homedir(), '.m2', 'wrapper', 'dists')
|
||||
],
|
||||
[join(os.homedir(), '.m2', 'repository')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
||||
@@ -161,10 +155,7 @@ describe('dependency cache', () => {
|
||||
|
||||
await restore('maven', '');
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[
|
||||
join(os.homedir(), '.m2', 'repository'),
|
||||
join(os.homedir(), '.m2', 'wrapper', 'dists')
|
||||
],
|
||||
[join(os.homedir(), '.m2', 'repository')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
||||
@@ -173,6 +164,39 @@ describe('dependency cache', () => {
|
||||
expect(spyWarning).not.toHaveBeenCalled();
|
||||
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');
|
||||
});
|
||||
it('restores the maven wrapper distribution cache independently of the main cache', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
createDirectory(join(workspace, '.mvn'));
|
||||
createDirectory(join(workspace, '.mvn', 'wrapper'));
|
||||
createFile(
|
||||
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
|
||||
);
|
||||
|
||||
await restore('maven', '');
|
||||
// Main cache no longer includes the wrapper distribution.
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'repository')],
|
||||
expect.any(String)
|
||||
);
|
||||
// Wrapper distribution is restored on its own, keyed only on the
|
||||
// maven-wrapper.properties hash.
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
||||
'**/.mvn/wrapper/maven-wrapper.properties'
|
||||
);
|
||||
});
|
||||
it('skips the maven wrapper cache when no maven-wrapper.properties exists', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
|
||||
await restore('maven', '');
|
||||
expect(spyCacheRestore).not.toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('for gradle', () => {
|
||||
it('throws error if no build.gradle found', async () => {
|
||||
@@ -228,6 +252,30 @@ describe('dependency cache', () => {
|
||||
expect(spyWarning).not.toHaveBeenCalled();
|
||||
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found');
|
||||
});
|
||||
it('restores the gradle wrapper distribution cache independently of the main cache', async () => {
|
||||
createFile(join(workspace, 'build.gradle'));
|
||||
createDirectory(join(workspace, 'gradle'));
|
||||
createDirectory(join(workspace, 'gradle', 'wrapper'));
|
||||
createFile(
|
||||
join(workspace, 'gradle', 'wrapper', 'gradle-wrapper.properties')
|
||||
);
|
||||
|
||||
await restore('gradle', '');
|
||||
// Main cache no longer includes the wrapper distribution.
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.gradle', 'caches')],
|
||||
expect.any(String)
|
||||
);
|
||||
// Wrapper distribution is restored on its own, keyed only on the
|
||||
// gradle-wrapper.properties hash.
|
||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.gradle', 'wrapper')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
||||
'**/gradle-wrapper.properties'
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('for sbt', () => {
|
||||
it('throws error if no build.sbt found', async () => {
|
||||
@@ -399,6 +447,40 @@ describe('dependency cache', () => {
|
||||
expect.stringMatching(/^Cache saved with the key:.*/)
|
||||
);
|
||||
});
|
||||
it('saves the maven wrapper distribution cache under its own key', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
createStateForWrapperRestore('maven-wrapper', false);
|
||||
|
||||
await save('maven');
|
||||
expect(spyCacheSave).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
'setup-java-maven-wrapper-primary-key'
|
||||
);
|
||||
});
|
||||
it('does not save the maven wrapper cache on an exact wrapper hit', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
createStateForWrapperRestore('maven-wrapper', true);
|
||||
|
||||
await save('maven');
|
||||
expect(spyCacheSave).not.toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
it('does not fail the post step when the wrapper distribution path is missing', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
createStateForWrapperRestore('maven-wrapper', false);
|
||||
spyCacheSave.mockImplementation((paths: string[], key: string) => {
|
||||
if (paths.includes(join(os.homedir(), '.m2', 'wrapper', 'dists'))) {
|
||||
return Promise.reject(
|
||||
new cache.ValidationError('Path Validation Error')
|
||||
);
|
||||
}
|
||||
return Promise.resolve(0);
|
||||
});
|
||||
|
||||
await expect(save('maven')).resolves.not.toThrow();
|
||||
});
|
||||
});
|
||||
describe('for gradle', () => {
|
||||
it('uploads cache even if no build.gradle found', async () => {
|
||||
@@ -451,6 +533,26 @@ describe('dependency cache', () => {
|
||||
expect.stringMatching(/^Cache saved with the key:.*/)
|
||||
);
|
||||
});
|
||||
it('saves the gradle wrapper distribution cache under its own key', async () => {
|
||||
createFile(join(workspace, 'build.gradle'));
|
||||
createStateForWrapperRestore('gradle-wrapper', false);
|
||||
|
||||
await save('gradle');
|
||||
expect(spyCacheSave).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.gradle', 'wrapper')],
|
||||
'setup-java-gradle-wrapper-primary-key'
|
||||
);
|
||||
});
|
||||
it('does not save the gradle wrapper cache on an exact wrapper hit', async () => {
|
||||
createFile(join(workspace, 'build.gradle'));
|
||||
createStateForWrapperRestore('gradle-wrapper', true);
|
||||
|
||||
await save('gradle');
|
||||
expect(spyCacheSave).not.toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.gradle', 'wrapper')],
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('for sbt', () => {
|
||||
it('uploads cache even if no build.sbt found', async () => {
|
||||
@@ -528,6 +630,29 @@ function createStateForSuccessfulRestore() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create states to emulate a restore process where an additional (wrapper)
|
||||
* cache was restored. When `hit` is true the matched key equals the primary
|
||||
* key, emulating an exact wrapper cache hit.
|
||||
*/
|
||||
function createStateForWrapperRestore(wrapperName: string, hit: boolean) {
|
||||
const primaryKey = `setup-java-${wrapperName}-primary-key`;
|
||||
jest.spyOn(core, 'getState').mockImplementation(name => {
|
||||
switch (name) {
|
||||
case 'cache-primary-key':
|
||||
return 'setup-java-cache-primary-key';
|
||||
case 'cache-matched-key':
|
||||
return 'setup-java-cache-matched-key';
|
||||
case `cache-primary-key-${wrapperName}`:
|
||||
return primaryKey;
|
||||
case `cache-matched-key-${wrapperName}`:
|
||||
return hit ? primaryKey : '';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createFile(path: string) {
|
||||
core.info(`created a file at ${path}`);
|
||||
fs.writeFileSync(path, '');
|
||||
|
||||
@@ -158,5 +158,45 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"25": [
|
||||
{
|
||||
"version": "25.0.3",
|
||||
"jdkVersion": "25.0.3",
|
||||
"latest": true,
|
||||
"baseUrl": "https://github.com/Tencent/TencentKona-25/releases/download/TencentKona-25.0.3/",
|
||||
"files": [
|
||||
{
|
||||
"os": "linux",
|
||||
"arch": "aarch64",
|
||||
"filename": "TencentKona-25.0.3.b1-jdk_linux-aarch64.tar.gz",
|
||||
"checksum": "2fb77e3ba9c00045ca497ea22210f18dae4bf7df4c87029f5abadd42a5daf8c7"
|
||||
},
|
||||
{
|
||||
"os": "linux",
|
||||
"arch": "x86_64",
|
||||
"filename": "TencentKona-25.0.3.b1-jdk_linux-x86_64.tar.gz",
|
||||
"checksum": "47445e6fad020e834055a705bb48fa3cd0727a2c57ad6f1c5206a45f4efb2d67"
|
||||
},
|
||||
{
|
||||
"os": "macos",
|
||||
"arch": "aarch64",
|
||||
"filename": "TencentKona-25.0.3.b1_jdk_macosx-aarch64_notarized.tar.gz",
|
||||
"checksum": "e29405eff95da412ed7ecc890e6ef5ebbfcd9ab334005b3d32d1700bbe4204d2"
|
||||
},
|
||||
{
|
||||
"os": "macos",
|
||||
"arch": "x86_64",
|
||||
"filename": "TencentKona-25.0.3.b1_jdk_macosx-x86_64_notarized.tar.gz",
|
||||
"checksum": "d512db5c079db16bd3a9c86d9cb979808994e90e4de29e17d27e5219fe488659"
|
||||
},
|
||||
{
|
||||
"os": "windows",
|
||||
"arch": "x86_64",
|
||||
"filename": "TencentKona-25.0.3.b1_jdk_windows-x86_64_signed.zip",
|
||||
"checksum": "865bce92ccbbca75115076e618a98baa1d0f30fcccdce954c0a22bee33d6ae83"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ describe('Check getAvailableReleases', () => {
|
||||
['11', 'linux', 'x86_64', 'linux-x86_64'],
|
||||
['11.0.25', 'macos', 'aarch64', 'macosx-aarch64'],
|
||||
['17.0.13', 'windows', 'x86_64', 'windows-x86_64'],
|
||||
['21.0.5', 'linux', 'x86_64', 'linux-x86_64']
|
||||
['21.0.5', 'linux', 'x86_64', 'linux-x86_64'],
|
||||
['25', 'linux', 'aarch64', 'linux-aarch64'],
|
||||
['25.0.3', 'macos', 'x86_64', 'macosx-x86_64']
|
||||
])(
|
||||
'should get releases with the specified version "%s", OS "%s" and arch "%s"',
|
||||
async (
|
||||
@@ -41,7 +43,7 @@ describe('Check getAvailableReleases', () => {
|
||||
|
||||
const releases = await distribution['getAvailableReleases']();
|
||||
expect(releases).not.toBeNull();
|
||||
expect(releases.length).toBe(4);
|
||||
expect(releases.length).toBe(5);
|
||||
releases.forEach(release =>
|
||||
expect(release.downloadUrl).toContain(expectedPattern)
|
||||
);
|
||||
@@ -173,6 +175,37 @@ describe('Check findPackageForDownload', () => {
|
||||
'windows',
|
||||
'x86_64',
|
||||
'https://github.com/Tencent/TencentKona-21/releases/download/TencentKona-21.0.5/TencentKona-21.0.5.b1_jdk_windows-x86_64_signed.zip'
|
||||
],
|
||||
|
||||
[
|
||||
'25',
|
||||
'linux',
|
||||
'aarch64',
|
||||
'https://github.com/Tencent/TencentKona-25/releases/download/TencentKona-25.0.3/TencentKona-25.0.3.b1-jdk_linux-aarch64.tar.gz'
|
||||
],
|
||||
[
|
||||
'25.0.3',
|
||||
'linux',
|
||||
'x86_64',
|
||||
'https://github.com/Tencent/TencentKona-25/releases/download/TencentKona-25.0.3/TencentKona-25.0.3.b1-jdk_linux-x86_64.tar.gz'
|
||||
],
|
||||
[
|
||||
'25.0.3',
|
||||
'macos',
|
||||
'aarch64',
|
||||
'https://github.com/Tencent/TencentKona-25/releases/download/TencentKona-25.0.3/TencentKona-25.0.3.b1_jdk_macosx-aarch64_notarized.tar.gz'
|
||||
],
|
||||
[
|
||||
'25.0.3',
|
||||
'macos',
|
||||
'x86_64',
|
||||
'https://github.com/Tencent/TencentKona-25/releases/download/TencentKona-25.0.3/TencentKona-25.0.3.b1_jdk_macosx-x86_64_notarized.tar.gz'
|
||||
],
|
||||
[
|
||||
'25.0.3',
|
||||
'windows',
|
||||
'x86_64',
|
||||
'https://github.com/Tencent/TencentKona-25/releases/download/TencentKona-25.0.3/TencentKona-25.0.3.b1_jdk_windows-x86_64_signed.zip'
|
||||
]
|
||||
])(
|
||||
'should return the download URL with the specified version "%s", OS "%s" and arch "%s"',
|
||||
|
||||
@@ -46,8 +46,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: altHome,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: altHome
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(false);
|
||||
@@ -95,8 +94,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -177,8 +175,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -263,8 +260,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -341,8 +337,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -412,8 +407,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -505,8 +499,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -565,8 +558,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -624,8 +616,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -708,8 +699,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -788,8 +778,7 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@@ -814,7 +803,7 @@ describe('toolchains tests', () => {
|
||||
).toEqual(result);
|
||||
}, 100000);
|
||||
|
||||
it('does not overwrite existing toolchains.xml files', async () => {
|
||||
it('extends existing toolchains.xml files instead of overwriting them', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
@@ -843,13 +832,20 @@ describe('toolchains tests', () => {
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: false
|
||||
settingsDirectory: m2Dir
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(originalFile);
|
||||
|
||||
const updated = fs.readFileSync(toolchainsFile, 'utf-8');
|
||||
// The pre-existing (Sun 1.6) toolchain must be preserved ...
|
||||
expect(updated).toContain('<id>sun_1.6</id>');
|
||||
expect(updated).toContain('<jdkHome>/opt/jdk/sun/1.6</jdkHome>');
|
||||
// ... and the newly installed JDK must be included in the merged result.
|
||||
expect(updated).toContain('<id>temurin_17</id>');
|
||||
expect(updated).toContain('<vendor>Eclipse Temurin</vendor>');
|
||||
expect(updated).toContain(`<jdkHome>${jdkInfo.jdkHome}</jdkHome>`);
|
||||
}, 100000);
|
||||
|
||||
it('generates valid toolchains.xml with minimal configuration', () => {
|
||||
@@ -914,4 +910,55 @@ describe('toolchains tests', () => {
|
||||
)
|
||||
);
|
||||
}, 100000);
|
||||
|
||||
it('preserves toolchains from previous executions across multiple setup-java runs', async () => {
|
||||
// Regression test for https://github.com/actions/setup-java/issues/1099
|
||||
// Running setup-java several times in the same job (e.g. multiple steps / multiple
|
||||
// java-version entries) must accumulate every JDK in toolchains.xml rather
|
||||
// than replacing previously registered entries.
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'settings-path') return m2Dir;
|
||||
return '';
|
||||
});
|
||||
|
||||
const runs = [
|
||||
{
|
||||
version: '8',
|
||||
distributionName: 'temurin',
|
||||
id: 'temurin_8',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/8.0.1-12/x64'
|
||||
},
|
||||
{
|
||||
version: '11',
|
||||
distributionName: 'temurin',
|
||||
id: 'temurin_11',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.1-12/x64'
|
||||
},
|
||||
{
|
||||
version: '17',
|
||||
distributionName: 'temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
}
|
||||
];
|
||||
|
||||
for (const run of runs) {
|
||||
await toolchains.configureToolchains(
|
||||
run.version,
|
||||
run.distributionName,
|
||||
run.jdkHome,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
const contents = fs.readFileSync(toolchainsFile, 'utf-8');
|
||||
|
||||
for (const run of runs) {
|
||||
expect(contents).toContain(`<id>${run.id}</id>`);
|
||||
expect(contents).toContain(`<jdkHome>${run.jdkHome}</jdkHome>`);
|
||||
}
|
||||
// Exactly one <toolchain> entry per run – no duplicates, none dropped.
|
||||
expect((contents.match(/<toolchain>/g) || []).length).toBe(runs.length);
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
137
dist/cleanup/index.js
vendored
137
dist/cleanup/index.js
vendored
@@ -51968,23 +51968,28 @@ const CACHE_KEY_PREFIX = 'setup-java';
|
||||
const supportedPackageManager = [
|
||||
{
|
||||
id: 'maven',
|
||||
path: [
|
||||
(0, path_1.join)(os_1.default.homedir(), '.m2', 'repository'),
|
||||
(0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists')
|
||||
],
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.m2', 'repository')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven
|
||||
pattern: [
|
||||
'**/pom.xml',
|
||||
'**/.mvn/wrapper/maven-wrapper.properties',
|
||||
'**/.mvn/extensions.xml'
|
||||
],
|
||||
// The Maven wrapper distribution only depends on the wrapper properties,
|
||||
// which change very rarely, so it is cached separately from the local
|
||||
// repository. This keeps it available across the frequent pom.xml changes
|
||||
// that rotate the main cache key. See issue #1095.
|
||||
additionalCaches: [
|
||||
{
|
||||
name: 'maven-wrapper',
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
pattern: ['**/.mvn/wrapper/maven-wrapper.properties']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'gradle',
|
||||
path: [
|
||||
(0, path_1.join)(os_1.default.homedir(), '.gradle', 'caches'),
|
||||
(0, path_1.join)(os_1.default.homedir(), '.gradle', 'wrapper')
|
||||
],
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.gradle', 'caches')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||
pattern: [
|
||||
'**/*.gradle*',
|
||||
@@ -51993,6 +51998,17 @@ const supportedPackageManager = [
|
||||
'buildSrc/**/Dependencies.kt',
|
||||
'gradle/*.versions.toml',
|
||||
'**/versions.properties'
|
||||
],
|
||||
// The Gradle wrapper distribution only depends on the wrapper properties,
|
||||
// which change very rarely, so it is cached separately from the Gradle
|
||||
// caches. This keeps it available across the frequent *.gradle* changes
|
||||
// that rotate the main cache key. See issue #269.
|
||||
additionalCaches: [
|
||||
{
|
||||
name: 'gradle-wrapper',
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.gradle', 'wrapper')],
|
||||
pattern: ['**/gradle-wrapper.properties']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -52028,6 +52044,19 @@ function findPackageManager(id) {
|
||||
}
|
||||
return packageManager;
|
||||
}
|
||||
/**
|
||||
* State keys used to carry an additional cache's restore-time information over
|
||||
* to the post (save) action, scoped by the additional cache name.
|
||||
*/
|
||||
function additionalCachePrimaryKeyState(name) {
|
||||
return `${STATE_CACHE_PRIMARY_KEY}-${name}`;
|
||||
}
|
||||
function additionalCacheMatchedKeyState(name) {
|
||||
return `${CACHE_MATCHED_KEY}-${name}`;
|
||||
}
|
||||
function buildCacheKey(id, fileHash) {
|
||||
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${id}-${fileHash}`;
|
||||
}
|
||||
/**
|
||||
* A function that generates a cache key to use.
|
||||
* Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"".
|
||||
@@ -52042,7 +52071,21 @@ function computeCacheKey(packageManager, cacheDependencyPath) {
|
||||
if (!fileHash) {
|
||||
throw new Error(`No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository`);
|
||||
}
|
||||
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`;
|
||||
return buildCacheKey(packageManager.id, fileHash);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Computes the cache key for an additional cache. Unlike {@link computeCacheKey}
|
||||
* this returns undefined (instead of throwing) when no file matches the pattern,
|
||||
* because additional caches are optional features that many projects do not use.
|
||||
*/
|
||||
function computeAdditionalCacheKey(additionalCache) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const fileHash = yield glob.hashFiles(additionalCache.pattern.join('\n'));
|
||||
if (!fileHash) {
|
||||
return undefined;
|
||||
}
|
||||
return buildCacheKey(additionalCache.name, fileHash);
|
||||
});
|
||||
}
|
||||
/**
|
||||
@@ -52051,6 +52094,7 @@ function computeCacheKey(packageManager, cacheDependencyPath) {
|
||||
* @param cacheDependencyPath The path to a dependency file
|
||||
*/
|
||||
function restore(id, cacheDependencyPath) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const packageManager = findPackageManager(id);
|
||||
const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath);
|
||||
@@ -52068,19 +52112,48 @@ function restore(id, cacheDependencyPath) {
|
||||
core.setOutput('cache-hit', false);
|
||||
core.info(`${packageManager.id} cache is not found`);
|
||||
}
|
||||
for (const additionalCache of (_a = packageManager.additionalCaches) !== null && _a !== void 0 ? _a : []) {
|
||||
yield restoreAdditionalCache(additionalCache);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.restore = restore;
|
||||
/**
|
||||
* Restore an additional cache (e.g. a build-tool wrapper distribution) that is
|
||||
* keyed independently of the main dependency cache so that it survives changes
|
||||
* to volatile dependency files. Skips silently when the project does not use
|
||||
* the corresponding feature.
|
||||
*/
|
||||
function restoreAdditionalCache(additionalCache) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const primaryKey = yield computeAdditionalCacheKey(additionalCache);
|
||||
if (!primaryKey) {
|
||||
core.debug(`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`);
|
||||
return;
|
||||
}
|
||||
core.debug(`${additionalCache.name} primary key is ${primaryKey}`);
|
||||
core.saveState(additionalCachePrimaryKeyState(additionalCache.name), primaryKey);
|
||||
const matchedKey = yield cache.restoreCache(additionalCache.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(additionalCacheMatchedKeyState(additionalCache.name), matchedKey);
|
||||
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Save the dependency cache
|
||||
* @param id ID of the package manager, should be "maven" or "gradle"
|
||||
*/
|
||||
function save(id) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const packageManager = findPackageManager(id);
|
||||
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||
for (const additionalCache of (_a = packageManager.additionalCaches) !== null && _a !== void 0 ? _a : []) {
|
||||
yield saveAdditionalCache(packageManager, additionalCache);
|
||||
}
|
||||
if (!primaryKey) {
|
||||
core.warning('Error retrieving key from state.');
|
||||
return;
|
||||
@@ -52117,6 +52190,52 @@ function save(id) {
|
||||
});
|
||||
}
|
||||
exports.save = save;
|
||||
/**
|
||||
* Save an additional cache under its own key. Skips when no key was recorded at
|
||||
* restore time (feature unused) or when the exact key was already restored.
|
||||
*/
|
||||
function saveAdditionalCache(packageManager, additionalCache) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const primaryKey = core.getState(additionalCachePrimaryKeyState(additionalCache.name));
|
||||
const matchedKey = core.getState(additionalCacheMatchedKeyState(additionalCache.name));
|
||||
if (!primaryKey) {
|
||||
// The feature is not used by this project, nothing to save.
|
||||
core.debug(`No primary key for the ${additionalCache.name} cache, not saving cache.`);
|
||||
return;
|
||||
}
|
||||
else if (matchedKey === primaryKey) {
|
||||
core.info(`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const cacheId = yield cache.saveCache(additionalCache.path, primaryKey);
|
||||
if (cacheId === -1) {
|
||||
core.debug(`${additionalCache.name} cache was not saved for the key: ${primaryKey}`);
|
||||
return;
|
||||
}
|
||||
core.info(`${additionalCache.name} cache saved with the key: ${primaryKey}`);
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.name === cache.ValidationError.name) {
|
||||
// The cache paths did not resolve, e.g. the wrapper distribution was
|
||||
// never downloaded because a system build tool was used or the download
|
||||
// failed. Optional wrapper caches must not fail the post step, so skip.
|
||||
core.debug(`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
if (err.name === cache.ReserveCacheError.name) {
|
||||
core.info(err.message);
|
||||
}
|
||||
else {
|
||||
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
||||
core.warning('Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for details.');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param packageManager the specified package manager by user
|
||||
* @param error the error thrown by the saveCache
|
||||
|
||||
164
dist/setup/index.js
vendored
164
dist/setup/index.js
vendored
@@ -77833,23 +77833,28 @@ const CACHE_KEY_PREFIX = 'setup-java';
|
||||
const supportedPackageManager = [
|
||||
{
|
||||
id: 'maven',
|
||||
path: [
|
||||
(0, path_1.join)(os_1.default.homedir(), '.m2', 'repository'),
|
||||
(0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists')
|
||||
],
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.m2', 'repository')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven
|
||||
pattern: [
|
||||
'**/pom.xml',
|
||||
'**/.mvn/wrapper/maven-wrapper.properties',
|
||||
'**/.mvn/extensions.xml'
|
||||
],
|
||||
// The Maven wrapper distribution only depends on the wrapper properties,
|
||||
// which change very rarely, so it is cached separately from the local
|
||||
// repository. This keeps it available across the frequent pom.xml changes
|
||||
// that rotate the main cache key. See issue #1095.
|
||||
additionalCaches: [
|
||||
{
|
||||
name: 'maven-wrapper',
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
pattern: ['**/.mvn/wrapper/maven-wrapper.properties']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'gradle',
|
||||
path: [
|
||||
(0, path_1.join)(os_1.default.homedir(), '.gradle', 'caches'),
|
||||
(0, path_1.join)(os_1.default.homedir(), '.gradle', 'wrapper')
|
||||
],
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.gradle', 'caches')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||
pattern: [
|
||||
'**/*.gradle*',
|
||||
@@ -77858,6 +77863,17 @@ const supportedPackageManager = [
|
||||
'buildSrc/**/Dependencies.kt',
|
||||
'gradle/*.versions.toml',
|
||||
'**/versions.properties'
|
||||
],
|
||||
// The Gradle wrapper distribution only depends on the wrapper properties,
|
||||
// which change very rarely, so it is cached separately from the Gradle
|
||||
// caches. This keeps it available across the frequent *.gradle* changes
|
||||
// that rotate the main cache key. See issue #269.
|
||||
additionalCaches: [
|
||||
{
|
||||
name: 'gradle-wrapper',
|
||||
path: [(0, path_1.join)(os_1.default.homedir(), '.gradle', 'wrapper')],
|
||||
pattern: ['**/gradle-wrapper.properties']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -77893,6 +77909,19 @@ function findPackageManager(id) {
|
||||
}
|
||||
return packageManager;
|
||||
}
|
||||
/**
|
||||
* State keys used to carry an additional cache's restore-time information over
|
||||
* to the post (save) action, scoped by the additional cache name.
|
||||
*/
|
||||
function additionalCachePrimaryKeyState(name) {
|
||||
return `${STATE_CACHE_PRIMARY_KEY}-${name}`;
|
||||
}
|
||||
function additionalCacheMatchedKeyState(name) {
|
||||
return `${CACHE_MATCHED_KEY}-${name}`;
|
||||
}
|
||||
function buildCacheKey(id, fileHash) {
|
||||
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${id}-${fileHash}`;
|
||||
}
|
||||
/**
|
||||
* A function that generates a cache key to use.
|
||||
* Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"".
|
||||
@@ -77907,7 +77936,21 @@ function computeCacheKey(packageManager, cacheDependencyPath) {
|
||||
if (!fileHash) {
|
||||
throw new Error(`No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository`);
|
||||
}
|
||||
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`;
|
||||
return buildCacheKey(packageManager.id, fileHash);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Computes the cache key for an additional cache. Unlike {@link computeCacheKey}
|
||||
* this returns undefined (instead of throwing) when no file matches the pattern,
|
||||
* because additional caches are optional features that many projects do not use.
|
||||
*/
|
||||
function computeAdditionalCacheKey(additionalCache) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const fileHash = yield glob.hashFiles(additionalCache.pattern.join('\n'));
|
||||
if (!fileHash) {
|
||||
return undefined;
|
||||
}
|
||||
return buildCacheKey(additionalCache.name, fileHash);
|
||||
});
|
||||
}
|
||||
/**
|
||||
@@ -77916,6 +77959,7 @@ function computeCacheKey(packageManager, cacheDependencyPath) {
|
||||
* @param cacheDependencyPath The path to a dependency file
|
||||
*/
|
||||
function restore(id, cacheDependencyPath) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const packageManager = findPackageManager(id);
|
||||
const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath);
|
||||
@@ -77933,19 +77977,48 @@ function restore(id, cacheDependencyPath) {
|
||||
core.setOutput('cache-hit', false);
|
||||
core.info(`${packageManager.id} cache is not found`);
|
||||
}
|
||||
for (const additionalCache of (_a = packageManager.additionalCaches) !== null && _a !== void 0 ? _a : []) {
|
||||
yield restoreAdditionalCache(additionalCache);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.restore = restore;
|
||||
/**
|
||||
* Restore an additional cache (e.g. a build-tool wrapper distribution) that is
|
||||
* keyed independently of the main dependency cache so that it survives changes
|
||||
* to volatile dependency files. Skips silently when the project does not use
|
||||
* the corresponding feature.
|
||||
*/
|
||||
function restoreAdditionalCache(additionalCache) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const primaryKey = yield computeAdditionalCacheKey(additionalCache);
|
||||
if (!primaryKey) {
|
||||
core.debug(`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`);
|
||||
return;
|
||||
}
|
||||
core.debug(`${additionalCache.name} primary key is ${primaryKey}`);
|
||||
core.saveState(additionalCachePrimaryKeyState(additionalCache.name), primaryKey);
|
||||
const matchedKey = yield cache.restoreCache(additionalCache.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(additionalCacheMatchedKeyState(additionalCache.name), matchedKey);
|
||||
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Save the dependency cache
|
||||
* @param id ID of the package manager, should be "maven" or "gradle"
|
||||
*/
|
||||
function save(id) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const packageManager = findPackageManager(id);
|
||||
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||
for (const additionalCache of (_a = packageManager.additionalCaches) !== null && _a !== void 0 ? _a : []) {
|
||||
yield saveAdditionalCache(packageManager, additionalCache);
|
||||
}
|
||||
if (!primaryKey) {
|
||||
core.warning('Error retrieving key from state.');
|
||||
return;
|
||||
@@ -77982,6 +78055,52 @@ function save(id) {
|
||||
});
|
||||
}
|
||||
exports.save = save;
|
||||
/**
|
||||
* Save an additional cache under its own key. Skips when no key was recorded at
|
||||
* restore time (feature unused) or when the exact key was already restored.
|
||||
*/
|
||||
function saveAdditionalCache(packageManager, additionalCache) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const primaryKey = core.getState(additionalCachePrimaryKeyState(additionalCache.name));
|
||||
const matchedKey = core.getState(additionalCacheMatchedKeyState(additionalCache.name));
|
||||
if (!primaryKey) {
|
||||
// The feature is not used by this project, nothing to save.
|
||||
core.debug(`No primary key for the ${additionalCache.name} cache, not saving cache.`);
|
||||
return;
|
||||
}
|
||||
else if (matchedKey === primaryKey) {
|
||||
core.info(`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const cacheId = yield cache.saveCache(additionalCache.path, primaryKey);
|
||||
if (cacheId === -1) {
|
||||
core.debug(`${additionalCache.name} cache was not saved for the key: ${primaryKey}`);
|
||||
return;
|
||||
}
|
||||
core.info(`${additionalCache.name} cache saved with the key: ${primaryKey}`);
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.name === cache.ValidationError.name) {
|
||||
// The cache paths did not resolve, e.g. the wrapper distribution was
|
||||
// never downloaded because a system build tool was used or the download
|
||||
// failed. Optional wrapper caches must not fail the post step, so skip.
|
||||
core.debug(`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
if (err.name === cache.ReserveCacheError.name) {
|
||||
core.info(err.message);
|
||||
}
|
||||
else {
|
||||
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
||||
core.warning('Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for details.');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param packageManager the specified package manager by user
|
||||
* @param error the error thrown by the saveCache
|
||||
@@ -81751,7 +81870,6 @@ const path = __importStar(__nccwpck_require__(16928));
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
const io = __importStar(__nccwpck_require__(94994));
|
||||
const constants = __importStar(__nccwpck_require__(27242));
|
||||
const util_1 = __nccwpck_require__(54527);
|
||||
const xmlbuilder2_1 = __nccwpck_require__(54697);
|
||||
function configureToolchains(version, distributionName, jdkHome, toolchainId) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@@ -81759,7 +81877,6 @@ function configureToolchains(version, distributionName, jdkHome, toolchainId) {
|
||||
const id = toolchainId || `${vendor}_${version}`;
|
||||
const settingsDirectory = core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = (0, util_1.getBooleanInput)(constants.INPUT_OVERWRITE_SETTINGS, true);
|
||||
yield createToolchainsSettings({
|
||||
jdkInfo: {
|
||||
version,
|
||||
@@ -81767,13 +81884,12 @@ function configureToolchains(version, distributionName, jdkHome, toolchainId) {
|
||||
id,
|
||||
jdkHome
|
||||
},
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
settingsDirectory
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.configureToolchains = configureToolchains;
|
||||
function createToolchainsSettings({ jdkInfo, settingsDirectory, overwriteSettings }) {
|
||||
function createToolchainsSettings({ jdkInfo, settingsDirectory }) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
@@ -81781,7 +81897,7 @@ function createToolchainsSettings({ jdkInfo, settingsDirectory, overwriteSetting
|
||||
yield io.mkdirP(settingsDirectory);
|
||||
const originalToolchains = yield readExistingToolchainsFile(settingsDirectory);
|
||||
const updatedToolchains = generateToolchainDefinition(originalToolchains, jdkInfo.version, jdkInfo.vendor, jdkInfo.id, jdkInfo.jdkHome);
|
||||
yield writeToolchainsFileToDisk(settingsDirectory, updatedToolchains, overwriteSettings);
|
||||
yield writeToolchainsFileToDisk(settingsDirectory, updatedToolchains);
|
||||
});
|
||||
}
|
||||
exports.createToolchainsSettings = createToolchainsSettings;
|
||||
@@ -81867,19 +81983,21 @@ function readExistingToolchainsFile(directory) {
|
||||
return '';
|
||||
});
|
||||
}
|
||||
function writeToolchainsFileToDisk(directory, settings, overwriteSettings) {
|
||||
function writeToolchainsFileToDisk(directory, settings) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
}
|
||||
else if (!settingsExists) {
|
||||
core.info(`Writing to ${location}`);
|
||||
// The toolchains file is produced by a non-destructive merge (existing JDK,
|
||||
// custom, and non-jdk toolchains are preserved – see generateToolchainDefinition),
|
||||
// so it is always safe to write it. Unlike settings.xml, it is therefore not
|
||||
// gated behind the `overwrite-settings` input; that would prevent subsequent
|
||||
// setup-java runs from registering additional JDKs and silently drop the
|
||||
// toolchain entries created by earlier runs.
|
||||
if (settingsExists) {
|
||||
core.info(`Updating existing file ${location}`);
|
||||
}
|
||||
else {
|
||||
core.info(`Skipping generation of ${location} because file already exists and overwriting is not enabled`);
|
||||
return;
|
||||
core.info(`Writing to ${location}`);
|
||||
}
|
||||
return fs.writeFileSync(location, settings, {
|
||||
encoding: 'utf-8',
|
||||
|
||||
@@ -237,7 +237,7 @@ The available package types are:
|
||||
- `jre+ft` - JBR (FreeType)
|
||||
|
||||
### Tencent Kona
|
||||
**NOTE:** Tencent Kona supports major versions 8, 11, 17 and 21, and provides jdk only.
|
||||
**NOTE:** Tencent Kona supports major versions 8, 11, 17, 21 and 25, and provides jdk only.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
@@ -684,6 +684,8 @@ The `setup-java` action generates a basic [Maven Toolchains declaration](https:/
|
||||
### Installing Multiple JDKs With Toolchains
|
||||
Subsequent calls to `setup-java` with distinct distribution and version parameters will continue to extend the toolchains declaration and make all specified Java versions available.
|
||||
|
||||
Toolchain entries are always merged non-destructively: existing JDK, custom, and user-managed toolchains are preserved, and only an entry with the exact same `type` and `provides.id` is replaced. This behavior is independent of the `overwrite-settings` input, which only controls regeneration of `settings.xml`. As a result, running `setup-java` several times in the same job (for example in multiple steps or with multiple `java-version` values) accumulates every JDK in `toolchains.xml` instead of dropping previously registered entries.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v5
|
||||
|
||||
194
src/cache.ts
194
src/cache.ts
@@ -12,6 +12,30 @@ const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
||||
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
||||
const CACHE_KEY_PREFIX = 'setup-java';
|
||||
|
||||
/**
|
||||
* An additional cache entry that is restored and saved independently of the
|
||||
* main dependency cache. Used for build-tool wrapper distributions that rarely
|
||||
* change (e.g. the Maven wrapper distribution) so that they are not evicted
|
||||
* every time a volatile dependency file such as pom.xml changes. See
|
||||
* https://github.com/actions/setup-java/issues/1095.
|
||||
*/
|
||||
interface AdditionalCache {
|
||||
/**
|
||||
* Short identifier for the cache, used to build its cache key and to scope
|
||||
* the state keys that carry information from restore to save.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Paths that make up this cache entry.
|
||||
*/
|
||||
path: string[];
|
||||
/**
|
||||
* Glob patterns whose hash forms the cache key. If no file matches, the
|
||||
* cache is skipped silently (the project simply does not use this feature).
|
||||
*/
|
||||
pattern: string[];
|
||||
}
|
||||
|
||||
interface PackageManager {
|
||||
id: 'maven' | 'gradle' | 'sbt';
|
||||
/**
|
||||
@@ -19,27 +43,36 @@ interface PackageManager {
|
||||
*/
|
||||
path: string[];
|
||||
pattern: string[];
|
||||
/**
|
||||
* Additional caches keyed independently of the main dependency cache.
|
||||
*/
|
||||
additionalCaches?: AdditionalCache[];
|
||||
}
|
||||
const supportedPackageManager: PackageManager[] = [
|
||||
{
|
||||
id: 'maven',
|
||||
path: [
|
||||
join(os.homedir(), '.m2', 'repository'),
|
||||
join(os.homedir(), '.m2', 'wrapper', 'dists')
|
||||
],
|
||||
path: [join(os.homedir(), '.m2', 'repository')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---maven
|
||||
pattern: [
|
||||
'**/pom.xml',
|
||||
'**/.mvn/wrapper/maven-wrapper.properties',
|
||||
'**/.mvn/extensions.xml'
|
||||
],
|
||||
// The Maven wrapper distribution only depends on the wrapper properties,
|
||||
// which change very rarely, so it is cached separately from the local
|
||||
// repository. This keeps it available across the frequent pom.xml changes
|
||||
// that rotate the main cache key. See issue #1095.
|
||||
additionalCaches: [
|
||||
{
|
||||
name: 'maven-wrapper',
|
||||
path: [join(os.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
pattern: ['**/.mvn/wrapper/maven-wrapper.properties']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'gradle',
|
||||
path: [
|
||||
join(os.homedir(), '.gradle', 'caches'),
|
||||
join(os.homedir(), '.gradle', 'wrapper')
|
||||
],
|
||||
path: [join(os.homedir(), '.gradle', 'caches')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||
pattern: [
|
||||
'**/*.gradle*',
|
||||
@@ -48,6 +81,17 @@ const supportedPackageManager: PackageManager[] = [
|
||||
'buildSrc/**/Dependencies.kt',
|
||||
'gradle/*.versions.toml',
|
||||
'**/versions.properties'
|
||||
],
|
||||
// The Gradle wrapper distribution only depends on the wrapper properties,
|
||||
// which change very rarely, so it is cached separately from the Gradle
|
||||
// caches. This keeps it available across the frequent *.gradle* changes
|
||||
// that rotate the main cache key. See issue #269.
|
||||
additionalCaches: [
|
||||
{
|
||||
name: 'gradle-wrapper',
|
||||
path: [join(os.homedir(), '.gradle', 'wrapper')],
|
||||
pattern: ['**/gradle-wrapper.properties']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -87,6 +131,21 @@ function findPackageManager(id: string): PackageManager {
|
||||
return packageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* State keys used to carry an additional cache's restore-time information over
|
||||
* to the post (save) action, scoped by the additional cache name.
|
||||
*/
|
||||
function additionalCachePrimaryKeyState(name: string): string {
|
||||
return `${STATE_CACHE_PRIMARY_KEY}-${name}`;
|
||||
}
|
||||
function additionalCacheMatchedKeyState(name: string): string {
|
||||
return `${CACHE_MATCHED_KEY}-${name}`;
|
||||
}
|
||||
|
||||
function buildCacheKey(id: string, fileHash: string): string {
|
||||
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${id}-${fileHash}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that generates a cache key to use.
|
||||
* Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"".
|
||||
@@ -105,7 +164,22 @@ async function computeCacheKey(
|
||||
`No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository`
|
||||
);
|
||||
}
|
||||
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`;
|
||||
return buildCacheKey(packageManager.id, fileHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the cache key for an additional cache. Unlike {@link computeCacheKey}
|
||||
* this returns undefined (instead of throwing) when no file matches the pattern,
|
||||
* because additional caches are optional features that many projects do not use.
|
||||
*/
|
||||
async function computeAdditionalCacheKey(
|
||||
additionalCache: AdditionalCache
|
||||
): Promise<string | undefined> {
|
||||
const fileHash = await glob.hashFiles(additionalCache.pattern.join('\n'));
|
||||
if (!fileHash) {
|
||||
return undefined;
|
||||
}
|
||||
return buildCacheKey(additionalCache.name, fileHash);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,6 +204,40 @@ export async function restore(id: string, cacheDependencyPath: string) {
|
||||
core.setOutput('cache-hit', false);
|
||||
core.info(`${packageManager.id} cache is not found`);
|
||||
}
|
||||
|
||||
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
||||
await restoreAdditionalCache(additionalCache);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore an additional cache (e.g. a build-tool wrapper distribution) that is
|
||||
* keyed independently of the main dependency cache so that it survives changes
|
||||
* to volatile dependency files. Skips silently when the project does not use
|
||||
* the corresponding feature.
|
||||
*/
|
||||
async function restoreAdditionalCache(additionalCache: AdditionalCache) {
|
||||
const primaryKey = await computeAdditionalCacheKey(additionalCache);
|
||||
if (!primaryKey) {
|
||||
core.debug(
|
||||
`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
core.debug(`${additionalCache.name} primary key is ${primaryKey}`);
|
||||
core.saveState(
|
||||
additionalCachePrimaryKeyState(additionalCache.name),
|
||||
primaryKey
|
||||
);
|
||||
|
||||
const matchedKey = await cache.restoreCache(additionalCache.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(
|
||||
additionalCacheMatchedKeyState(additionalCache.name),
|
||||
matchedKey
|
||||
);
|
||||
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,6 +251,10 @@ export async function save(id: string) {
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||
|
||||
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
||||
await saveAdditionalCache(packageManager, additionalCache);
|
||||
}
|
||||
|
||||
if (!primaryKey) {
|
||||
core.warning('Error retrieving key from state.');
|
||||
return;
|
||||
@@ -180,6 +292,70 @@ export async function save(id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an additional cache under its own key. Skips when no key was recorded at
|
||||
* restore time (feature unused) or when the exact key was already restored.
|
||||
*/
|
||||
async function saveAdditionalCache(
|
||||
packageManager: PackageManager,
|
||||
additionalCache: AdditionalCache
|
||||
) {
|
||||
const primaryKey = core.getState(
|
||||
additionalCachePrimaryKeyState(additionalCache.name)
|
||||
);
|
||||
const matchedKey = core.getState(
|
||||
additionalCacheMatchedKeyState(additionalCache.name)
|
||||
);
|
||||
|
||||
if (!primaryKey) {
|
||||
// The feature is not used by this project, nothing to save.
|
||||
core.debug(
|
||||
`No primary key for the ${additionalCache.name} cache, not saving cache.`
|
||||
);
|
||||
return;
|
||||
} else if (matchedKey === primaryKey) {
|
||||
core.info(
|
||||
`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const cacheId = await cache.saveCache(additionalCache.path, primaryKey);
|
||||
if (cacheId === -1) {
|
||||
core.debug(
|
||||
`${additionalCache.name} cache was not saved for the key: ${primaryKey}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
core.info(
|
||||
`${additionalCache.name} cache saved with the key: ${primaryKey}`
|
||||
);
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
|
||||
if (err.name === cache.ValidationError.name) {
|
||||
// The cache paths did not resolve, e.g. the wrapper distribution was
|
||||
// never downloaded because a system build tool was used or the download
|
||||
// failed. Optional wrapper caches must not fail the post step, so skip.
|
||||
core.debug(
|
||||
`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err.name === cache.ReserveCacheError.name) {
|
||||
core.info(err.message);
|
||||
} else {
|
||||
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
||||
core.warning(
|
||||
'Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for details.'
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param packageManager the specified package manager by user
|
||||
* @param error the error thrown by the saveCache
|
||||
|
||||
@@ -5,7 +5,6 @@ import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as constants from './constants';
|
||||
|
||||
import {getBooleanInput} from './util';
|
||||
import {create as xmlCreate} from 'xmlbuilder2';
|
||||
|
||||
interface JdkInfo {
|
||||
@@ -27,10 +26,6 @@ export async function configureToolchains(
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
true
|
||||
);
|
||||
|
||||
await createToolchainsSettings({
|
||||
jdkInfo: {
|
||||
@@ -39,19 +34,16 @@ export async function configureToolchains(
|
||||
id,
|
||||
jdkHome
|
||||
},
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
settingsDirectory
|
||||
});
|
||||
}
|
||||
|
||||
export async function createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
settingsDirectory
|
||||
}: {
|
||||
jdkInfo: JdkInfo;
|
||||
settingsDirectory: string;
|
||||
overwriteSettings: boolean;
|
||||
}) {
|
||||
core.info(
|
||||
`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`
|
||||
@@ -68,11 +60,7 @@ export async function createToolchainsSettings({
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
);
|
||||
await writeToolchainsFileToDisk(
|
||||
settingsDirectory,
|
||||
updatedToolchains,
|
||||
overwriteSettings
|
||||
);
|
||||
await writeToolchainsFileToDisk(settingsDirectory, updatedToolchains);
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
@@ -172,22 +160,19 @@ async function readExistingToolchainsFile(directory: string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
async function writeToolchainsFileToDisk(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
) {
|
||||
async function writeToolchainsFileToDisk(directory: string, settings: string) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
} else if (!settingsExists) {
|
||||
core.info(`Writing to ${location}`);
|
||||
// The toolchains file is produced by a non-destructive merge (existing JDK,
|
||||
// custom, and non-jdk toolchains are preserved – see generateToolchainDefinition),
|
||||
// so it is always safe to write it. Unlike settings.xml, it is therefore not
|
||||
// gated behind the `overwrite-settings` input; that would prevent subsequent
|
||||
// setup-java runs from registering additional JDKs and silently drop the
|
||||
// toolchain entries created by earlier runs.
|
||||
if (settingsExists) {
|
||||
core.info(`Updating existing file ${location}`);
|
||||
} else {
|
||||
core.info(
|
||||
`Skipping generation of ${location} because file already exists and overwriting is not enabled`
|
||||
);
|
||||
return;
|
||||
core.info(`Writing to ${location}`);
|
||||
}
|
||||
|
||||
return fs.writeFileSync(location, settings, {
|
||||
|
||||
Reference in New Issue
Block a user