From 37bedf2b883cc64476e03a5c29207adf3af9c8c8 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 14:14:23 +0200 Subject: [PATCH 01/15] add initial logic --- action.yml | 3 + dist/setup/index.js | 70 +++++---- microsoft-build-of-openjdk-versions.json | 176 +++++++++++++++++++++++ src/distributions/microsoft/installer.ts | 91 ++++++------ 4 files changed, 259 insertions(+), 81 deletions(-) create mode 100644 microsoft-build-of-openjdk-versions.json diff --git a/action.yml b/action.yml index ec05f65ab..abcfb6b27 100644 --- a/action.yml +++ b/action.yml @@ -59,6 +59,9 @@ inputs: job-status: description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting' default: ${{ job.status }} + token: + description: Used to pull java versions from setup-java. Since there's a default, this is typically not supplied by the user. + default: ${{ github.token }} outputs: distribution: description: 'Distribution of Java that has been installed' diff --git a/dist/setup/index.js b/dist/setup/index.js index 92cf879e6..2f72b1dec 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102398,7 +102398,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.MicrosoftDistributions = void 0; const base_installer_1 = __nccwpck_require__(9741); -const semver_1 = __importDefault(__nccwpck_require__(1383)); const util_1 = __nccwpck_require__(2629); const core = __importStar(__nccwpck_require__(2186)); const tc = __importStar(__nccwpck_require__(7784)); @@ -102433,49 +102432,44 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); } const availableVersionsRaw = yield this.getAvailableVersions(); - const opts = this.getPlatformOption(); - const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${this.architecture}.${opts.archive}`, - version: this.convertVersionToSemver(item) - })); - const satisfiedVersion = availableVersions - .filter(item => util_1.isVersionSatisfies(range, item.version)) - .sort((a, b) => -semver_1.default.compareBuild(a.version, b.version))[0]; - if (!satisfiedVersion) { - const availableOptions = availableVersions.map(item => item.version).join(', '); - const availableOptionsMessage = availableOptions - ? `\nAvailable versions: ${availableOptions}` - : ''; - throw new Error(`Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`); - } - return satisfiedVersion; + if (!availableVersionsRaw) { + throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); + } + const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw, this.architecture); + // const opts = this.getPlatformOption(); + // const availableVersions = availableVersionsRaw.map(item => ({ + // url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ + // this.architecture // https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz + // }.${opts.archive}`, + // version: this.convertVersionToSemver(item) + // })); + // const satisfiedVersion = availableVersions + // .filter(item => isVersionSatisfies(range, item.version)) + // .sort((a, b) => -semver.compareBuild(a.version, b.version))[0]; + // if (!satisfiedVersion) { + // const availableOptions = availableVersions.map(item => item.version).join(', '); + // const availableOptionsMessage = availableOptions + // ? `\nAvailable versions: ${availableOptions}` + // : ''; + // throw new Error( + // `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}` + // ); + // } + if (!foundRelease) { + throw new Error(`Could not find satisfied version for SemVer ${range}. ${availableVersionsRaw + .map(item => item.version) + .join(', ')}`); + } + return { url: foundRelease.release_url, version: foundRelease.version }; }); } getAvailableVersions() { return __awaiter(this, void 0, void 0, function* () { // TODO get these dynamically! // We will need Microsoft to add an endpoint where we can query for versions. - const jdkVersions = [ - { - version: [17, 0, 3] - }, - { - version: [17, 0, 1, 12, 1] - }, - { - version: [16, 0, 2, 7, 1] - }, - { - version: [11, 0, 15] - } - ]; - // M1 is only supported for Java 16 & 17 - if (process.platform !== 'darwin' || this.architecture !== 'aarch64') { - jdkVersions.push({ - version: [11, 0, 13, 8, 1] - }); - } - return jdkVersions; + const token = core.getInput('token'); + const manifest = (yield this.http.getJson('https://github.com/dmitry-shibanov/setup-java/tree/main', { authorization: token })).result; + return manifest; }); } getPlatformOption(platform = process.platform /* for testing */) { diff --git a/microsoft-build-of-openjdk-versions.json b/microsoft-build-of-openjdk-versions.json new file mode 100644 index 000000000..11125b783 --- /dev/null +++ b/microsoft-build-of-openjdk-versions.json @@ -0,0 +1,176 @@ +[ + { + "version": "17.0.3", + "stable": true, + "files": [ + { + "filename": "microsoft-jdk-17.0.3-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.3-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.3-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-17.0.3-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.3-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "17.0.1+12.1", + "stable": true, + "files": [ + { + "filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "16.0.2+7.1", + "stable": true, + "files": [ + { + "filename": "microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-16.0.2+7.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-16.0.2+7.1-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-16.0.2+7.1-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-16.0.2+7.1-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "11.0.15", + "stable": true, + "files": [ + { + "filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.15-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.15-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-11.0.15-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.15-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "11.0.13+8.1", + "stable": true, + "files": [ + { + "filename": "microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.13+8.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.13+8.1-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-11.0.13+8.1-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-linux-aarch64.tar.gz" + } + ] + } +] \ No newline at end of file diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 4ceb4285b..7cd96a374 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -51,57 +51,62 @@ export class MicrosoftDistributions extends JavaBase { const availableVersionsRaw = await this.getAvailableVersions(); - const opts = this.getPlatformOption(); - const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ - this.architecture - }.${opts.archive}`, - version: this.convertVersionToSemver(item) - })); - - const satisfiedVersion = availableVersions - .filter(item => isVersionSatisfies(range, item.version)) - .sort((a, b) => -semver.compareBuild(a.version, b.version))[0]; - - if (!satisfiedVersion) { - const availableOptions = availableVersions.map(item => item.version).join(', '); - const availableOptionsMessage = availableOptions - ? `\nAvailable versions: ${availableOptions}` - : ''; + if (!availableVersionsRaw) { + throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); + } + + const foundRelease = await tc.findFromManifest( + range, + true, + availableVersionsRaw, + this.architecture + ); + + // const opts = this.getPlatformOption(); + // const availableVersions = availableVersionsRaw.map(item => ({ + // url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ + // this.architecture // https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz + // }.${opts.archive}`, + // version: this.convertVersionToSemver(item) + // })); + + // const satisfiedVersion = availableVersions + // .filter(item => isVersionSatisfies(range, item.version)) + // .sort((a, b) => -semver.compareBuild(a.version, b.version))[0]; + + // if (!satisfiedVersion) { + // const availableOptions = availableVersions.map(item => item.version).join(', '); + // const availableOptionsMessage = availableOptions + // ? `\nAvailable versions: ${availableOptions}` + // : ''; + // throw new Error( + // `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}` + // ); + // } + + if (!foundRelease) { throw new Error( - `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}` + `Could not find satisfied version for SemVer ${range}. ${availableVersionsRaw + .map(item => item.version) + .join(', ')}` ); } - return satisfiedVersion; + return { url: foundRelease.release_url, version: foundRelease.version }; } - private async getAvailableVersions(): Promise { + private async getAvailableVersions(): Promise { // TODO get these dynamically! // We will need Microsoft to add an endpoint where we can query for versions. - const jdkVersions = [ - { - version: [17, 0, 3] - }, - { - version: [17, 0, 1, 12, 1] - }, - { - version: [16, 0, 2, 7, 1] - }, - { - version: [11, 0, 15] - } - ]; - - // M1 is only supported for Java 16 & 17 - if (process.platform !== 'darwin' || this.architecture !== 'aarch64') { - jdkVersions.push({ - version: [11, 0, 13, 8, 1] - }); - } - - return jdkVersions; + const token = core.getInput('token'); + const manifest = ( + await this.http.getJson( + 'https://github.com/dmitry-shibanov/setup-java/tree/main', + { authorization: token } + ) + ).result; + + return manifest; } private getPlatformOption( From 5c11592098d013d412b3c28b73f4a148b91f7571 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 14:21:46 +0200 Subject: [PATCH 02/15] update url --- dist/setup/index.js | 2 +- src/distributions/microsoft/installer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 2f72b1dec..f7bfb08ab 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102468,7 +102468,7 @@ 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 this.http.getJson('https://github.com/dmitry-shibanov/setup-java/tree/main', { authorization: token })).result; + const manifest = (yield this.http.getJson('https://github.com/dmitry-shibanov/setup-java/tree/add-json-for-microsoft-versions', { authorization: token })).result; return manifest; }); } diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 7cd96a374..f4d268f7e 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -101,7 +101,7 @@ export class MicrosoftDistributions extends JavaBase { const token = core.getInput('token'); const manifest = ( await this.http.getJson( - 'https://github.com/dmitry-shibanov/setup-java/tree/main', + 'https://github.com/dmitry-shibanov/setup-java/tree/add-json-for-microsoft-versions', { authorization: token } ) ).result; From f25607f34840f1eb97fae1d91d920ff12a350666 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 14:24:35 +0200 Subject: [PATCH 03/15] update url --- dist/setup/index.js | 2 +- src/distributions/microsoft/installer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index f7bfb08ab..96d71a1db 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102468,7 +102468,7 @@ 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 this.http.getJson('https://github.com/dmitry-shibanov/setup-java/tree/add-json-for-microsoft-versions', { authorization: token })).result; + const manifest = (yield this.http.getJson('https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token })).result; return manifest; }); } diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index f4d268f7e..9daf2415c 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -101,7 +101,7 @@ export class MicrosoftDistributions extends JavaBase { const token = core.getInput('token'); const manifest = ( await this.http.getJson( - 'https://github.com/dmitry-shibanov/setup-java/tree/add-json-for-microsoft-versions', + 'https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token } ) ).result; From afb8d2e48a1d98ffe17c0158db48e5aae167340d Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 14:52:51 +0200 Subject: [PATCH 04/15] add property --- src/distributions/microsoft/installer.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 9daf2415c..5a2ded497 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -1,13 +1,18 @@ 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 } from '../../util'; import * as core from '@actions/core'; import { MicrosoftVersion, PlatformOptions } from './models'; import * as tc from '@actions/tool-cache'; import fs from 'fs'; import path from 'path'; +export interface IToolRelease { + version: string; + stable: boolean; + files: tc.IToolReleaseFile[]; +} + export class MicrosoftDistributions extends JavaBase { constructor(installerOptions: JavaInstallerOptions) { super('Microsoft', installerOptions); @@ -58,7 +63,7 @@ export class MicrosoftDistributions extends JavaBase { const foundRelease = await tc.findFromManifest( range, true, - availableVersionsRaw, + availableVersionsRaw.map(item => Object.assign(item, { release_url: '' })), this.architecture ); @@ -95,12 +100,12 @@ export class MicrosoftDistributions extends JavaBase { return { url: foundRelease.release_url, version: foundRelease.version }; } - private async getAvailableVersions(): Promise { + private async getAvailableVersions(): Promise { // 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 this.http.getJson( + await this.http.getJson( 'https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token } ) From e2b8e57140e28c4b47b2b5fc7c54bbf7fbb043e1 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 15:00:18 +0200 Subject: [PATCH 05/15] add log --- dist/setup/index.js | 3 ++- src/distributions/microsoft/installer.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 96d71a1db..0c22427fe 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102435,7 +102435,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { if (!availableVersionsRaw) { throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); } - const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw, this.architecture); + const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw.map(item => Object.assign(item, { release_url: '' })), this.architecture); // const opts = this.getPlatformOption(); // const availableVersions = availableVersionsRaw.map(item => ({ // url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ @@ -102469,6 +102469,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { // We will need Microsoft to add an endpoint where we can query for versions. const token = core.getInput('token'); const manifest = (yield this.http.getJson('https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token })).result; + core.info(manifest); return manifest; }); } diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 5a2ded497..806b5f064 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -105,12 +105,14 @@ export class MicrosoftDistributions extends JavaBase { // We will need Microsoft to add an endpoint where we can query for versions. const token = core.getInput('token'); const manifest = ( - await this.http.getJson( + await this.http.getJson( 'https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token } ) ).result; + core.info(manifest); + return manifest; } From 7b84a4c0bd160bd8829038e1e833b66c16f9bbce Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 15:07:57 +0200 Subject: [PATCH 06/15] minor changes --- dist/setup/index.js | 7 ++++--- src/distributions/microsoft/installer.ts | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0c22427fe..586b87d12 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102468,9 +102468,10 @@ 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 this.http.getJson('https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token })).result; - core.info(manifest); - return manifest; + const { result, statusCode } = (yield this.http.getJson('https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token })); + core.info(result); + core.info(statusCode.toString()); + return result; }); } getPlatformOption(platform = process.platform /* for testing */) { diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 806b5f064..92544b736 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -104,16 +104,17 @@ 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 = ( + const {result, statusCode} = ( await this.http.getJson( 'https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token } ) - ).result; + ); - core.info(manifest); + core.info(result); + core.info(statusCode.toString()); - return manifest; + return result; } private getPlatformOption( From 1ba38a2e767c61ed8dd9f42c7d07c2df17876ec8 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 15:25:05 +0200 Subject: [PATCH 07/15] minor changes --- dist/setup/index.js | 8 +++----- microsoft-build-of-openjdk-versions.json | 5 +++++ src/distributions/microsoft/installer.ts | 19 ++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 586b87d12..c5d3a4ce3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102435,7 +102435,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { if (!availableVersionsRaw) { throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); } - const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw.map(item => Object.assign(item, { release_url: '' })), this.architecture); + const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw, this.architecture); // const opts = this.getPlatformOption(); // const availableVersions = availableVersionsRaw.map(item => ({ // url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ @@ -102468,10 +102468,8 @@ 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 { result, statusCode } = (yield this.http.getJson('https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', { authorization: token })); - core.info(result); - core.info(statusCode.toString()); - return result; + const manifest = yield tc.getManifestFromRepo('dmitry-shibanov', 'setup-java', token, 'add-json-for-microsoft-versions'); + return manifest; }); } getPlatformOption(platform = process.platform /* for testing */) { diff --git a/microsoft-build-of-openjdk-versions.json b/microsoft-build-of-openjdk-versions.json index 11125b783..4f8d7d404 100644 --- a/microsoft-build-of-openjdk-versions.json +++ b/microsoft-build-of-openjdk-versions.json @@ -2,6 +2,7 @@ { "version": "17.0.3", "stable": true, + "release_url": "https://aka.ms/download-jdk", "files": [ { "filename": "microsoft-jdk-17.0.3-macos-x64.tar.gz", @@ -38,6 +39,7 @@ { "version": "17.0.1+12.1", "stable": true, + "release_url": "https://aka.ms/download-jdk", "files": [ { "filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz", @@ -74,6 +76,7 @@ { "version": "16.0.2+7.1", "stable": true, + "release_url": "https://aka.ms/download-jdk", "files": [ { "filename": "microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz", @@ -110,6 +113,7 @@ { "version": "11.0.15", "stable": true, + "release_url": "https://aka.ms/download-jdk", "files": [ { "filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz", @@ -146,6 +150,7 @@ { "version": "11.0.13+8.1", "stable": true, + "release_url": "https://aka.ms/download-jdk", "files": [ { "filename": "microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz", diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 92544b736..489a3d39e 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -63,7 +63,7 @@ export class MicrosoftDistributions extends JavaBase { const foundRelease = await tc.findFromManifest( range, true, - availableVersionsRaw.map(item => Object.assign(item, { release_url: '' })), + availableVersionsRaw, this.architecture ); @@ -100,21 +100,18 @@ export class MicrosoftDistributions extends JavaBase { return { url: foundRelease.release_url, version: foundRelease.version }; } - private async getAvailableVersions(): Promise { + private async getAvailableVersions(): Promise { // TODO get these dynamically! // We will need Microsoft to add an endpoint where we can query for versions. const token = core.getInput('token'); - const {result, statusCode} = ( - await this.http.getJson( - 'https://github.com/dmitry-shibanov/setup-java/blob/add-json-for-microsoft-versions/microsoft-build-of-openjdk-versions.json', - { authorization: token } - ) + const manifest = await tc.getManifestFromRepo( + 'dmitry-shibanov', + 'setup-java', + token, + 'add-json-for-microsoft-versions' ); - core.info(result); - core.info(statusCode.toString()); - - return result; + return manifest; } private getPlatformOption( From 109e9d02416d2dcfc6ba75a62249838ca4acdc7b Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 15:33:04 +0200 Subject: [PATCH 08/15] rename json --- ...osoft-build-of-openjdk-versions.json => versions-manifest.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename microsoft-build-of-openjdk-versions.json => versions-manifest.json (100%) diff --git a/microsoft-build-of-openjdk-versions.json b/versions-manifest.json similarity index 100% rename from microsoft-build-of-openjdk-versions.json rename to versions-manifest.json From 244aafd0a2344230fee300fc106181573dbe350c Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 5 Sep 2022 15:44:00 +0200 Subject: [PATCH 09/15] minor changes --- dist/setup/index.js | 2 +- src/distributions/microsoft/installer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index c5d3a4ce3..597f03c6b 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102460,7 +102460,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { .map(item => item.version) .join(', ')}`); } - return { url: foundRelease.release_url, version: foundRelease.version }; + return { url: foundRelease.files[0].download_url, version: foundRelease.version }; }); } getAvailableVersions() { diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 489a3d39e..d3aa569de 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -97,7 +97,7 @@ export class MicrosoftDistributions extends JavaBase { ); } - return { url: foundRelease.release_url, version: foundRelease.version }; + return { url: foundRelease.files[0].download_url, version: foundRelease.version }; } private async getAvailableVersions(): Promise { From ee1310e14d2ea3418e9b69b339e218b127681868 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 6 Sep 2022 13:29:57 +0200 Subject: [PATCH 10/15] fix test and json --- .../distributors/microsoft-installer.test.ts | 48 +++++---------- dist/setup/index.js | 45 ++------------ src/distributions/microsoft/installer.ts | 60 ++----------------- src/distributions/microsoft/models.ts | 10 ---- tsconfig.json | 1 + versions-manifest.json | 36 +++++------ 6 files changed, 43 insertions(+), 157 deletions(-) diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index 9be0f50ea..bc5856035 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -1,7 +1,12 @@ import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer'; +import * as tc from '@actions/tool-cache'; +import data from '../../versions-manifest.json'; +import * as core from '@actions/core'; describe('findPackageForDownload', () => { let distribution: MicrosoftDistributions; + let spyGetManifestFromRepo: jest.SpyInstance; + let spyDebug: jest.SpyInstance; beforeEach(() => { distribution = new MicrosoftDistributions({ @@ -10,12 +15,20 @@ describe('findPackageForDownload', () => { packageType: 'jdk', checkLatest: false }); + + spyGetManifestFromRepo = jest.spyOn(tc, 'getManifestFromRepo'); + spyGetManifestFromRepo.mockImplementation(() => { + return data; + }); + + spyDebug = jest.spyOn(core, 'debug'); + spyDebug.mockImplementation(() => {}); }); it.each([ [ '17.0.1', - '17.0.1', + '17.0.1+12.1', 'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' ], [ @@ -25,12 +38,12 @@ describe('findPackageForDownload', () => { ], [ '16.0.x', - '16.0.2', + '16.0.2+7.1', 'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' ], [ '11.0.13', - '11.0.13', + '11.0.13+8.1', 'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' ], [ @@ -67,32 +80,3 @@ describe('findPackageForDownload', () => { ); }); }); - -describe('getPlatformOption', () => { - const distributions = new MicrosoftDistributions({ - architecture: 'x64', - version: '11', - packageType: 'jdk', - checkLatest: false - }); - - it.each([ - ['linux', 'tar.gz', 'linux'], - ['darwin', 'tar.gz', 'macos'], - ['win32', 'zip', 'windows'] - ])('os version %s -> %s', (input, expectedArchive, expectedOs) => { - const actual = distributions['getPlatformOption'](input as NodeJS.Platform); - - expect(actual.archive).toEqual(expectedArchive); - expect(actual.os).toEqual(expectedOs); - }); - - it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])( - 'not support os version %s', - input => { - expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow( - /Platform '\w+' is not supported\. Supported platforms: .+/ - ); - } - ); -}); diff --git a/dist/setup/index.js b/dist/setup/index.js index 597f03c6b..06a85bbc8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102431,32 +102431,13 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { if (this.packageType !== 'jdk') { throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); } - const availableVersionsRaw = yield this.getAvailableVersions(); - if (!availableVersionsRaw) { + const manifest = yield this.getAvailableVersions(); + if (!manifest) { throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); } - const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw, this.architecture); - // const opts = this.getPlatformOption(); - // const availableVersions = availableVersionsRaw.map(item => ({ - // url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ - // this.architecture // https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz - // }.${opts.archive}`, - // version: this.convertVersionToSemver(item) - // })); - // const satisfiedVersion = availableVersions - // .filter(item => isVersionSatisfies(range, item.version)) - // .sort((a, b) => -semver.compareBuild(a.version, b.version))[0]; - // if (!satisfiedVersion) { - // const availableOptions = availableVersions.map(item => item.version).join(', '); - // const availableOptionsMessage = availableOptions - // ? `\nAvailable versions: ${availableOptions}` - // : ''; - // throw new Error( - // `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}` - // ); - // } + const foundRelease = yield tc.findFromManifest(range, true, manifest, this.architecture); if (!foundRelease) { - throw new Error(`Could not find satisfied version for SemVer ${range}. ${availableVersionsRaw + throw new Error(`Could not find satisfied version for SemVer ${range}. ${manifest .map(item => item.version) .join(', ')}`); } @@ -102472,24 +102453,6 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { return manifest; }); } - getPlatformOption(platform = process.platform /* for testing */) { - switch (platform) { - case 'darwin': - return { archive: 'tar.gz', os: 'macos' }; - case 'win32': - return { archive: 'zip', os: 'windows' }; - case 'linux': - return { archive: 'tar.gz', os: 'linux' }; - default: - throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`); - } - } - convertVersionToSemver(version) { - const major = version.version[0]; - const minor = version.version[1]; - const patch = version.version[2]; - return `${major}.${minor}.${patch}`; - } } exports.MicrosoftDistributions = MicrosoftDistributions; diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index d3aa569de..2745e4174 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -2,7 +2,6 @@ import { JavaBase } from '../base-installer'; import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models'; import { extractJdkFile, getDownloadArchiveExtension } from '../../util'; import * as core from '@actions/core'; -import { MicrosoftVersion, PlatformOptions } from './models'; import * as tc from '@actions/tool-cache'; import fs from 'fs'; import path from 'path'; @@ -54,44 +53,17 @@ export class MicrosoftDistributions extends JavaBase { throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); } - const availableVersionsRaw = await this.getAvailableVersions(); + const manifest = await this.getAvailableVersions(); - if (!availableVersionsRaw) { + if (!manifest) { throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); } - const foundRelease = await tc.findFromManifest( - range, - true, - availableVersionsRaw, - this.architecture - ); - - // const opts = this.getPlatformOption(); - // const availableVersions = availableVersionsRaw.map(item => ({ - // url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ - // this.architecture // https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz - // }.${opts.archive}`, - // version: this.convertVersionToSemver(item) - // })); - - // const satisfiedVersion = availableVersions - // .filter(item => isVersionSatisfies(range, item.version)) - // .sort((a, b) => -semver.compareBuild(a.version, b.version))[0]; - - // if (!satisfiedVersion) { - // const availableOptions = availableVersions.map(item => item.version).join(', '); - // const availableOptionsMessage = availableOptions - // ? `\nAvailable versions: ${availableOptions}` - // : ''; - // throw new Error( - // `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}` - // ); - // } + const foundRelease = await tc.findFromManifest(range, true, manifest, this.architecture); if (!foundRelease) { throw new Error( - `Could not find satisfied version for SemVer ${range}. ${availableVersionsRaw + `Could not find satisfied version for SemVer ${range}. ${manifest .map(item => item.version) .join(', ')}` ); @@ -113,28 +85,4 @@ export class MicrosoftDistributions extends JavaBase { return manifest; } - - private getPlatformOption( - platform: NodeJS.Platform = process.platform /* for testing */ - ): PlatformOptions { - switch (platform) { - case 'darwin': - return { archive: 'tar.gz', os: 'macos' }; - case 'win32': - return { archive: 'zip', os: 'windows' }; - case 'linux': - return { archive: 'tar.gz', os: 'linux' }; - default: - throw new Error( - `Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'` - ); - } - } - - private convertVersionToSemver(version: MicrosoftVersion): string { - const major = version.version[0]; - const minor = version.version[1]; - const patch = version.version[2]; - return `${major}.${minor}.${patch}`; - } } diff --git a/src/distributions/microsoft/models.ts b/src/distributions/microsoft/models.ts index 361c7dba5..c012bc73b 100644 --- a/src/distributions/microsoft/models.ts +++ b/src/distributions/microsoft/models.ts @@ -1,12 +1,2 @@ type OsVersions = 'linux' | 'macos' | 'windows'; type ArchiveType = 'tar.gz' | 'zip'; - -export interface PlatformOptions { - archive: ArchiveType; - os: OsVersions; -} - -export interface MicrosoftVersion { - downloadUrl?: string; - version: Array; -} diff --git a/tsconfig.json b/tsconfig.json index 9ecff8679..562115800 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ + "resolveJsonModule": true, // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ diff --git a/versions-manifest.json b/versions-manifest.json index 4f8d7d404..b729619d5 100644 --- a/versions-manifest.json +++ b/versions-manifest.json @@ -79,34 +79,34 @@ "release_url": "https://aka.ms/download-jdk", "files": [ { - "filename": "microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz", + "filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz", "arch": "x64", "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz" }, { - "filename": "microsoft-jdk-16.0.2+7.1-linux-x64.tar.gz", + "filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz", "arch": "x64", "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-linux-x64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz" }, { - "filename": "microsoft-jdk-16.0.2+7.1-windows-x64.zip", + "filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip", "arch": "x64", "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-windows-x64.zip" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-windows-x64.zip" }, { - "filename": "microsoft-jdk-16.0.2+7.1-macos-aarch64.tar.gz", + "filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz", "arch": "aarch64", "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-macos-aarch64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz" }, { - "filename": "microsoft-jdk-16.0.2+7.1-linux-aarch64.tar.gz", + "filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz", "arch": "aarch64", "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-linux-aarch64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz" } ] }, @@ -153,28 +153,28 @@ "release_url": "https://aka.ms/download-jdk", "files": [ { - "filename": "microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz", + "filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz", "arch": "x64", "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz" }, { - "filename": "microsoft-jdk-11.0.13+8.1-linux-x64.tar.gz", + "filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz", "arch": "x64", "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-linux-x64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz" }, { - "filename": "microsoft-jdk-11.0.13+8.1-windows-x64.zip", + "filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip", "arch": "x64", "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-windows-x64.zip" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-x64.zip" }, { - "filename": "microsoft-jdk-11.0.13+8.1-linux-aarch64.tar.gz", + "filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz", "arch": "aarch64", "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-linux-aarch64.tar.gz" + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz" } ] } From 4e8be27276cb8361bbf817f4dc36c1ac1ac46044 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 19 Sep 2022 14:19:09 +0200 Subject: [PATCH 11/15] minor fix --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 41709419c..499eae3f5 100644 --- a/action.yml +++ b/action.yml @@ -60,7 +60,7 @@ inputs: description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting' default: ${{ job.status }} token: - description: Used to pull java versions from setup-java. Since there's a default, this is typically not supplied by the user. + description: Used to pull java versions from setup-java. Since there is a default value, token is typically not supplied by the user. default: ${{ github.token }} outputs: distribution: From 7f8371344eca04ee1465dde35ff35f34a84b9e66 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 19 Sep 2022 17:16:32 +0200 Subject: [PATCH 12/15] resolving comment --- .../distributors/microsoft-installer.test.ts | 11 ++-- dist/setup/index.js | 34 +++++++++++- src/distributions/microsoft/installer.ts | 53 ++++++++++++++----- .../microsoft/microsoft-openjdk-versions.json | 0 4 files changed, 79 insertions(+), 19 deletions(-) rename versions-manifest.json => src/distributions/microsoft/microsoft-openjdk-versions.json (100%) diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index bc5856035..10335da13 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -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'); diff --git a/dist/setup/index.js b/dist/setup/index.js index 2ad382e12..4b2f80afb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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; }); } } diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 2745e4174..eda3a050b 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -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'; + + 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 | null = null; + + try { + response = await 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?.statusCode}` + ); + return null; + } + + let versionsRaw = response.result; + + if (versionsRaw) { + versionsRaw = versionsRaw.replace(/^\uFEFF/, ''); + try { + releases = JSON.parse(versionsRaw); + } catch { + core.debug('Invalid json'); + } + } - return manifest; + return releases; } } diff --git a/versions-manifest.json b/src/distributions/microsoft/microsoft-openjdk-versions.json similarity index 100% rename from versions-manifest.json rename to src/distributions/microsoft/microsoft-openjdk-versions.json From 62a27417dcc3c6311475e1d332438fc837c272e9 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 19 Sep 2022 17:26:47 +0200 Subject: [PATCH 13/15] fix type --- .../distributors/microsoft-installer.test.ts | 2 +- dist/setup/index.js | 13 +++---------- src/distributions/microsoft/installer.ts | 17 +++++------------ 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index 10335da13..c3e560bfc 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -19,7 +19,7 @@ describe('findPackageForDownload', () => { spyGetManifestFromRepo = jest.spyOn(httpm.HttpClient.prototype, 'getJson'); spyGetManifestFromRepo.mockReturnValue({ - result: JSON.stringify(data), + result: data, statusCode: 200, headers: {} }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 4b2f80afb..e58a8308f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -104460,7 +104460,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { const repository = 'setup-java'; const branch = 'add-json-for-microsoft-versions'; const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json'; - let releases = []; + let releases = null; const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; const headers = { authorization: token, @@ -104477,15 +104477,8 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { 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'); - } + if (response.result) { + releases = response.result; } return releases; }); diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index eda3a050b..2d5518ad4 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -77,7 +77,7 @@ export class MicrosoftDistributions extends JavaBase { const branch = 'add-json-for-microsoft-versions'; const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json'; - let releases: tc.IToolRelease[] = []; + let releases: tc.IToolRelease[] | null = null; const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; const headers: OutgoingHttpHeaders = { @@ -85,10 +85,10 @@ export class MicrosoftDistributions extends JavaBase { accept: 'application/vnd.github.VERSION.raw' }; - let response: ITypedResponse | null = null; + let response: ITypedResponse | null = null; try { - response = await this.http.getJson(fileUrl, headers); + response = await this.http.getJson(fileUrl, headers); if (!response.result) { return null; } @@ -99,15 +99,8 @@ export class MicrosoftDistributions extends JavaBase { return null; } - let versionsRaw = response.result; - - if (versionsRaw) { - versionsRaw = versionsRaw.replace(/^\uFEFF/, ''); - try { - releases = JSON.parse(versionsRaw); - } catch { - core.debug('Invalid json'); - } + if (response.result) { + releases = response.result; } return releases; From 792b271717dd84283fe28c122dfdb2607490c8db Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 22 Sep 2022 16:12:12 +0200 Subject: [PATCH 14/15] remove json --- .../microsoft/microsoft-openjdk-versions.json | 181 ------------------ 1 file changed, 181 deletions(-) delete mode 100644 src/distributions/microsoft/microsoft-openjdk-versions.json diff --git a/src/distributions/microsoft/microsoft-openjdk-versions.json b/src/distributions/microsoft/microsoft-openjdk-versions.json deleted file mode 100644 index b729619d5..000000000 --- a/src/distributions/microsoft/microsoft-openjdk-versions.json +++ /dev/null @@ -1,181 +0,0 @@ -[ - { - "version": "17.0.3", - "stable": true, - "release_url": "https://aka.ms/download-jdk", - "files": [ - { - "filename": "microsoft-jdk-17.0.3-macos-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-17.0.3-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-17.0.3-windows-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-windows-x64.zip" - }, - { - "filename": "microsoft-jdk-17.0.3-macos-aarch64.tar.gz", - "arch": "aarch64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-aarch64.tar.gz" - }, - { - "filename": "microsoft-jdk-17.0.3-linux-aarch64.tar.gz", - "arch": "aarch64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz" - } - ] - }, - { - "version": "17.0.1+12.1", - "stable": true, - "release_url": "https://aka.ms/download-jdk", - "files": [ - { - "filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-17.0.1.12.1-windows-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-windows-x64.zip" - }, - { - "filename": "microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz", - "arch": "aarch64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz" - }, - { - "filename": "microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz", - "arch": "aarch64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz" - } - ] - }, - { - "version": "16.0.2+7.1", - "stable": true, - "release_url": "https://aka.ms/download-jdk", - "files": [ - { - "filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-windows-x64.zip" - }, - { - "filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz", - "arch": "aarch64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz" - }, - { - "filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz", - "arch": "aarch64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz" - } - ] - }, - { - "version": "11.0.15", - "stable": true, - "release_url": "https://aka.ms/download-jdk", - "files": [ - { - "filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-11.0.15-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-11.0.15-windows-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-windows-x64.zip" - }, - { - "filename": "microsoft-jdk-11.0.15-macos-aarch64.tar.gz", - "arch": "aarch64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-aarch64.tar.gz" - }, - { - "filename": "microsoft-jdk-11.0.15-linux-aarch64.tar.gz", - "arch": "aarch64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-aarch64.tar.gz" - } - ] - }, - { - "version": "11.0.13+8.1", - "stable": true, - "release_url": "https://aka.ms/download-jdk", - "files": [ - { - "filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz" - }, - { - "filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-x64.zip" - }, - { - "filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz", - "arch": "aarch64", - "platform": "linux", - "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz" - } - ] - } -] \ No newline at end of file From 70ee3e0c5cc4cd425d5b1bac0216c7125dd96697 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 22 Sep 2022 16:14:28 +0200 Subject: [PATCH 15/15] change remote --- dist/setup/index.js | 4 ++-- src/distributions/microsoft/installer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e58a8308f..e19da558a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -104456,9 +104456,9 @@ 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 owner = 'dmitry-shibanov'; + const owner = 'actions'; const repository = 'setup-java'; - const branch = 'add-json-for-microsoft-versions'; + const branch = 'main'; const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json'; let releases = null; const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 2d5518ad4..4a7264da3 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -72,9 +72,9 @@ 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 owner = 'dmitry-shibanov'; + const owner = 'actions'; const repository = 'setup-java'; - const branch = 'add-json-for-microsoft-versions'; + const branch = 'main'; const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json'; let releases: tc.IToolRelease[] | null = null;