diff --git a/dist/setup/index.js b/dist/setup/index.js index ca30589..959b4a0 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102683,22 +102683,14 @@ class DragonwellDistribution extends base_installer_1.JavaBase { return __awaiter(this, void 0, void 0, function* () { const platform = this.getPlatformOption(); const arch = this.distributionArchitecture(); - const token = core.getInput('token'); - const auth = !token ? undefined : `token ${token}`; - const owner = 'dragonwell-releng'; - const repository = 'dragonwell-setup-java'; - const branch = 'main'; - const filePath = 'releases.json'; - const availableVersionsUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; - const headers = { - authorization: auth, - accept: 'application/vnd.github.VERSION.raw' - }; - const fetchedDragonwellVersions = (yield this.http.getJson(availableVersionsUrl, headers)).result; - if (!fetchedDragonwellVersions) { - throw new Error(`Couldn't fetch any dragonwell versions from ${availableVersionsUrl}`); + let fetchedDragonwellJson = yield this.fetchJsonFromPrimaryUrl(); + if (!fetchedDragonwellJson) { + fetchedDragonwellJson = yield this.fetchJsonFromBackupUrl(); } - const availableVersions = this.parseVersions(platform, arch, fetchedDragonwellVersions); + if (!fetchedDragonwellJson) { + throw new Error(`Couldn't fetch any dragonwell versions from both primary and backup urls`); + } + const availableVersions = this.parseVersions(platform, arch, fetchedDragonwellJson); if (core.isDebug()) { core.startGroup('Print information about available versions'); core.debug(availableVersions.map(item => item.jdk_version).join(', ')); @@ -102783,6 +102775,44 @@ class DragonwellDistribution extends base_installer_1.JavaBase { return process.platform; } } + fetchJsonFromPrimaryUrl() { + return __awaiter(this, void 0, void 0, function* () { + const primaryUrl = 'https://dragonwell-jjk.io/map_with_checksum.json'; + try { + core.debug(`Trying to fetch available versions info from the primary url: ${primaryUrl}`); + const fetchedDragonwellJson = (yield this.http.getJson(primaryUrl)).result; + return fetchedDragonwellJson; + } + catch (err) { + core.debug(`Fetching from the primary link: ${primaryUrl} ended with the error: ${err.message}`); + return null; + } + }); + } + fetchJsonFromBackupUrl() { + return __awaiter(this, void 0, void 0, function* () { + const token = core.getInput('token'); + const auth = !token ? undefined : `token ${token}`; + const owner = 'dragonwell-releng'; + const repository = 'dragonwell-setup-java'; + const branch = 'main'; + const filePath = 'releases.json'; + const backupUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; + const headers = { + authorization: auth, + accept: 'application/vnd.github.VERSION.raw' + }; + try { + core.debug(`Trying to fetch available versions from the backup url: ${backupUrl}`); + const fetchedDragonwellVersions = (yield this.http.getJson(backupUrl, headers)).result; + return fetchedDragonwellVersions; + } + catch (err) { + core.debug(`Fetching from the backup url: ${backupUrl} ended with the error: ${err.message}`); + return null; + } + }); + } } exports.DragonwellDistribution = DragonwellDistribution; diff --git a/src/distributions/dragonwell/installer.ts b/src/distributions/dragonwell/installer.ts index 34e47bc..79914c4 100644 --- a/src/distributions/dragonwell/installer.ts +++ b/src/distributions/dragonwell/installer.ts @@ -62,37 +62,22 @@ export class DragonwellDistribution extends JavaBase { const platform = this.getPlatformOption(); const arch = this.distributionArchitecture(); - const token = core.getInput('token'); - const auth = !token ? undefined : `token ${token}`; - const owner = 'dragonwell-releng'; - const repository = 'dragonwell-setup-java'; - const branch = 'main'; - const filePath = 'releases.json'; + let fetchedDragonwellJson = await this.fetchJsonFromPrimaryUrl(); - const availableVersionsUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; + if (!fetchedDragonwellJson) { + fetchedDragonwellJson = await this.fetchJsonFromBackupUrl(); + } - const headers: OutgoingHttpHeaders = { - authorization: auth, - accept: 'application/vnd.github.VERSION.raw' - }; - - const fetchedDragonwellVersions = ( - await this.http.getJson( - availableVersionsUrl, - headers - ) - ).result; - - if (!fetchedDragonwellVersions) { + if (!fetchedDragonwellJson) { throw new Error( - `Couldn't fetch any dragonwell versions from ${availableVersionsUrl}` + `Couldn't fetch any dragonwell versions from both primary and backup urls` ); } const availableVersions = this.parseVersions( platform, arch, - fetchedDragonwellVersions + fetchedDragonwellJson ); if (core.isDebug()) { @@ -210,4 +195,53 @@ export class DragonwellDistribution extends JavaBase { return process.platform; } } + + private async fetchJsonFromPrimaryUrl(): Promise { + const primaryUrl = 'https://dragonwell-jjk.io/map_with_checksum.json'; + try { + core.debug( + `Trying to fetch available versions info from the primary url: ${primaryUrl}` + ); + const fetchedDragonwellJson = ( + await this.http.getJson(primaryUrl) + ).result; + return fetchedDragonwellJson; + } catch (err) { + core.debug( + `Fetching from the primary link: ${primaryUrl} ended with the error: ${err.message}` + ); + return null; + } + } + + private async fetchJsonFromBackupUrl(): Promise { + const token = core.getInput('token'); + const auth = !token ? undefined : `token ${token}`; + const owner = 'dragonwell-releng'; + const repository = 'dragonwell-setup-java'; + const branch = 'main'; + const filePath = 'releases.json'; + + const backupUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; + + const headers: OutgoingHttpHeaders = { + authorization: auth, + accept: 'application/vnd.github.VERSION.raw' + }; + + try { + core.debug( + `Trying to fetch available versions from the backup url: ${backupUrl}` + ); + const fetchedDragonwellVersions = ( + await this.http.getJson(backupUrl, headers) + ).result; + return fetchedDragonwellVersions; + } catch (err) { + core.debug( + `Fetching from the backup url: ${backupUrl} ended with the error: ${err.message}` + ); + return null; + } + } }