mirror of
https://github.com/actions/setup-java.git
synced 2024-08-26 14:17:20 -04:00
Add support for multiple jdks (#368)
This commit is contained in:
parent
749e4491fa
commit
d854b6da19
15 changed files with 4218 additions and 3568 deletions
37
.github/workflows/e2e-versions.yml
vendored
37
.github/workflows/e2e-versions.yml
vendored
|
@ -87,6 +87,43 @@ jobs:
|
|||
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
||||
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:
|
||||
name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
||||
needs: setup-java-major-minor-versions
|
||||
|
|
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
21
README.md
21
README.md
|
@ -158,25 +158,18 @@ jobs:
|
|||
```
|
||||
|
||||
### 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
|
||||
steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: 8
|
||||
- run: echo "JAVA_8=$JAVA_HOME" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
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
|
||||
java-version: |
|
||||
8
|
||||
11
|
||||
15
|
||||
```
|
||||
|
||||
### Advanced
|
||||
|
|
|
@ -244,6 +244,10 @@ describe('setupJava', () => {
|
|||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
`JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`,
|
||||
expected.path
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
|
||||
|
|
2045
dist/cleanup/index.js
vendored
2045
dist/cleanup/index.js
vendored
File diff suppressed because it is too large
Load diff
2105
dist/setup/index.js
vendored
2105
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
3505
package-lock.json
generated
3505
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -25,7 +25,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.0.0",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/core": "^1.9.0",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/glob": "^0.2.0",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
|
@ -38,9 +38,9 @@
|
|||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.25",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.5",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"prettier": "^1.19.1",
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.2.3"
|
||||
|
|
|
@ -93,7 +93,9 @@ export class AdoptDistribution extends JavaBase {
|
|||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('adopt-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('adopt-retrieve-available-versions');
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
|
|
@ -142,10 +142,12 @@ export abstract class JavaBase {
|
|||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
const majorVerssion = version.split('.')[0];
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
core.exportVariable(`JAVA_HOME_${majorVerssion}_${this.architecture.toUpperCase()}`, toolPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,9 @@ export class CorrettoDistribution extends JavaBase {
|
|||
const arch = this.architecture;
|
||||
const imageType = this.packageType;
|
||||
|
||||
console.time('coretto-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('coretto-retrieve-available-versions');
|
||||
}
|
||||
|
||||
const availableVersionsUrl =
|
||||
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json';
|
||||
|
|
|
@ -66,7 +66,9 @@ export class LibericaDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<LibericaVersion[]> {
|
||||
console.time('liberica-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('liberica-retrieve-available-versions');
|
||||
}
|
||||
const url = this.prepareAvailableVersionsUrl();
|
||||
|
||||
if (core.isDebug()) {
|
||||
|
|
|
@ -91,7 +91,9 @@ export class TemurinDistribution extends JavaBase {
|
|||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('temurin-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('temurin-retrieve-available-versions');
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
|
|
@ -90,7 +90,9 @@ export class ZuluDistribution extends JavaBase {
|
|||
const javafx = features?.includes('fx') ?? false;
|
||||
const releaseStatus = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('azul-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('azul-retrieve-available-versions');
|
||||
}
|
||||
const requestArguments = [
|
||||
`os=${platform}`,
|
||||
`ext=${extension}`,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { JavaInstallerOptions } from './distributions/base-models';
|
|||
|
||||
async function run() {
|
||||
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 architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
|
@ -17,27 +17,30 @@ async function run() {
|
|||
const cache = core.getInput(constants.INPUT_CACHE);
|
||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version,
|
||||
checkLatest
|
||||
};
|
||||
core.startGroup('Installed distributions');
|
||||
for (const version of versions) {
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version,
|
||||
checkLatest
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||
|
||||
|
|
Loading…
Reference in a new issue