mirror of
https://github.com/actions/setup-python.git
synced 2026-01-21 05:38:54 +08:00
Utilize pagination when querying GraalPy GitHub releases
This commit is contained in:
parent
62fe528f26
commit
feb18948f5
3 changed files with 64 additions and 10 deletions
|
|
@ -14,7 +14,8 @@ import {
|
|||
IGraalPyManifestRelease,
|
||||
createSymlinkInFolder,
|
||||
isNightlyKeyword,
|
||||
getBinaryDirectory
|
||||
getBinaryDirectory,
|
||||
getNextPageUrl
|
||||
} from './utils';
|
||||
|
||||
const TOKEN = core.getInput('token');
|
||||
|
|
@ -106,7 +107,6 @@ export async function installGraalPy(
|
|||
}
|
||||
|
||||
export async function getAvailableGraalPyVersions() {
|
||||
const url = 'https://api.github.com/repos/oracle/graalpython/releases';
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache');
|
||||
|
||||
let headers: ifm.IHeaders = {};
|
||||
|
|
@ -114,14 +114,22 @@ export async function getAvailableGraalPyVersions() {
|
|||
headers.authorization = AUTH;
|
||||
}
|
||||
|
||||
const response = await http.getJson<IGraalPyManifestRelease[]>(url, headers);
|
||||
if (!response.result) {
|
||||
throw new Error(
|
||||
`Unable to retrieve the list of available GraalPy versions from '${url}'`
|
||||
);
|
||||
}
|
||||
let url: string | null =
|
||||
'https://api.github.com/repos/oracle/graalpython/releases';
|
||||
const result: IGraalPyManifestRelease[] = [];
|
||||
do {
|
||||
const response: ifm.ITypedResponse<IGraalPyManifestRelease[]> =
|
||||
await http.getJson(url, headers);
|
||||
if (!response.result) {
|
||||
throw new Error(
|
||||
`Unable to retrieve the list of available GraalPy versions from '${url}'`
|
||||
);
|
||||
}
|
||||
result.push(...response.result);
|
||||
url = getNextPageUrl(response);
|
||||
} while (url);
|
||||
|
||||
return response.result;
|
||||
return result;
|
||||
}
|
||||
|
||||
async function createGraalPySymlink(
|
||||
|
|
|
|||
23
src/utils.ts
23
src/utils.ts
|
|
@ -6,6 +6,7 @@ import * as path from 'path';
|
|||
import * as semver from 'semver';
|
||||
import * as toml from '@iarna/toml';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as ifm from '@actions/http-client/interfaces';
|
||||
|
||||
export const IS_WINDOWS = process.platform === 'win32';
|
||||
export const IS_LINUX = process.platform === 'linux';
|
||||
|
|
@ -271,3 +272,25 @@ export function getVersionInputFromFile(versionFile: string): string[] {
|
|||
export function getBinaryDirectory(installDir: string) {
|
||||
return IS_WINDOWS ? installDir : path.join(installDir, 'bin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract next page URL from a HTTP response "link" header. Such headers are used in GitHub APIs.
|
||||
*/
|
||||
export function getNextPageUrl<T>(response: ifm.ITypedResponse<T>) {
|
||||
const responseHeaders = <ifm.IHeaders>response.headers;
|
||||
const linkHeader = responseHeaders.link;
|
||||
if (typeof linkHeader === 'string') {
|
||||
for (let link of linkHeader.split(/\s*,\s*/)) {
|
||||
const match = link.match(/<([^>]+)>(.*)/);
|
||||
if (match) {
|
||||
const url = match[1];
|
||||
for (let param of match[2].split(/\s*;\s*/)) {
|
||||
if (param.match(/rel="?next"?/)) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue