Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('installer tests', () => {
}
}, 100000);

it('Acquires version of Java if no matching version is installed', async () => {
it('Installs version of Java from jdkFile if no matching version is installed', async () => {
await installer.getJava('12', 'x64', javaFilePath);
const JavaDir = path.join(toolDir, 'Java', '12.0.0', 'x64');

Expand All @@ -69,6 +69,24 @@ describe('installer tests', () => {
expect(thrown).toBe(true);
});

it('Downloads java if no file given', async () => {
await installer.getJava('8.0.102', 'x64', '');
const JavaDir = path.join(toolDir, 'Java', '8.0.102', 'x64');

expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000);

it('Throws if invalid directory to jdk', async () => {
let thrown = false;
try {
await installer.getJava('1000', 'x64', 'bad path');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});

it('Uses version of Java installed in cache', async () => {
const JavaDir: string = path.join(toolDir, 'Java', '250.0.0', 'x64');
await io.mkdirP(JavaDir);
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Setup your runner with Java'
author: 'GitHub'
inputs:
version:
description: 'A number that specifies the JDK version to make available on the path. Use a whole number version, such as 10'
description: 'The JDK version to make available on the path. Use a whole version, such as 9.0.4'
required: true
architecture:
description: 'The architecture (x86, x64) of the JDK.'
Expand Down
52 changes: 47 additions & 5 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const exec = __importStar(require("@actions/exec"));
const tc = __importStar(require("@actions/tool-cache"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const httpm = __importStar(require("typed-rest-client/HttpClient"));
const IS_WINDOWS = process.platform === 'win32';
if (!tempDirectory) {
let baseLocation;
Expand All @@ -46,15 +47,20 @@ function getJava(version, arch, jdkFile) {
core.debug(`Tool found in cache ${toolPath}`);
}
else {
let compressedFileExtension = '';
if (!jdkFile) {
throw new Error(`Failed to find Java ${version} in the cache. Please specify a valid jdk file to install from instead.`);
core.debug('Downloading Jdk from Azul');
jdkFile = yield downloadJava(version);
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
}
core.debug('Retrieving Jdk from local path');
const compressedFileExtension = getFileEnding(jdkFile);
else {
core.debug('Retrieving Jdk from local path');
}
compressedFileExtension = compressedFileExtension || getFileEnding(jdkFile);
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
core.debug(`jdk extracted to ${jdkDir}`);
toolPath = yield tc.cacheDir(jdkDir, 'Java', `${version}.0.0`, arch);
toolPath = yield tc.cacheDir(jdkDir, 'Java', normalizeVersion(version), arch);
}
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
core.exportVariable('JAVA_HOME', toolPath);
Expand All @@ -63,6 +69,13 @@ function getJava(version, arch, jdkFile) {
});
}
exports.getJava = getJava;
function normalizeVersion(version) {
const versionArray = version.split('.');
const major = versionArray[0];
const minor = versionArray.length > 1 ? versionArray[1] : '0';
const patch = versionArray.length > 2 ? versionArray[2] : '0';
return `${major}.${minor}.${patch}`;
}
function getFileEnding(file) {
let fileEnding = '';
if (file.endsWith('.tar')) {
Expand Down Expand Up @@ -126,7 +139,7 @@ function unpackJars(fsPath, javaBinPath) {
}
});
}
function unzipJavaDownload(repoRoot, fileEnding, destinationFolder) {
function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) {
return __awaiter(this, void 0, void 0, function* () {
// Create the destination folder if it doesn't exist
yield io.mkdirP(destinationFolder);
Expand All @@ -143,3 +156,32 @@ function unzipJavaDownload(repoRoot, fileEnding, destinationFolder) {
}
});
}
function downloadJava(version) {
return __awaiter(this, void 0, void 0, function* () {
let filterString = '';
if (IS_WINDOWS) {
filterString = `jdk${version}-win_x64.zip`;
}
else {
if (process.platform === 'darwin') {
filterString = `jdk${version}-macosx_x64.tar.gz`;
}
else {
filterString = `jdk${version}-linux_x64.tar.gz`;
}
}
let http = new httpm.HttpClient('setup-java');
let contents = yield (yield http.get('https://static.azul.com/zulu/bin/')).readBody();
let refs = contents.match(/<a href.*\">/gi) || [];
refs = refs.filter(val => {
if (val.indexOf(filterString) > -1) {
return true;
}
});
if (refs.length == 0) {
throw new Error(`No valid download found for version ${version}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`);
}
const fileName = refs[0].slice('<a href="'.length, refs[0].length - '">'.length);
return yield tc.downloadTool(`https://static.azul.com/zulu/bin/${fileName}`);
});
}
24 changes: 24 additions & 0 deletions node_modules/@actions/core/lib/core.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions node_modules/@actions/core/lib/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/@actions/core/lib/core.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions node_modules/@actions/core/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions node_modules/@actions/exec/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions node_modules/@actions/exit/LICENSE.md

This file was deleted.

7 changes: 0 additions & 7 deletions node_modules/@actions/exit/README.md

This file was deleted.

29 changes: 0 additions & 29 deletions node_modules/@actions/exit/lib/exit.d.ts

This file was deleted.

Loading