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:
Gregory Mitchell 2024-10-13 20:23:43 -05:00
parent 28233e2fcb
commit 53d9f2a017
No known key found for this signature in database
GPG key ID: 771A6C995A086B84
4 changed files with 4355 additions and 4342 deletions

View file

@ -1,8 +1,6 @@
import https from 'https';
import {HttpClient} from '@actions/http-client'; import {HttpClient} from '@actions/http-client';
import os from 'os';
import fs from 'fs';
import {JetBrainsDistribution} from '../../src/distributions/jetbrains/installer'; import {JetBrainsDistribution} from '../../src/distributions/jetbrains/installer';
import {JavaInstallerOptions} from '../../src/distributions/base-models';
import manifestData from '../data/jetbrains.json'; import manifestData from '../data/jetbrains.json';
@ -64,28 +62,48 @@ describe('findPackageForDownload', () => {
['21', '21.0.3+465.3'], ['21', '21.0.3+465.3'],
['x', '21.0.3+465.3'] ['x', '21.0.3+465.3']
])('version is resolved correctly %s -> %s', async (input, expected) => { ])('version is resolved correctly %s -> %s', async (input, expected) => {
const distribution = new JetBrainsDistribution( const distribution = new JetBrainsDistribution({
{
version: input, version: input,
architecture: 'x64', architecture: 'x64',
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}, });
);
distribution['getAvailableVersions'] = async () => manifestData as any; distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input); const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected); expect(resolvedVersion.version).toBe(expected);
}); });
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 () => { it('version is not found', async () => {
const distribution = new JetBrainsDistribution( const distribution = new JetBrainsDistribution({
{
version: '8.0.452', version: '8.0.452',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}, });
);
distribution['getAvailableVersions'] = async () => manifestData as any; distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('8.x')).rejects.toThrow( await expect(distribution['findPackageForDownload']('8.x')).rejects.toThrow(
/Could not find satisfied version for SemVer */ /Could not find satisfied version for SemVer */
@ -93,14 +111,12 @@ describe('findPackageForDownload', () => {
}); });
it('version list is empty', async () => { it('version list is empty', async () => {
const distribution = new JetBrainsDistribution( const distribution = new JetBrainsDistribution({
{
version: '8', version: '8',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}, });
);
distribution['getAvailableVersions'] = async () => []; distribution['getAvailableVersions'] = async () => [];
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow( await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
/Could not find satisfied version for SemVer */ /Could not find satisfied version for SemVer */

8600
dist/setup/index.js vendored

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,7 @@ import {OracleDistribution} from './oracle/installer';
import {DragonwellDistribution} from './dragonwell/installer'; import {DragonwellDistribution} from './dragonwell/installer';
import {SapMachineDistribution} from './sapmachine/installer'; import {SapMachineDistribution} from './sapmachine/installer';
import {GraalVMDistribution} from './graalvm/installer'; import {GraalVMDistribution} from './graalvm/installer';
import {JetBrainsDistribution} from "./jetbrains/installer"; import {JetBrainsDistribution} from './jetbrains/installer';
enum JavaDistribution { enum JavaDistribution {
Adopt = 'adopt', Adopt = 'adopt',

View file

@ -12,11 +12,8 @@ import {
JavaInstallerOptions, JavaInstallerOptions,
JavaInstallerResults JavaInstallerResults
} from '../base-models'; } from '../base-models';
import { import {extractJdkFile, isVersionSatisfies} from '../../util';
extractJdkFile, import {OutgoingHttpHeaders} from 'http';
isVersionSatisfies
} from '../../util';
import {IncomingHttpHeaders, OutgoingHttpHeaders} from "http";
export class JetBrainsDistribution extends JavaBase { export class JetBrainsDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) { constructor(installerOptions: JavaInstallerOptions) {
@ -46,7 +43,9 @@ export class JetBrainsDistribution extends JavaBase {
const resolvedFullVersion = const resolvedFullVersion =
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null; satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
if (!resolvedFullVersion) { if (!resolvedFullVersion) {
const availableOptions = versionsRaw.map(item => item.tag_name).join(', '); const availableOptions = versionsRaw
.map(item => item.tag_name)
.join(', ');
const availableOptionsMessage = availableOptions const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
@ -68,7 +67,7 @@ export class JetBrainsDistribution extends JavaBase {
const javaArchivePath = await tc.downloadTool(javaRelease.url); const javaArchivePath = await tc.downloadTool(javaRelease.url);
core.info(`Extracting Java archive...`); 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 archiveName = fs.readdirSync(extractedJavaPath)[0];
const archivePath = path.join(extractedJavaPath, archiveName); const archivePath = path.join(extractedJavaPath, archiveName);
@ -98,7 +97,7 @@ export class JetBrainsDistribution extends JavaBase {
const rawVersions: IJetBrainsRawVersion[] = []; const rawVersions: IJetBrainsRawVersion[] = [];
while (true) { while (true) {
const requestArguments = `per_page=100&page=${page_index}`; const requestArguments = `per_page=100&page=${page_index}`;
const requestHeaders: OutgoingHttpHeaders = {} const requestHeaders: OutgoingHttpHeaders = {};
if (process.env.GITHUB_TOKEN) { if (process.env.GITHUB_TOKEN) {
requestHeaders['Authorization'] = `Bearer ${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) { if (core.isDebug() && page_index === 1) {
// url is identical except page_index so print it once for debug // url is identical except page_index so print it once for debug
core.debug( core.debug(`Gathering available versions from '${rawUrl}'`);
`Gathering available versions from '${rawUrl}'`
);
} }
const paginationPage = ( const paginationPage = (
await this.http.getJson<IJetBrainsRawVersion[]>( await this.http.getJson<IJetBrainsRawVersion[]>(rawUrl, requestHeaders)
rawUrl, requestHeaders
)
).result; ).result;
if (!paginationPage || paginationPage.length === 0) { if (!paginationPage || paginationPage.length === 0) {
// break infinity loop because we have reached end of pagination // 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, '.'); vstring = tag.substring(2).replace(/-/g, '').replace(/_/g, '.');
break; break;
case undefined: // 0 case undefined: // 0
vstring = tag.substring(3) vstring = tag.substring(3);
break; break;
default: default:
throw new Error(`Unrecognized tag_name: ${tag}`) throw new Error(`Unrecognized tag_name: ${tag}`);
} }
const vsplit = vstring.split('b'); const vsplit = vstring.split('b');
const semver = vsplit[0].replace(/_/g, '.'); const semver = vsplit[0];
const build = +vsplit[1]; const build = +vsplit[1];
// Construct URL // Construct URL