feat: add logic for backuping getting json

This commit is contained in:
Ivan Zosimov 2023-09-19 11:44:45 +02:00
parent cf4e1422a0
commit 6ba9d9dd2c
2 changed files with 101 additions and 37 deletions

60
dist/setup/index.js vendored
View File

@ -102683,22 +102683,14 @@ class DragonwellDistribution extends base_installer_1.JavaBase {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const platform = this.getPlatformOption(); const platform = this.getPlatformOption();
const arch = this.distributionArchitecture(); const arch = this.distributionArchitecture();
const token = core.getInput('token'); let fetchedDragonwellJson = yield this.fetchJsonFromPrimaryUrl();
const auth = !token ? undefined : `token ${token}`; if (!fetchedDragonwellJson) {
const owner = 'dragonwell-releng'; fetchedDragonwellJson = yield this.fetchJsonFromBackupUrl();
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}`);
} }
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()) { if (core.isDebug()) {
core.startGroup('Print information about available versions'); core.startGroup('Print information about available versions');
core.debug(availableVersions.map(item => item.jdk_version).join(', ')); core.debug(availableVersions.map(item => item.jdk_version).join(', '));
@ -102783,6 +102775,44 @@ class DragonwellDistribution extends base_installer_1.JavaBase {
return process.platform; 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; exports.DragonwellDistribution = DragonwellDistribution;

View File

@ -62,37 +62,22 @@ export class DragonwellDistribution extends JavaBase {
const platform = this.getPlatformOption(); const platform = this.getPlatformOption();
const arch = this.distributionArchitecture(); const arch = this.distributionArchitecture();
const token = core.getInput('token'); let fetchedDragonwellJson = await this.fetchJsonFromPrimaryUrl();
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}`; if (!fetchedDragonwellJson) {
fetchedDragonwellJson = await this.fetchJsonFromBackupUrl();
}
const headers: OutgoingHttpHeaders = { if (!fetchedDragonwellJson) {
authorization: auth,
accept: 'application/vnd.github.VERSION.raw'
};
const fetchedDragonwellVersions = (
await this.http.getJson<IDragonwellAllVersions>(
availableVersionsUrl,
headers
)
).result;
if (!fetchedDragonwellVersions) {
throw new Error( 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( const availableVersions = this.parseVersions(
platform, platform,
arch, arch,
fetchedDragonwellVersions fetchedDragonwellJson
); );
if (core.isDebug()) { if (core.isDebug()) {
@ -210,4 +195,53 @@ export class DragonwellDistribution extends JavaBase {
return process.platform; return process.platform;
} }
} }
private async fetchJsonFromPrimaryUrl(): Promise<IDragonwellAllVersions | null> {
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<IDragonwellAllVersions>(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<IDragonwellAllVersions | null> {
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<IDragonwellAllVersions>(backupUrl, headers)
).result;
return fetchedDragonwellVersions;
} catch (err) {
core.debug(
`Fetching from the backup url: ${backupUrl} ended with the error: ${err.message}`
);
return null;
}
}
} }