mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 01:46:46 +00:00
Updates
This commit is contained in:
parent
dff91e4ff3
commit
204a88328a
3 changed files with 4613 additions and 4349 deletions
|
@ -1,9 +1,9 @@
|
|||
import { HttpClient } from '@actions/http-client';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
|
||||
import { JavaInstallerOptions } from '../../src/distributions/base-models';
|
||||
import { SemeruDistribution } from '../../src/distributions/semeru/installer';
|
||||
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
import {SemeruDistribution} from '../../src/distributions/semeru/installer';
|
||||
|
||||
let manifestData = require('../data/semeru.json') as [];
|
||||
import manifestData from '../data/semeru.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
|
@ -25,26 +25,47 @@ describe('getAvailableVersions', () => {
|
|||
|
||||
it.each([
|
||||
[
|
||||
{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false },
|
||||
{
|
||||
version: '16',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
},
|
||||
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
|
||||
],
|
||||
[
|
||||
{ version: '16', architecture: 'x86', packageType: 'jdk', checkLatest: false },
|
||||
{
|
||||
version: '16',
|
||||
architecture: 'x86',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
},
|
||||
'os=mac&architecture=x86&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
|
||||
],
|
||||
[
|
||||
{ version: '16', architecture: 'x64', packageType: 'jre', checkLatest: false },
|
||||
{
|
||||
version: '16',
|
||||
architecture: 'x64',
|
||||
packageType: 'jre',
|
||||
checkLatest: false
|
||||
},
|
||||
'os=mac&architecture=x64&image_type=jre&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
|
||||
],
|
||||
[
|
||||
{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false },
|
||||
{
|
||||
version: '16',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
},
|
||||
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
|
||||
]
|
||||
])(
|
||||
'build correct url for %s',
|
||||
async (installerOptions: JavaInstallerOptions, expectedParameters) => {
|
||||
const distribution = new SemeruDistribution(installerOptions);
|
||||
const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
|
||||
const baseUrl =
|
||||
'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
|
||||
const expectedUrl = `${baseUrl}?project=jdk&vendor=ibm&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
|
||||
distribution['getPlatformOption'] = () => 'mac';
|
||||
|
||||
|
@ -116,7 +137,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||
expect(resolvedVersion.version).toBe(expected);
|
||||
});
|
||||
|
@ -128,10 +149,10 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
await expect(
|
||||
distribution['findPackageForDownload']('9.0.8')
|
||||
).rejects.toThrow(/Could not find satisfied version for SemVer */);
|
||||
});
|
||||
|
||||
it('version is not found', async () => {
|
||||
|
@ -141,8 +162,8 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
|
@ -155,7 +176,7 @@ describe('findPackageForDownload', () => {
|
|||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => [];
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrowError(
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
|
@ -169,7 +190,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
const resolvedVersion = await distribution['findPackageForDownload']('8');
|
||||
expect(resolvedVersion.version).not.toBeNull();
|
||||
}
|
||||
|
@ -185,7 +206,7 @@ describe('findPackageForDownload', () => {
|
|||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => [];
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrowError(
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||
`Unsupported architecture for IBM Semeru: ${arch}, the following are supported: x64, x86, ppc64le, ppc64, s390x, aarch64`
|
||||
);
|
||||
}
|
||||
|
@ -200,14 +221,26 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](version)
|
||||
).rejects.toThrow(
|
||||
'IBM Semeru does not provide builds for early access versions'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
it.each(['jdk+fx', 'jre+fx', 'test', 'test2', 'jdk-fx', 'javafx', 'jdk-javafx', 'ibm', ' '])(
|
||||
it.each([
|
||||
'jdk+fx',
|
||||
'jre+fx',
|
||||
'test',
|
||||
'test2',
|
||||
'jdk-fx',
|
||||
'javafx',
|
||||
'jdk-javafx',
|
||||
'ibm',
|
||||
' '
|
||||
])(
|
||||
'rejects incorrect `%s` Semeru package type',
|
||||
async (packageType: string) => {
|
||||
const distribution = new SemeruDistribution({
|
||||
|
@ -216,8 +249,8 @@ describe('findPackageForDownload', () => {
|
|||
packageType: packageType,
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrowError(
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||
'IBM Semeru only provide `jdk` and `jre` package types'
|
||||
);
|
||||
}
|
||||
|
@ -232,7 +265,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: packageType,
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
const resolvedVersion = await distribution['findPackageForDownload']('8');
|
||||
await expect(resolvedVersion.version).toMatch(/8[0-9.]+/);
|
||||
}
|
||||
|
@ -247,7 +280,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
})
|
||||
).toThrowError(
|
||||
).toThrow(
|
||||
"The string 'jdk-16.0.2+7_openj9-0.27.1' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information"
|
||||
);
|
||||
});
|
||||
|
|
8789
dist/setup/index.js
vendored
8789
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,38 @@
|
|||
import { JavaBase } from '../base-installer';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import semver from 'semver';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
isVersionSatisfies
|
||||
} from '../../util';
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { ISemeruAvailableVersions } from './models';
|
||||
import {ISemeruAvailableVersions} from './models';
|
||||
|
||||
const supportedArchitectures = ['x64', 'x86', 'ppc64le', 'ppc64', 's390x', 'aarch64'];
|
||||
const supportedArchitectures = [
|
||||
'x64',
|
||||
'x86',
|
||||
'ppc64le',
|
||||
'ppc64',
|
||||
's390x',
|
||||
'aarch64'
|
||||
];
|
||||
|
||||
export class SemeruDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('IBM_Semeru', installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(
|
||||
version: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
if (!supportedArchitectures.includes(this.architecture)) {
|
||||
throw new Error(
|
||||
`Unsupported architecture for IBM Semeru: ${
|
||||
|
@ -25,7 +42,9 @@ export class SemeruDistribution extends JavaBase {
|
|||
}
|
||||
|
||||
if (!this.stable) {
|
||||
throw new Error('IBM Semeru does not provide builds for early access versions');
|
||||
throw new Error(
|
||||
'IBM Semeru does not provide builds for early access versions'
|
||||
);
|
||||
}
|
||||
|
||||
if (this.packageType !== 'jdk' && this.packageType !== 'jre') {
|
||||
|
@ -52,9 +71,12 @@ export class SemeruDistribution extends JavaBase {
|
|||
return -semver.compareBuild(a.version, b.version);
|
||||
});
|
||||
|
||||
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
const resolvedFullVersion =
|
||||
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = availableVersionsWithBinaries.map(item => item.version).join(', ');
|
||||
const availableOptions = availableVersionsWithBinaries
|
||||
.map(item => item.version)
|
||||
.join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
|
@ -66,27 +88,34 @@ export class SemeruDistribution extends JavaBase {
|
|||
return resolvedFullVersion;
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
let javaPath: string;
|
||||
let extractedJavaPath: string;
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
let extension = getDownloadArchiveExtension();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
const extractedJavaPath: string = await extractJdkFile(
|
||||
javaArchivePath,
|
||||
extension
|
||||
);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
javaPath = await tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||
const javaPath: string = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected get toolcacheFolderName(): string {
|
||||
|
@ -100,7 +129,7 @@ export class SemeruDistribution extends JavaBase {
|
|||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('semeru-retrieve-available-versions');
|
||||
console.time('semeru-retrieve-available-versions'); // eslint-disable-line no-console
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
@ -124,7 +153,9 @@ export class SemeruDistribution extends JavaBase {
|
|||
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
||||
if (core.isDebug() && page_index === 0) {
|
||||
// url is identical except page_index so print it once for debug
|
||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||
core.debug(
|
||||
`Gathering available versions from '${availableVersionsUrl}'`
|
||||
);
|
||||
}
|
||||
|
||||
if (core.isDebug()) {
|
||||
|
@ -133,13 +164,14 @@ export class SemeruDistribution extends JavaBase {
|
|||
|
||||
let iTypedResponse = null;
|
||||
try {
|
||||
iTypedResponse = await this.http.getJson<ISemeruAvailableVersions[]>(availableVersionsUrl);
|
||||
iTypedResponse = await this.http.getJson<ISemeruAvailableVersions[]>(
|
||||
availableVersionsUrl
|
||||
);
|
||||
} catch (element) {
|
||||
console.log('error', element);
|
||||
console.log('error', element); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const paginationPage = iTypedResponse.result;
|
||||
const paginationPage = iTypedResponse!.result;
|
||||
if (paginationPage === null || paginationPage.length === 0) {
|
||||
// break infinity loop because we have reached end of pagination
|
||||
break;
|
||||
|
@ -151,10 +183,12 @@ export class SemeruDistribution extends JavaBase {
|
|||
|
||||
if (core.isDebug()) {
|
||||
core.startGroup('Print information about available IBM Semeru versions');
|
||||
console.timeEnd('semeru-retrieve-available-versions');
|
||||
console.log(`Available versions: [${availableVersions.length}]`);
|
||||
console.log(availableVersions.map(item => item.version_data.semver).join(', '));
|
||||
console.log(JSON.stringify(availableVersions));
|
||||
console.timeEnd('semeru-retrieve-available-versions'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(
|
||||
availableVersions.map(item => item.version_data.semver).join(', ')
|
||||
);
|
||||
core.debug(JSON.stringify(availableVersions));
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue