Skip to content

Commit b61c881

Browse files
committed
Add support for http url in jdkFile
Closes actions#232
1 parent f5cbdad commit b61c881

File tree

7 files changed

+2174
-2078
lines changed

7 files changed

+2174
-2078
lines changed

.github/workflows/e2e-local-file.yml

+36
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,39 @@ jobs:
121121
- name: Verify Java version
122122
run: bash __tests__/verify-java.sh "11.0.12" "${{ steps.setup-java.outputs.path }}"
123123
shell: bash
124+
125+
setup-java-remote-file-temurin:
126+
name: Validate download from remote file Eclipse Temurin
127+
runs-on: ${{ matrix.os }}
128+
strategy:
129+
fail-fast: false
130+
matrix:
131+
os: [macos-latest, windows-latest, ubuntu-latest]
132+
steps:
133+
- name: Checkout
134+
uses: actions/checkout@v2
135+
- name: Download Eclipse Temurin file
136+
run: |
137+
if ($IsLinux) {
138+
$downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz"
139+
$localFilename = "java_package.tar.gz"
140+
} elseif ($IsMacOS) {
141+
$downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_mac_hotspot_11.0.12_7.tar.gz"
142+
$localFilename = "java_package.tar.gz"
143+
} elseif ($IsWindows) {
144+
$downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_windows_hotspot_11.0.12_7.zip"
145+
$localFilename = "java_package.zip"
146+
}
147+
echo "DownloadUrl=$downloadUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
148+
shell: pwsh
149+
- name: setup-java
150+
uses: ./
151+
id: setup-java
152+
with:
153+
distribution: 'jdkfile'
154+
jdkFile: ${{ env.DownloadUrl }}
155+
java-version: '11.0.0-ea'
156+
architecture: x64
157+
- name: Verify Java version
158+
run: bash __tests__/verify-java.sh "11.0.12" "${{ steps.setup-java.outputs.path }}"
159+
shell: bash

__tests__/distributors/local-installer.test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,36 @@ describe('setupJava', () => {
161161
);
162162
});
163163

164+
it('java is downloaded from remote jdkfile', async () => {
165+
const inputs = {
166+
version: '11.0.289',
167+
architecture: 'x86',
168+
packageType: 'jdk',
169+
checkLatest: false
170+
};
171+
const expected = {
172+
version: '11.0.289',
173+
path: path.join('Java_jdkfile_jdk', inputs.version, inputs.architecture)
174+
};
175+
176+
const jdkFile = 'https://example.com/jdk.tar.gz';
177+
178+
const spyTcDownloadTool = jest.spyOn(tc, 'downloadTool');
179+
spyTcDownloadTool.mockReturnValue(Promise.resolve(expectedJdkFile));
180+
181+
mockJavaBase = new LocalDistribution(inputs, jdkFile);
182+
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
183+
expect(spyTcFindAllVersions).toHaveBeenCalled();
184+
expect(spyTcDownloadTool).toHaveBeenCalledWith(jdkFile);
185+
expect(spyCoreInfo).not.toHaveBeenCalledWith(
186+
`Resolved Java ${actualJavaVersion} from tool-cache`
187+
);
188+
expect(spyCoreInfo).toHaveBeenCalledWith(`Extracting Java from '${expectedJdkFile}'`);
189+
expect(spyCoreInfo).toHaveBeenCalledWith(
190+
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
191+
);
192+
});
193+
164194
it('jdk file is not found', async () => {
165195
const inputs = {
166196
version: '11.0.289',

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inputs:
1818
required: false
1919
default: 'x64'
2020
jdkFile:
21-
description: 'Path to where the compressed JDK is located'
21+
description: 'Path to where the compressed JDK is located, or URL where it should be downloaded from'
2222
required: false
2323
check-latest:
2424
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'

0 commit comments

Comments
 (0)