mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
improve core.info messages
This commit is contained in:
parent
d87fc52c90
commit
2c10c084cc
3 changed files with 70 additions and 57 deletions
20
.github/workflows/e2e-versions.yml
vendored
20
.github/workflows/e2e-versions.yml
vendored
|
@ -70,8 +70,8 @@ jobs:
|
||||||
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-java-major-minor-versions-with-check-latest:
|
setup-java-check-latest:
|
||||||
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
name: ${{ matrix.distribution }} ${{ matrix.version }} - check-latest flag - ${{ matrix.os }}
|
||||||
needs: setup-java-major-versions
|
needs: setup-java-major-versions
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -79,20 +79,6 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
distribution: ['adopt', 'zulu']
|
distribution: ['adopt', 'zulu']
|
||||||
version:
|
|
||||||
- '11.0'
|
|
||||||
- '8.0.282'
|
|
||||||
- '11.0.2+7'
|
|
||||||
include:
|
|
||||||
- distribution: 'adopt'
|
|
||||||
version: '12.0.2+10.1'
|
|
||||||
os: macos-latest
|
|
||||||
- distribution: 'adopt'
|
|
||||||
version: '12.0.2+10.1'
|
|
||||||
os: windows-latest
|
|
||||||
- distribution: 'adopt'
|
|
||||||
version: '12.0.2+10.1'
|
|
||||||
os: ubuntu-latest
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -100,8 +86,8 @@ jobs:
|
||||||
uses: ./
|
uses: ./
|
||||||
id: setup-java
|
id: setup-java
|
||||||
with:
|
with:
|
||||||
java-version: ${{ matrix.version }}
|
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
|
java-version: 11
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe('findInToolcache', () => {
|
||||||
[{ version: '8', architecture: 'x64', packageType: 'jdk' }, null],
|
[{ version: '8', architecture: 'x64', packageType: 'jdk' }, null],
|
||||||
[{ version: '11', architecture: 'x86', packageType: 'jdk' }, null],
|
[{ version: '11', architecture: 'x86', packageType: 'jdk' }, null],
|
||||||
[{ version: '11', architecture: 'x86', packageType: 'jre' }, null]
|
[{ version: '11', architecture: 'x86', packageType: 'jre' }, null]
|
||||||
])(`should find java for path %o -> %o`, (input, expected) => {
|
])(`should find java for path %s -> %s`, (input, expected) => {
|
||||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
||||||
spyGetToolcachePath.mockImplementation(
|
spyGetToolcachePath.mockImplementation(
|
||||||
(toolname: string, javaVersion: string, architecture: string) => {
|
(toolname: string, javaVersion: string, architecture: string) => {
|
||||||
|
@ -134,10 +134,10 @@ describe('findInToolcache', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setupJava', () => {
|
describe('setupJava', () => {
|
||||||
const actualJavaVersion = '11.0.8';
|
const actualJavaVersion = '11.0.9';
|
||||||
const installedJavaVersion = '11.0.9';
|
const installedJavaVersion = '11.0.8';
|
||||||
const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x86');
|
const javaPath = path.join('Java_Empty_jdk', installedJavaVersion, 'x86');
|
||||||
const javaPathInstalled = path.join('toolcache', 'Java_Empty_jdk', installedJavaVersion, 'x86');
|
const javaPathInstalled = path.join('toolcache', 'Java_Empty_jdk', actualJavaVersion, 'x86');
|
||||||
|
|
||||||
let mockJavaBase: EmptyJavaBase;
|
let mockJavaBase: EmptyJavaBase;
|
||||||
|
|
||||||
|
@ -159,12 +159,12 @@ describe('setupJava', () => {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
return semver.satisfies(installedJavaVersion, semverVersion) ? javaPath : '';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
|
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
|
||||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
spyTcFindAllVersions.mockReturnValue([installedJavaVersion]);
|
||||||
|
|
||||||
// Spy on core methods
|
// Spy on core methods
|
||||||
spyCoreDebug = jest.spyOn(core, 'debug');
|
spyCoreDebug = jest.spyOn(core, 'debug');
|
||||||
|
@ -192,42 +192,24 @@ describe('setupJava', () => {
|
||||||
it.each([
|
it.each([
|
||||||
[
|
[
|
||||||
{ version: '11', architecture: 'x86', packageType: 'jdk' },
|
{ version: '11', architecture: 'x86', packageType: 'jdk' },
|
||||||
{ version: actualJavaVersion, path: javaPath }
|
{ version: installedJavaVersion, path: javaPath }
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{ version: '11.0', architecture: 'x86', packageType: 'jdk' },
|
{ version: '11.0', architecture: 'x86', packageType: 'jdk' },
|
||||||
{ version: actualJavaVersion, path: javaPath }
|
{ version: installedJavaVersion, path: javaPath }
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk' },
|
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk' },
|
||||||
{ version: actualJavaVersion, path: javaPath }
|
{ version: installedJavaVersion, path: javaPath }
|
||||||
]
|
]
|
||||||
])('should find java locally for %o', (input, expected) => {
|
])('should find java locally for %s', (input, expected) => {
|
||||||
mockJavaBase = new EmptyJavaBase(input);
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||||
});
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${expected.version} from tool-cache`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`)
|
||||||
it.each([
|
expect(spyCoreInfo).not.toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||||
[
|
expect(spyCoreInfo).not.toHaveBeenCalledWith('Trying to download...');
|
||||||
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
|
||||||
{ version: installedJavaVersion, path: javaPathInstalled }
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
|
||||||
{ version: installedJavaVersion, path: javaPathInstalled }
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
|
||||||
{ version: installedJavaVersion, path: javaPathInstalled }
|
|
||||||
]
|
|
||||||
])('should check the latest java version for %o', async (input, expected) => {
|
|
||||||
mockJavaBase = new EmptyJavaBase(input);
|
|
||||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
|
||||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
|
||||||
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve latest version remotely');
|
|
||||||
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
|
|
||||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${installedJavaVersion} was downloaded`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
@ -250,6 +232,50 @@ describe('setupJava', () => {
|
||||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${expected.version} was downloaded`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`)
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[
|
||||||
|
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||||
|
{ version: '11.0.9', path: javaPathInstalled }
|
||||||
|
],
|
||||||
|
])('should check the latest java version for %s and resolve locally', async (input, expected) => {
|
||||||
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
|
mockJavaBase['findInToolcache'] = () => ({ version: '11.0.9', path: expected.path });
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${expected.version} from tool-cache`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`)
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[
|
||||||
|
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||||
|
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||||
|
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||||
|
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||||
|
]
|
||||||
|
])('should check the latest java version for %s and download', async (input, expected) => {
|
||||||
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||||
|
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${actualJavaVersion}`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${actualJavaVersion} was downloaded`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`)
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
|
|
@ -36,17 +36,18 @@ export abstract class JavaBase {
|
||||||
if (foundJava && !this.checkLatest) {
|
if (foundJava && !this.checkLatest) {
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
} else {
|
} else {
|
||||||
core.info('Trying to resolve latest version remotely');
|
core.info('Trying to resolve the latest version from remote');
|
||||||
const javaRelease = await this.findPackageForDownload(this.version);
|
const javaRelease = await this.findPackageForDownload(this.version);
|
||||||
|
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||||
|
core.info(foundJava?.version ?? '');
|
||||||
|
core.info(javaRelease.version ?? '');
|
||||||
|
if (foundJava?.version === javaRelease.version) {
|
||||||
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
|
} else {
|
||||||
core.info('Trying to download...');
|
core.info('Trying to download...');
|
||||||
if (foundJava?.version != javaRelease.version) {
|
|
||||||
foundJava = await this.downloadTool(javaRelease);
|
foundJava = await this.downloadTool(javaRelease);
|
||||||
core.info(`Java ${foundJava.version} was downloaded`);
|
core.info(`Java ${foundJava.version} was downloaded`);
|
||||||
} else {
|
|
||||||
core.info('latest version was resolved locally');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Java ${foundJava.version} was resolved`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue