Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add logic for backuping getting json
  • Loading branch information
Ivan Zosimov committed Sep 19, 2023
commit 6ba9d9dd2cf69598a2e222bce45ad12fb62ccae0
60 changes: 45 additions & 15 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', '));
Expand Down Expand Up @@ -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;

Expand Down
78 changes: 56 additions & 22 deletions src/distributions/dragonwell/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

const availableVersionsUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;

const headers: OutgoingHttpHeaders = {
authorization: auth,
accept: 'application/vnd.github.VERSION.raw'
};
let fetchedDragonwellJson = await this.fetchJsonFromPrimaryUrl();

const fetchedDragonwellVersions = (
await this.http.getJson<IDragonwellAllVersions>(
availableVersionsUrl,
headers
)
).result;
if (!fetchedDragonwellJson) {
fetchedDragonwellJson = await this.fetchJsonFromBackupUrl();
}

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()) {
Expand Down Expand Up @@ -210,4 +195,53 @@ export class DragonwellDistribution extends JavaBase {
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;
}
}
}