Fix JetBrains Runtime release pagination (#1218)

* Fix JetBrains release pagination

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Update setup distribution

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Bruno Borges <brborges@microsoft.com>
This commit is contained in:
Julien Dubois
2026-08-05 12:32:52 -04:00
committed by GitHub
co-authored by Copilot App Bruno Borges
parent 2b61aea53d
commit fb58a661f3
3 changed files with 226 additions and 50 deletions
+48 -29
View File
@@ -11,10 +11,21 @@ import {
JavaInstallerOptions,
JavaInstallerResults
} from '../base-models.js';
import {cacheJdkDir, extractJdkFile, isVersionSatisfies} from '../../util.js';
import {
cacheJdkDir,
extractJdkFile,
getNextPageUrlFromLinkHeader,
isVersionSatisfies,
MAX_PAGINATION_PAGES,
validatePaginationUrl
} from '../../util.js';
import {OutgoingHttpHeaders} from 'http';
import {HttpCodes} from '@actions/http-client';
const JETBRAINS_RELEASES_URL =
'https://api.github.com/repos/JetBrains/JetBrainsRuntime/releases?per_page=100';
const GITHUB_API_ORIGIN = 'https://api.github.com';
export class JetBrainsDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
super('JetBrains', installerOptions);
@@ -96,46 +107,54 @@ export class JetBrainsDistribution extends JavaBase {
console.time('Retrieving available versions for JBR took'); // eslint-disable-line no-console
}
// need to iterate through all pages to retrieve the list of all versions
// GitHub API doesn't provide way to retrieve the count of pages to iterate so infinity loop
let page_index = 1;
const rawVersions: IJetBrainsRawVersion[] = [];
const bearerToken = process.env.GITHUB_TOKEN;
const requestHeaders: OutgoingHttpHeaders = {};
if (bearerToken) {
requestHeaders['Authorization'] = `Bearer ${bearerToken}`;
}
let releasesUrl: string | null = JETBRAINS_RELEASES_URL;
let pageCount = 0;
while (true) {
const requestArguments = `per_page=100&page=${page_index}`;
const requestHeaders: OutgoingHttpHeaders = {};
if (core.isDebug()) {
core.debug(`Gathering available versions from '${releasesUrl}'`);
}
if (bearerToken) {
requestHeaders['Authorization'] = `Bearer ${bearerToken}`;
}
const rawUrl = `https://api.github.com/repos/JetBrains/JetBrainsRuntime/releases?${requestArguments}`;
if (core.isDebug() && page_index === 1) {
// url is identical except page_index so print it once for debug
core.debug(`Gathering available versions from '${rawUrl}'`);
}
const paginationPageResult = (
await this.http.getJson<IJetBrainsRawVersion[]>(rawUrl, requestHeaders)
).result;
while (releasesUrl) {
pageCount++;
const response = await this.http.getJson<IJetBrainsRawVersion[]>(
releasesUrl,
requestHeaders
);
const paginationPageResult = response.result;
if (!paginationPageResult || paginationPageResult.length === 0) {
// break infinity loop because we have reached end of pagination
break;
}
const paginationPage: IJetBrainsRawVersion[] =
paginationPageResult.filter(version =>
rawVersions.push(
...paginationPageResult.filter(version =>
this.stable ? !version.prerelease : version.prerelease
)
);
const nextUrl = getNextPageUrlFromLinkHeader(response.headers);
if (nextUrl && !validatePaginationUrl(nextUrl, GITHUB_API_ORIGIN)) {
core.warning(
`Ignoring pagination link with unexpected origin: ${nextUrl}`
);
if (!paginationPage || paginationPage.length === 0) {
// break infinity loop because we have reached end of pagination
break;
releasesUrl = null;
} else {
releasesUrl = nextUrl;
}
rawVersions.push(...paginationPage);
page_index++;
if (pageCount >= MAX_PAGINATION_PAGES) {
if (releasesUrl) {
core.warning(
`Reached pagination safeguard limit (${MAX_PAGINATION_PAGES} pages) while listing JetBrains Runtime releases.`
);
}
break;
}
}
if (this.stable) {