mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 02:16:45 +00:00
Use archive as fallback only when dealing with major version
This commit is contained in:
parent
ebe05e0f88
commit
33b10b64eb
3 changed files with 79 additions and 25 deletions
|
@ -65,26 +65,48 @@ export class OracleDistribution extends JavaBase {
|
|||
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
const major = range.includes('.') ? range.split('.')[0] : range;
|
||||
const fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||
|
||||
const isOnlyMajorProvided = !range.includes('.');
|
||||
const major = isOnlyMajorProvided ? range : range.split('.')[0];
|
||||
|
||||
const possibleUrls: string[] = [];
|
||||
|
||||
/**
|
||||
* NOTE
|
||||
* If only major version was provided we will check it under /latest first
|
||||
* in order to retrieve the latest possible version if possible,
|
||||
* otherwise we will fall back to /archive where we are guaranteed to
|
||||
* find any version if it exists
|
||||
*/
|
||||
if (isOnlyMajorProvided) {
|
||||
possibleUrls.push(
|
||||
`${ORACLE_DL_BASE}/${major}/latest/jdk-${major}_${platform}-${arch}_bin.${extension}`
|
||||
);
|
||||
}
|
||||
|
||||
possibleUrls.push(
|
||||
`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`
|
||||
);
|
||||
|
||||
if (parseInt(major) < 17) {
|
||||
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
||||
}
|
||||
|
||||
const response = await this.http.head(fileUrl);
|
||||
for (const url of possibleUrls) {
|
||||
const response = await this.http.head(url);
|
||||
|
||||
if (response.message.statusCode === HttpCodes.NotFound) {
|
||||
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
|
||||
if (response.message.statusCode === HttpCodes.OK) {
|
||||
return {url, version: range};
|
||||
}
|
||||
|
||||
if (response.message.statusCode !== HttpCodes.NotFound) {
|
||||
throw new Error(
|
||||
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (response.message.statusCode !== HttpCodes.OK) {
|
||||
throw new Error(
|
||||
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
|
||||
);
|
||||
}
|
||||
|
||||
return {url: fileUrl, version: range};
|
||||
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
|
||||
}
|
||||
|
||||
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue