mirror of
https://github.com/actions/setup-java.git
synced 2026-06-22 11:57:44 +00:00
Move pagination safeguard to non-JetBrains installers
This commit is contained in:
parent
a22487fd8c
commit
3b472a4e31
@ -14,6 +14,7 @@ import * as core from '@actions/core';
|
|||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: jest.SpyInstance;
|
let spyHttpClient: jest.SpyInstance;
|
||||||
let spyCoreError: jest.SpyInstance;
|
let spyCoreError: jest.SpyInstance;
|
||||||
|
let spyCoreWarning: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||||
@ -26,6 +27,8 @@ describe('getAvailableVersions', () => {
|
|||||||
// Mock core.error to suppress error logs
|
// Mock core.error to suppress error logs
|
||||||
spyCoreError = jest.spyOn(core, 'error');
|
spyCoreError = jest.spyOn(core, 'error');
|
||||||
spyCoreError.mockImplementation(() => {});
|
spyCoreError.mockImplementation(() => {});
|
||||||
|
spyCoreWarning = jest.spyOn(core, 'warning');
|
||||||
|
spyCoreWarning.mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -166,6 +169,32 @@ describe('getAvailableVersions', () => {
|
|||||||
expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl);
|
expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stops pagination after 1000 pages as a safeguard', async () => {
|
||||||
|
const nextPageUrl = 'https://example.com/releases?page=2';
|
||||||
|
spyHttpClient.mockReturnValue({
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {link: `<${nextPageUrl}>; rel="next"`},
|
||||||
|
result: [{version_data: {semver: '17.0.1'}, binaries: []}] as any
|
||||||
|
});
|
||||||
|
|
||||||
|
const distribution = new AdoptDistribution(
|
||||||
|
{
|
||||||
|
version: '11',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
},
|
||||||
|
AdoptImplementation.Hotspot
|
||||||
|
);
|
||||||
|
|
||||||
|
await distribution['getAvailableVersions']();
|
||||||
|
|
||||||
|
expect(spyHttpClient).toHaveBeenCalledTimes(1000);
|
||||||
|
expect(spyCoreWarning).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('Reached pagination safeguard limit (1000 pages)')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[AdoptImplementation.Hotspot, 'jdk', 'Java_Adopt_jdk'],
|
[AdoptImplementation.Hotspot, 'jdk', 'Java_Adopt_jdk'],
|
||||||
[AdoptImplementation.Hotspot, 'jre', 'Java_Adopt_jre'],
|
[AdoptImplementation.Hotspot, 'jre', 'Java_Adopt_jre'],
|
||||||
|
|||||||
@ -9,8 +9,6 @@ import * as core from '@actions/core';
|
|||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: jest.SpyInstance;
|
let spyHttpClient: jest.SpyInstance;
|
||||||
let spyCoreError: jest.SpyInstance;
|
let spyCoreError: jest.SpyInstance;
|
||||||
let spyCoreWarning: jest.SpyInstance;
|
|
||||||
let spyHeadRequest: jest.SpyInstance;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||||
@ -23,14 +21,6 @@ describe('getAvailableVersions', () => {
|
|||||||
// Mock core.error to suppress error logs
|
// Mock core.error to suppress error logs
|
||||||
spyCoreError = jest.spyOn(core, 'error');
|
spyCoreError = jest.spyOn(core, 'error');
|
||||||
spyCoreError.mockImplementation(() => {});
|
spyCoreError.mockImplementation(() => {});
|
||||||
spyCoreWarning = jest.spyOn(core, 'warning');
|
|
||||||
spyCoreWarning.mockImplementation(() => {});
|
|
||||||
spyHeadRequest = jest.spyOn(HttpClient.prototype, 'head');
|
|
||||||
spyHeadRequest.mockResolvedValue({
|
|
||||||
message: {
|
|
||||||
statusCode: 404
|
|
||||||
}
|
|
||||||
} as any);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -60,27 +50,6 @@ describe('getAvailableVersions', () => {
|
|||||||
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
|
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
|
||||||
expect(availableVersions.length).toBe(length);
|
expect(availableVersions.length).toBe(length);
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
|
|
||||||
it('stops pagination after 1000 pages as a safeguard', async () => {
|
|
||||||
spyHttpClient.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: [{tag_name: 'jbr17-b87.7', name: 'jbr17-b87.7', prerelease: false}]
|
|
||||||
});
|
|
||||||
|
|
||||||
const distribution = new JetBrainsDistribution({
|
|
||||||
version: '17',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
await distribution['getAvailableVersions']();
|
|
||||||
|
|
||||||
expect(spyHttpClient).toHaveBeenCalledTimes(1000);
|
|
||||||
expect(spyCoreWarning).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining('Reached pagination safeguard limit (1000 pages)')
|
|
||||||
);
|
|
||||||
}, 20_000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import * as core from '@actions/core';
|
|||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: jest.SpyInstance;
|
let spyHttpClient: jest.SpyInstance;
|
||||||
let spyCoreError: jest.SpyInstance;
|
let spyCoreError: jest.SpyInstance;
|
||||||
|
let spyCoreWarning: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||||
@ -20,6 +21,8 @@ describe('getAvailableVersions', () => {
|
|||||||
// Mock core.error to suppress error logs
|
// Mock core.error to suppress error logs
|
||||||
spyCoreError = jest.spyOn(core, 'error');
|
spyCoreError = jest.spyOn(core, 'error');
|
||||||
spyCoreError.mockImplementation(() => {});
|
spyCoreError.mockImplementation(() => {});
|
||||||
|
spyCoreWarning = jest.spyOn(core, 'warning');
|
||||||
|
spyCoreWarning.mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -109,6 +112,29 @@ describe('getAvailableVersions', () => {
|
|||||||
expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl);
|
expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stops pagination after 1000 pages as a safeguard', async () => {
|
||||||
|
const nextPageUrl = 'https://example.com/releases?page=2';
|
||||||
|
spyHttpClient.mockReturnValue({
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {link: `<${nextPageUrl}>; rel="next"`},
|
||||||
|
result: [{version_data: {semver: '17.0.1'}, binaries: []}] as any
|
||||||
|
});
|
||||||
|
|
||||||
|
const distribution = new SemeruDistribution({
|
||||||
|
version: '8',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
|
||||||
|
await distribution['getAvailableVersions']();
|
||||||
|
|
||||||
|
expect(spyHttpClient).toHaveBeenCalledTimes(1000);
|
||||||
|
expect(spyCoreWarning).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('Reached pagination safeguard limit (1000 pages)')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['jdk', 'Java_IBM_Semeru_jdk'],
|
['jdk', 'Java_IBM_Semeru_jdk'],
|
||||||
['jre', 'Java_IBM_Semeru_jre']
|
['jre', 'Java_IBM_Semeru_jre']
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import * as core from '@actions/core';
|
|||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: jest.SpyInstance;
|
let spyHttpClient: jest.SpyInstance;
|
||||||
let spyCoreError: jest.SpyInstance;
|
let spyCoreError: jest.SpyInstance;
|
||||||
|
let spyCoreWarning: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||||
@ -23,6 +24,8 @@ describe('getAvailableVersions', () => {
|
|||||||
// Mock core.error to suppress error logs
|
// Mock core.error to suppress error logs
|
||||||
spyCoreError = jest.spyOn(core, 'error');
|
spyCoreError = jest.spyOn(core, 'error');
|
||||||
spyCoreError.mockImplementation(() => {});
|
spyCoreError.mockImplementation(() => {});
|
||||||
|
spyCoreWarning = jest.spyOn(core, 'warning');
|
||||||
|
spyCoreWarning.mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -123,6 +126,32 @@ describe('getAvailableVersions', () => {
|
|||||||
expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl);
|
expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stops pagination after 1000 pages as a safeguard', async () => {
|
||||||
|
const nextPageUrl = 'https://example.com/releases?page=2';
|
||||||
|
spyHttpClient.mockReturnValue({
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {link: `<${nextPageUrl}>; rel="next"`},
|
||||||
|
result: [{version_data: {semver: '17.0.1'}, binaries: []}] as any
|
||||||
|
});
|
||||||
|
|
||||||
|
const distribution = new TemurinDistribution(
|
||||||
|
{
|
||||||
|
version: '8',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
},
|
||||||
|
TemurinImplementation.Hotspot
|
||||||
|
);
|
||||||
|
|
||||||
|
await distribution['getAvailableVersions']();
|
||||||
|
|
||||||
|
expect(spyHttpClient).toHaveBeenCalledTimes(1000);
|
||||||
|
expect(spyCoreWarning).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('Reached pagination safeguard limit (1000 pages)')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[TemurinImplementation.Hotspot, 'jdk', 'Java_Temurin-Hotspot_jdk'],
|
[TemurinImplementation.Hotspot, 'jdk', 'Java_Temurin-Hotspot_jdk'],
|
||||||
[TemurinImplementation.Hotspot, 'jre', 'Java_Temurin-Hotspot_jre']
|
[TemurinImplementation.Hotspot, 'jre', 'Java_Temurin-Hotspot_jre']
|
||||||
|
|||||||
@ -20,6 +20,8 @@ import {
|
|||||||
renameWinArchive
|
renameWinArchive
|
||||||
} from '../../util';
|
} from '../../util';
|
||||||
|
|
||||||
|
const MAX_PAGINATION_PAGES = 1000;
|
||||||
|
|
||||||
export enum AdoptImplementation {
|
export enum AdoptImplementation {
|
||||||
Hotspot = 'Hotspot',
|
Hotspot = 'Hotspot',
|
||||||
OpenJ9 = 'OpenJ9'
|
OpenJ9 = 'OpenJ9'
|
||||||
@ -129,11 +131,13 @@ export class AdoptDistribution extends JavaBase {
|
|||||||
const requestArguments = `${baseRequestArguments}&page_size=20&page=0`;
|
const requestArguments = `${baseRequestArguments}&page_size=20&page=0`;
|
||||||
let availableVersionsUrl: string | null = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
let availableVersionsUrl: string | null = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
||||||
const availableVersions: IAdoptAvailableVersions[] = [];
|
const availableVersions: IAdoptAvailableVersions[] = [];
|
||||||
|
let pageCount = 0;
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (availableVersionsUrl) {
|
while (availableVersionsUrl) {
|
||||||
|
pageCount++;
|
||||||
const response =
|
const response =
|
||||||
await this.http.getJson<IAdoptAvailableVersions[]>(availableVersionsUrl);
|
await this.http.getJson<IAdoptAvailableVersions[]>(availableVersionsUrl);
|
||||||
const paginationPage = response.result;
|
const paginationPage = response.result;
|
||||||
@ -143,6 +147,13 @@ export class AdoptDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
availableVersions.push(...paginationPage);
|
availableVersions.push(...paginationPage);
|
||||||
|
|
||||||
|
if (pageCount >= MAX_PAGINATION_PAGES && availableVersionsUrl) {
|
||||||
|
core.warning(
|
||||||
|
`Reached pagination safeguard limit (${MAX_PAGINATION_PAGES} pages) while listing Adopt releases.`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
|
|||||||
@ -16,8 +16,6 @@ import {extractJdkFile, isVersionSatisfies} from '../../util';
|
|||||||
import {OutgoingHttpHeaders} from 'http';
|
import {OutgoingHttpHeaders} from 'http';
|
||||||
import {HttpCodes} from '@actions/http-client';
|
import {HttpCodes} from '@actions/http-client';
|
||||||
|
|
||||||
const MAX_PAGINATION_PAGES = 1000;
|
|
||||||
|
|
||||||
export class JetBrainsDistribution extends JavaBase {
|
export class JetBrainsDistribution extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
super('JetBrains', installerOptions);
|
super('JetBrains', installerOptions);
|
||||||
@ -95,7 +93,7 @@ export class JetBrainsDistribution extends JavaBase {
|
|||||||
const rawVersions: IJetBrainsRawVersion[] = [];
|
const rawVersions: IJetBrainsRawVersion[] = [];
|
||||||
const bearerToken = process.env.GITHUB_TOKEN;
|
const bearerToken = process.env.GITHUB_TOKEN;
|
||||||
|
|
||||||
while (page_index <= MAX_PAGINATION_PAGES) {
|
while (true) {
|
||||||
const requestArguments = `per_page=100&page=${page_index}`;
|
const requestArguments = `per_page=100&page=${page_index}`;
|
||||||
const requestHeaders: OutgoingHttpHeaders = {};
|
const requestHeaders: OutgoingHttpHeaders = {};
|
||||||
|
|
||||||
@ -131,12 +129,6 @@ export class JetBrainsDistribution extends JavaBase {
|
|||||||
page_index++;
|
page_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page_index > MAX_PAGINATION_PAGES) {
|
|
||||||
core.warning(
|
|
||||||
`Reached pagination safeguard limit (${MAX_PAGINATION_PAGES} pages) while listing JetBrains runtime releases.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.stable) {
|
if (this.stable) {
|
||||||
// Add versions not available from the API but are downloadable
|
// Add versions not available from the API but are downloadable
|
||||||
const hidden = ['11_0_10b1145.115', '11_0_11b1341.60'];
|
const hidden = ['11_0_10b1145.115', '11_0_11b1341.60'];
|
||||||
|
|||||||
@ -18,6 +18,8 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {ISemeruAvailableVersions} from './models';
|
import {ISemeruAvailableVersions} from './models';
|
||||||
|
|
||||||
|
const MAX_PAGINATION_PAGES = 1000;
|
||||||
|
|
||||||
const supportedArchitectures = [
|
const supportedArchitectures = [
|
||||||
'x64',
|
'x64',
|
||||||
'x86',
|
'x86',
|
||||||
@ -159,11 +161,13 @@ export class SemeruDistribution extends JavaBase {
|
|||||||
const requestArguments = `${baseRequestArguments}&page_size=20&page=0`;
|
const requestArguments = `${baseRequestArguments}&page_size=20&page=0`;
|
||||||
let availableVersionsUrl: string | null = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
let availableVersionsUrl: string | null = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
||||||
const availableVersions: ISemeruAvailableVersions[] = [];
|
const availableVersions: ISemeruAvailableVersions[] = [];
|
||||||
|
let pageCount = 0;
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (availableVersionsUrl) {
|
while (availableVersionsUrl) {
|
||||||
|
pageCount++;
|
||||||
const response = await this.http.getJson<ISemeruAvailableVersions[]>(
|
const response = await this.http.getJson<ISemeruAvailableVersions[]>(
|
||||||
availableVersionsUrl
|
availableVersionsUrl
|
||||||
);
|
);
|
||||||
@ -174,6 +178,13 @@ export class SemeruDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
availableVersions.push(...paginationPage);
|
availableVersions.push(...paginationPage);
|
||||||
|
|
||||||
|
if (pageCount >= MAX_PAGINATION_PAGES && availableVersionsUrl) {
|
||||||
|
core.warning(
|
||||||
|
`Reached pagination safeguard limit (${MAX_PAGINATION_PAGES} pages) while listing Semeru releases.`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
|
|||||||
@ -20,6 +20,8 @@ import {
|
|||||||
renameWinArchive
|
renameWinArchive
|
||||||
} from '../../util';
|
} from '../../util';
|
||||||
|
|
||||||
|
const MAX_PAGINATION_PAGES = 1000;
|
||||||
|
|
||||||
export enum TemurinImplementation {
|
export enum TemurinImplementation {
|
||||||
Hotspot = 'Hotspot'
|
Hotspot = 'Hotspot'
|
||||||
}
|
}
|
||||||
@ -127,11 +129,13 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
const requestArguments = `${baseRequestArguments}&page_size=20&page=0`;
|
const requestArguments = `${baseRequestArguments}&page_size=20&page=0`;
|
||||||
let availableVersionsUrl: string | null = `https://api.adoptium.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
let availableVersionsUrl: string | null = `https://api.adoptium.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
||||||
const availableVersions: ITemurinAvailableVersions[] = [];
|
const availableVersions: ITemurinAvailableVersions[] = [];
|
||||||
|
let pageCount = 0;
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (availableVersionsUrl) {
|
while (availableVersionsUrl) {
|
||||||
|
pageCount++;
|
||||||
const response = await this.http.getJson<ITemurinAvailableVersions[]>(
|
const response = await this.http.getJson<ITemurinAvailableVersions[]>(
|
||||||
availableVersionsUrl
|
availableVersionsUrl
|
||||||
);
|
);
|
||||||
@ -143,6 +147,13 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
availableVersions.push(...paginationPage);
|
availableVersions.push(...paginationPage);
|
||||||
|
|
||||||
|
if (pageCount >= MAX_PAGINATION_PAGES && availableVersionsUrl) {
|
||||||
|
core.warning(
|
||||||
|
`Reached pagination safeguard limit (${MAX_PAGINATION_PAGES} pages) while listing Temurin releases.`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user