Add support for multiple jdks (#368)

This commit is contained in:
Dmitry Shibanov 2022-09-08 15:26:54 +02:00 committed by GitHub
parent 749e4491fa
commit d854b6da19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 4218 additions and 3568 deletions

View File

@ -87,6 +87,43 @@ jobs:
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}" run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
shell: bash shell: bash
setup-java-multiple-jdks:
name: ${{ matrix.distribution }} ${{ matrix.version }} - multiple jdks - ${{ matrix.os }}
needs: setup-java-major-versions
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
distribution: ['temurin', 'zulu', 'liberica']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version: |
11
17
- name: Verify Java env variables
run: |
$versionsArr = "11","17"
foreach ($version in $versionsArr)
{
$envName = "JAVA_HOME_${version}_${env:RUNNER_ARCH}"
$JavaVersionPath = [Environment]::GetEnvironmentVariable($envName)
if (-not (Test-Path "$JavaVersionPath")) {
Write-Host "$envName is not found"
exit 1
}
}
shell: pwsh
- name: Verify Java
run: bash __tests__/verify-java.sh "17" "${{ steps.setup-java.outputs.path }}"
shell: bash
setup-java-ea-versions-zulu: setup-java-ea-versions-zulu:
name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }} name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
needs: setup-java-major-minor-versions needs: setup-java-major-minor-versions

Binary file not shown.

View File

@ -158,25 +158,18 @@ jobs:
``` ```
### Install multiple JDKs ### Install multiple JDKs
All versions are added to the PATH. The last version will be used and available globally. Other Java versions can be accessed through env variables with such specification as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'.
```yaml ```yaml
steps: steps:
- uses: actions/setup-java@v3 - uses: actions/setup-java@v3
with: with:
distribution: '<distribution>' distribution: '<distribution>'
java-version: 8 java-version: |
- run: echo "JAVA_8=$JAVA_HOME" >> $GITHUB_ENV 8
11
- uses: actions/setup-java@v3 15
with:
distribution: '<distribution>'
java-version: 11
- run: echo "JAVA_11=$JAVA_HOME" >> $GITHUB_ENV
- uses: actions/setup-java@v3
with:
distribution: '<distribution>'
java-version: 15
- run: echo "JAVA_15=$JAVA_HOME" >> $GITHUB_ENV
``` ```
### Advanced ### Advanced

View File

@ -244,6 +244,10 @@ describe('setupJava', () => {
expect(spyGetToolcachePath).toHaveBeenCalled(); expect(spyGetToolcachePath).toHaveBeenCalled();
expect(spyCoreAddPath).toHaveBeenCalled(); expect(spyCoreAddPath).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalled(); expect(spyCoreExportVariable).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalledWith(
`JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`,
expected.path
);
expect(spyCoreSetOutput).toHaveBeenCalled(); expect(spyCoreSetOutput).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote'); expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`); expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);

2045
dist/cleanup/index.js vendored

File diff suppressed because it is too large Load Diff

2063
dist/setup/index.js vendored

File diff suppressed because it is too large Load Diff

3505
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^3.0.0", "@actions/cache": "^3.0.0",
"@actions/core": "^1.2.6", "@actions/core": "^1.9.0",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.0.4",
"@actions/glob": "^0.2.0", "@actions/glob": "^0.2.0",
"@actions/http-client": "^1.0.11", "@actions/http-client": "^1.0.11",
@ -38,9 +38,9 @@
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^7.3.4", "@types/semver": "^7.3.4",
"@vercel/ncc": "^0.33.4",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.5", "jest-circus": "^27.2.5",
"@vercel/ncc": "^0.33.4",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"typescript": "^4.2.3" "typescript": "^4.2.3"

View File

@ -93,7 +93,9 @@ export class AdoptDistribution extends JavaBase {
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
const releaseType = this.stable ? 'ga' : 'ea'; const releaseType = this.stable ? 'ga' : 'ea';
if (core.isDebug()) {
console.time('adopt-retrieve-available-versions'); console.time('adopt-retrieve-available-versions');
}
const baseRequestArguments = [ const baseRequestArguments = [
`project=jdk`, `project=jdk`,

View File

@ -142,10 +142,12 @@ export abstract class JavaBase {
} }
protected setJavaDefault(version: string, toolPath: string) { protected setJavaDefault(version: string, toolPath: string) {
const majorVerssion = version.split('.')[0];
core.exportVariable('JAVA_HOME', toolPath); core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path.join(toolPath, 'bin')); core.addPath(path.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution); core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath); core.setOutput('path', toolPath);
core.setOutput('version', version); core.setOutput('version', version);
core.exportVariable(`JAVA_HOME_${majorVerssion}_${this.architecture.toUpperCase()}`, toolPath);
} }
} }

View File

@ -71,7 +71,9 @@ export class CorrettoDistribution extends JavaBase {
const arch = this.architecture; const arch = this.architecture;
const imageType = this.packageType; const imageType = this.packageType;
if (core.isDebug()) {
console.time('coretto-retrieve-available-versions'); console.time('coretto-retrieve-available-versions');
}
const availableVersionsUrl = const availableVersionsUrl =
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'; 'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json';

View File

@ -66,7 +66,9 @@ export class LibericaDistributions extends JavaBase {
} }
private async getAvailableVersions(): Promise<LibericaVersion[]> { private async getAvailableVersions(): Promise<LibericaVersion[]> {
if (core.isDebug()) {
console.time('liberica-retrieve-available-versions'); console.time('liberica-retrieve-available-versions');
}
const url = this.prepareAvailableVersionsUrl(); const url = this.prepareAvailableVersionsUrl();
if (core.isDebug()) { if (core.isDebug()) {

View File

@ -91,7 +91,9 @@ export class TemurinDistribution extends JavaBase {
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
const releaseType = this.stable ? 'ga' : 'ea'; const releaseType = this.stable ? 'ga' : 'ea';
if (core.isDebug()) {
console.time('temurin-retrieve-available-versions'); console.time('temurin-retrieve-available-versions');
}
const baseRequestArguments = [ const baseRequestArguments = [
`project=jdk`, `project=jdk`,

View File

@ -90,7 +90,9 @@ export class ZuluDistribution extends JavaBase {
const javafx = features?.includes('fx') ?? false; const javafx = features?.includes('fx') ?? false;
const releaseStatus = this.stable ? 'ga' : 'ea'; const releaseStatus = this.stable ? 'ga' : 'ea';
if (core.isDebug()) {
console.time('azul-retrieve-available-versions'); console.time('azul-retrieve-available-versions');
}
const requestArguments = [ const requestArguments = [
`os=${platform}`, `os=${platform}`,
`ext=${extension}`, `ext=${extension}`,

View File

@ -9,7 +9,7 @@ import { JavaInstallerOptions } from './distributions/base-models';
async function run() { async function run() {
try { try {
const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION, { required: true });
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true });
const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
@ -17,6 +17,8 @@ async function run() {
const cache = core.getInput(constants.INPUT_CACHE); const cache = core.getInput(constants.INPUT_CACHE);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false); const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
core.startGroup('Installed distributions');
for (const version of versions) {
const installerOptions: JavaInstallerOptions = { const installerOptions: JavaInstallerOptions = {
architecture, architecture,
packageType, packageType,
@ -37,7 +39,8 @@ async function run() {
core.info(` Version: ${result.version}`); core.info(` Version: ${result.version}`);
core.info(` Path: ${result.path}`); core.info(` Path: ${result.path}`);
core.info(''); core.info('');
}
core.endGroup();
const matchersPath = path.join(__dirname, '..', '..', '.github'); const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);