Skip to content

Commit d854b6d

Browse files
Add support for multiple jdks (actions#368)
1 parent 749e449 commit d854b6d

File tree

15 files changed

+5110
-4460
lines changed

15 files changed

+5110
-4460
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,43 @@ jobs:
8787
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
8888
shell: bash
8989

90+
setup-java-multiple-jdks:
91+
name: ${{ matrix.distribution }} ${{ matrix.version }} - multiple jdks - ${{ matrix.os }}
92+
needs: setup-java-major-versions
93+
runs-on: ${{ matrix.os }}
94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
os: [macos-latest, windows-latest, ubuntu-latest]
98+
distribution: ['temurin', 'zulu', 'liberica']
99+
steps:
100+
- name: Checkout
101+
uses: actions/checkout@v3
102+
- name: setup-java
103+
uses: ./
104+
id: setup-java
105+
with:
106+
distribution: ${{ matrix.distribution }}
107+
java-version: |
108+
11
109+
17
110+
- name: Verify Java env variables
111+
run: |
112+
$versionsArr = "11","17"
113+
foreach ($version in $versionsArr)
114+
{
115+
$envName = "JAVA_HOME_${version}_${env:RUNNER_ARCH}"
116+
$JavaVersionPath = [Environment]::GetEnvironmentVariable($envName)
117+
if (-not (Test-Path "$JavaVersionPath")) {
118+
Write-Host "$envName is not found"
119+
exit 1
120+
}
121+
}
122+
shell: pwsh
123+
- name: Verify Java
124+
run: bash __tests__/verify-java.sh "17" "${{ steps.setup-java.outputs.path }}"
125+
shell: bash
126+
90127
setup-java-ea-versions-zulu:
91128
name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
92129
needs: setup-java-major-minor-versions

.licenses/npm/@actions/core.dep.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,18 @@ jobs:
158158
```
159159

160160
### Install multiple JDKs
161+
162+
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 }}'.
163+
161164
```yaml
162165
steps:
163166
- uses: actions/setup-java@v3
164167
with:
165168
distribution: '<distribution>'
166-
java-version: 8
167-
- run: echo "JAVA_8=$JAVA_HOME" >> $GITHUB_ENV
168-
169-
- uses: actions/setup-java@v3
170-
with:
171-
distribution: '<distribution>'
172-
java-version: 11
173-
- run: echo "JAVA_11=$JAVA_HOME" >> $GITHUB_ENV
174-
175-
- uses: actions/setup-java@v3
176-
with:
177-
distribution: '<distribution>'
178-
java-version: 15
179-
- run: echo "JAVA_15=$JAVA_HOME" >> $GITHUB_ENV
169+
java-version: |
170+
8
171+
11
172+
15
180173
```
181174

182175
### Advanced

__tests__/distributors/base-installer.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ describe('setupJava', () => {
244244
expect(spyGetToolcachePath).toHaveBeenCalled();
245245
expect(spyCoreAddPath).toHaveBeenCalled();
246246
expect(spyCoreExportVariable).toHaveBeenCalled();
247+
expect(spyCoreExportVariable).toHaveBeenCalledWith(
248+
`JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`,
249+
expected.path
250+
);
247251
expect(spyCoreSetOutput).toHaveBeenCalled();
248252
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
249253
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);

0 commit comments

Comments
 (0)