mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
resolving comment
This commit is contained in:
parent
4e8be27276
commit
7f8371344e
4 changed files with 79 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
|
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
|
||||||
import * as tc from '@actions/tool-cache';
|
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';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
|
@ -16,9 +17,11 @@ describe('findPackageForDownload', () => {
|
||||||
checkLatest: false
|
checkLatest: false
|
||||||
});
|
});
|
||||||
|
|
||||||
spyGetManifestFromRepo = jest.spyOn(tc, 'getManifestFromRepo');
|
spyGetManifestFromRepo = jest.spyOn(httpm.HttpClient.prototype, 'getJson');
|
||||||
spyGetManifestFromRepo.mockImplementation(() => {
|
spyGetManifestFromRepo.mockReturnValue({
|
||||||
return data;
|
result: JSON.stringify(data),
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
spyDebug = jest.spyOn(core, 'debug');
|
spyDebug = jest.spyOn(core, 'debug');
|
||||||
|
|
34
dist/setup/index.js
vendored
34
dist/setup/index.js
vendored
|
@ -104456,8 +104456,38 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
|
||||||
// TODO get these dynamically!
|
// TODO get these dynamically!
|
||||||
// We will need Microsoft to add an endpoint where we can query for versions.
|
// We will need Microsoft to add an endpoint where we can query for versions.
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
const manifest = yield tc.getManifestFromRepo('dmitry-shibanov', 'setup-java', token, 'add-json-for-microsoft-versions');
|
const owner = 'dmitry-shibanov';
|
||||||
return manifest;
|
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,10 @@ import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from
|
||||||
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
|
import { OutgoingHttpHeaders } from 'http';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { ITypedResponse } from '@actions/http-client/interfaces';
|
||||||
export interface IToolRelease {
|
|
||||||
version: string;
|
|
||||||
stable: boolean;
|
|
||||||
files: tc.IToolReleaseFile[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MicrosoftDistributions extends JavaBase {
|
export class MicrosoftDistributions extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
|
@ -76,13 +72,44 @@ export class MicrosoftDistributions extends JavaBase {
|
||||||
// TODO get these dynamically!
|
// TODO get these dynamically!
|
||||||
// We will need Microsoft to add an endpoint where we can query for versions.
|
// We will need Microsoft to add an endpoint where we can query for versions.
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
const manifest = await tc.getManifestFromRepo(
|
const owner = 'dmitry-shibanov';
|
||||||
'dmitry-shibanov',
|
const repository = 'setup-java';
|
||||||
'setup-java',
|
const branch = 'add-json-for-microsoft-versions';
|
||||||
token,
|
const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json';
|
||||||
'add-json-for-microsoft-versions'
|
|
||||||
);
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue