resolving comment

This commit is contained in:
Dmitry Shibanov 2022-09-19 17:16:32 +02:00
parent 4e8be27276
commit 7f8371344e
4 changed files with 79 additions and 19 deletions

View File

@ -1,6 +1,7 @@
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
import * as tc from '@actions/tool-cache';
import data from '../../versions-manifest.json';
import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json';
import * as httpm from '@actions/http-client';
import * as core from '@actions/core';
describe('findPackageForDownload', () => {
@ -16,9 +17,11 @@ describe('findPackageForDownload', () => {
checkLatest: false
});
spyGetManifestFromRepo = jest.spyOn(tc, 'getManifestFromRepo');
spyGetManifestFromRepo.mockImplementation(() => {
return data;
spyGetManifestFromRepo = jest.spyOn(httpm.HttpClient.prototype, 'getJson');
spyGetManifestFromRepo.mockReturnValue({
result: JSON.stringify(data),
statusCode: 200,
headers: {}
});
spyDebug = jest.spyOn(core, 'debug');

34
dist/setup/index.js vendored
View File

@ -104456,8 +104456,38 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
// TODO get these dynamically!
// We will need Microsoft to add an endpoint where we can query for versions.
const token = core.getInput('token');
const manifest = yield tc.getManifestFromRepo('dmitry-shibanov', 'setup-java', token, 'add-json-for-microsoft-versions');
return manifest;
const owner = 'dmitry-shibanov';
const repository = 'setup-java';
const branch = 'add-json-for-microsoft-versions';
const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json';
let releases = [];
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
const headers = {
authorization: token,
accept: 'application/vnd.github.VERSION.raw'
};
let response = null;
try {
response = yield this.http.getJson(fileUrl, headers);
if (!response.result) {
return null;
}
}
catch (err) {
core.debug(`Http request for microsoft-openjdk-versions.json failed with status code: ${response === null || response === void 0 ? void 0 : response.statusCode}`);
return null;
}
let versionsRaw = response.result;
if (versionsRaw) {
versionsRaw = versionsRaw.replace(/^\uFEFF/, '');
try {
releases = JSON.parse(versionsRaw);
}
catch (_a) {
core.debug('Invalid json');
}
}
return releases;
});
}
}

View File

@ -3,14 +3,10 @@ import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import { OutgoingHttpHeaders } from 'http';
import fs from 'fs';
import path from 'path';
export interface IToolRelease {
version: string;
stable: boolean;
files: tc.IToolReleaseFile[];
}
import { ITypedResponse } from '@actions/http-client/interfaces';
export class MicrosoftDistributions extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
@ -76,13 +72,44 @@ export class MicrosoftDistributions extends JavaBase {
// TODO get these dynamically!
// We will need Microsoft to add an endpoint where we can query for versions.
const token = core.getInput('token');
const manifest = await tc.getManifestFromRepo(
'dmitry-shibanov',
'setup-java',
token,
'add-json-for-microsoft-versions'
);
const owner = 'dmitry-shibanov';
const repository = 'setup-java';
const branch = 'add-json-for-microsoft-versions';
const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json';
return manifest;
let releases: tc.IToolRelease[] = [];
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
const headers: OutgoingHttpHeaders = {
authorization: token,
accept: 'application/vnd.github.VERSION.raw'
};
let response: ITypedResponse<string> | null = null;
try {
response = await this.http.getJson<string>(fileUrl, headers);
if (!response.result) {
return null;
}
} catch (err) {
core.debug(
`Http request for microsoft-openjdk-versions.json failed with status code: ${response?.statusCode}`
);
return null;
}
let versionsRaw = response.result;
if (versionsRaw) {
versionsRaw = versionsRaw.replace(/^\uFEFF/, '');
try {
releases = JSON.parse(versionsRaw);
} catch {
core.debug('Invalid json');
}
}
return releases;
}
}