mirror of
https://github.com/actions/setup-java.git
synced 2024-12-01 21:00:56 -05:00
Fix PR Issues
- Fix JDK 11 URL Bug - Add JDK URL Testing to ensure versions can be downloaded - Run Prettier
This commit is contained in:
parent
28233e2fcb
commit
53d9f2a017
4 changed files with 4355 additions and 4342 deletions
|
@ -1,8 +1,6 @@
|
|||
import https from 'https';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
import {JetBrainsDistribution} from '../../src/distributions/jetbrains/installer';
|
||||
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
|
||||
import manifestData from '../data/jetbrains.json';
|
||||
|
||||
|
@ -64,28 +62,48 @@ describe('findPackageForDownload', () => {
|
|||
['21', '21.0.3+465.3'],
|
||||
['x', '21.0.3+465.3']
|
||||
])('version is resolved correctly %s -> %s', async (input, expected) => {
|
||||
const distribution = new JetBrainsDistribution(
|
||||
{
|
||||
version: input,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
},
|
||||
);
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: input,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||
expect(resolvedVersion.version).toBe(expected);
|
||||
});
|
||||
|
||||
it('version is not found', async () => {
|
||||
const distribution = new JetBrainsDistribution(
|
||||
{
|
||||
version: '8.0.452',
|
||||
it.each(['17', '11.0', '11.0.11', '21.0.2', '21'])(
|
||||
'version %s can be downloaded',
|
||||
async input => {
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: input,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
},
|
||||
);
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](
|
||||
input
|
||||
);
|
||||
const url = resolvedVersion.url;
|
||||
const options = {method: 'HEAD'};
|
||||
|
||||
https.request(url, options, res => {
|
||||
// JetBrains uses 403 for inexistent packages
|
||||
expect(res.statusCode).not.toBe(403);
|
||||
res.resume();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
it('version is not found', async () => {
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: '8.0.452',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||
await expect(distribution['findPackageForDownload']('8.x')).rejects.toThrow(
|
||||
/Could not find satisfied version for SemVer */
|
||||
|
@ -93,14 +111,12 @@ describe('findPackageForDownload', () => {
|
|||
});
|
||||
|
||||
it('version list is empty', async () => {
|
||||
const distribution = new JetBrainsDistribution(
|
||||
{
|
||||
version: '8',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
},
|
||||
);
|
||||
const distribution = new JetBrainsDistribution({
|
||||
version: '8',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => [];
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||
/Could not find satisfied version for SemVer */
|
||||
|
|
8600
dist/setup/index.js
vendored
8600
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,7 @@ import {OracleDistribution} from './oracle/installer';
|
|||
import {DragonwellDistribution} from './dragonwell/installer';
|
||||
import {SapMachineDistribution} from './sapmachine/installer';
|
||||
import {GraalVMDistribution} from './graalvm/installer';
|
||||
import {JetBrainsDistribution} from "./jetbrains/installer";
|
||||
import {JetBrainsDistribution} from './jetbrains/installer';
|
||||
|
||||
enum JavaDistribution {
|
||||
Adopt = 'adopt',
|
||||
|
|
|
@ -12,11 +12,8 @@ import {
|
|||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {
|
||||
extractJdkFile,
|
||||
isVersionSatisfies
|
||||
} from '../../util';
|
||||
import {IncomingHttpHeaders, OutgoingHttpHeaders} from "http";
|
||||
import {extractJdkFile, isVersionSatisfies} from '../../util';
|
||||
import {OutgoingHttpHeaders} from 'http';
|
||||
|
||||
export class JetBrainsDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
|
@ -46,7 +43,9 @@ export class JetBrainsDistribution extends JavaBase {
|
|||
const resolvedFullVersion =
|
||||
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = versionsRaw.map(item => item.tag_name).join(', ');
|
||||
const availableOptions = versionsRaw
|
||||
.map(item => item.tag_name)
|
||||
.join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
|
@ -68,7 +67,7 @@ export class JetBrainsDistribution extends JavaBase {
|
|||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, "tar.gz");
|
||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, 'tar.gz');
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
|
@ -98,7 +97,7 @@ export class JetBrainsDistribution extends JavaBase {
|
|||
const rawVersions: IJetBrainsRawVersion[] = [];
|
||||
while (true) {
|
||||
const requestArguments = `per_page=100&page=${page_index}`;
|
||||
const requestHeaders: OutgoingHttpHeaders = {}
|
||||
const requestHeaders: OutgoingHttpHeaders = {};
|
||||
|
||||
if (process.env.GITHUB_TOKEN) {
|
||||
requestHeaders['Authorization'] = `Bearer ${process.env.GITHUB_TOKEN}`;
|
||||
|
@ -108,15 +107,11 @@ export class JetBrainsDistribution extends JavaBase {
|
|||
|
||||
if (core.isDebug() && page_index === 1) {
|
||||
// url is identical except page_index so print it once for debug
|
||||
core.debug(
|
||||
`Gathering available versions from '${rawUrl}'`
|
||||
);
|
||||
core.debug(`Gathering available versions from '${rawUrl}'`);
|
||||
}
|
||||
|
||||
const paginationPage = (
|
||||
await this.http.getJson<IJetBrainsRawVersion[]>(
|
||||
rawUrl, requestHeaders
|
||||
)
|
||||
await this.http.getJson<IJetBrainsRawVersion[]>(rawUrl, requestHeaders)
|
||||
).result;
|
||||
if (!paginationPage || paginationPage.length === 0) {
|
||||
// break infinity loop because we have reached end of pagination
|
||||
|
@ -145,14 +140,14 @@ export class JetBrainsDistribution extends JavaBase {
|
|||
vstring = tag.substring(2).replace(/-/g, '').replace(/_/g, '.');
|
||||
break;
|
||||
case undefined: // 0
|
||||
vstring = tag.substring(3)
|
||||
vstring = tag.substring(3);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unrecognized tag_name: ${tag}`)
|
||||
throw new Error(`Unrecognized tag_name: ${tag}`);
|
||||
}
|
||||
|
||||
const vsplit = vstring.split('b');
|
||||
const semver = vsplit[0].replace(/_/g, '.');
|
||||
const semver = vsplit[0];
|
||||
const build = +vsplit[1];
|
||||
|
||||
// Construct URL
|
||||
|
|
Loading…
Reference in a new issue