mirror of
https://github.com/actions/setup-java.git
synced 2026-06-13 15:52:15 +08:00
Make the Adoptopenjdk package type look at the Temurin repo first for latest assets (#522)
* Make the Adoptopenjdk package type look at the Temurin repo first for latest assets
* Address Copilot code review comments
- Use strict equality (===, !==) instead of loose equality (==, !=) for all comparisons
- Properly handle caught errors with instanceof type narrowing before accessing properties
- Only fall back to legacy AdoptOpenJDK for specific version-not-found errors
- Rethrow unexpected errors to avoid masking real issues (network failures, rate limits, etc.)
- Fix error message check to match actual error text ('No matching version found')
- Remove unnecessary undefined check since method return type is never undefined
- Add @internal JSDoc annotation to TemurinDistribution.findPackageForDownload()
- Update tests to properly mock Temurin lookup failures for fallback behavior testing
- Rebuild dist files
* Always fall back to legacy AdoptOpenJDK but log all Temurin failures
- Change error handling to gracefully fall back for all errors, not just version-not-found
- Log version-not-found errors as notices with migration guidance
- Log other Temurin failures as debug messages for troubleshooting
- Improves resilience: users always get a result even if Temurin API has issues
- Maintains visibility: failures are still logged for debugging
* Fixes from review
* Fixes from review
* Fixes from review
* Regenerate dist
This commit is contained in:
parent
43120bc3c3
commit
b24df5bba5
@ -4,6 +4,7 @@ import {
|
|||||||
AdoptDistribution,
|
AdoptDistribution,
|
||||||
AdoptImplementation
|
AdoptImplementation
|
||||||
} from '../../src/distributions/adopt/installer';
|
} from '../../src/distributions/adopt/installer';
|
||||||
|
import {TemurinDistribution} from '../../src/distributions/temurin/installer';
|
||||||
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||||
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
@ -256,6 +257,38 @@ describe('getAvailableVersions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
|
it('returns Temurin result and does not query Adopt API when Temurin succeeds', async () => {
|
||||||
|
const temurinRelease = {
|
||||||
|
version: '11.0.31+11',
|
||||||
|
url: 'https://example.test/temurin-11.tar.gz'
|
||||||
|
};
|
||||||
|
const temurinFindPackageForDownload = jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue(temurinRelease);
|
||||||
|
const temurinDistribution = {
|
||||||
|
findPackageForDownload: temurinFindPackageForDownload
|
||||||
|
} as unknown as TemurinDistribution;
|
||||||
|
|
||||||
|
const distribution = new AdoptDistribution(
|
||||||
|
{
|
||||||
|
version: '11',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
},
|
||||||
|
AdoptImplementation.Hotspot,
|
||||||
|
temurinDistribution
|
||||||
|
);
|
||||||
|
const adoptLookupSpy = jest.fn();
|
||||||
|
distribution['getAvailableVersions'] = adoptLookupSpy;
|
||||||
|
|
||||||
|
const resolvedVersion = await distribution['findPackageForDownload']('11');
|
||||||
|
|
||||||
|
expect(resolvedVersion).toEqual(temurinRelease);
|
||||||
|
expect(temurinFindPackageForDownload).toHaveBeenCalledWith('11');
|
||||||
|
expect(adoptLookupSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['9', '9.0.7+10'],
|
['9', '9.0.7+10'],
|
||||||
['15', '15.0.2+7'],
|
['15', '15.0.2+7'],
|
||||||
@ -278,6 +311,11 @@ describe('findPackageForDownload', () => {
|
|||||||
},
|
},
|
||||||
AdoptImplementation.Hotspot
|
AdoptImplementation.Hotspot
|
||||||
);
|
);
|
||||||
|
// Mock Temurin to fail so fallback to AdoptOpenJDK is tested
|
||||||
|
distribution['temurinDistribution']!['findPackageForDownload'] =
|
||||||
|
async () => {
|
||||||
|
throw new Error('No matching version found for SemVer');
|
||||||
|
};
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||||
expect(resolvedVersion.version).toBe(expected);
|
expect(resolvedVersion.version).toBe(expected);
|
||||||
@ -293,6 +331,11 @@ describe('findPackageForDownload', () => {
|
|||||||
},
|
},
|
||||||
AdoptImplementation.Hotspot
|
AdoptImplementation.Hotspot
|
||||||
);
|
);
|
||||||
|
// Mock Temurin to fail so fallback to AdoptOpenJDK is tested
|
||||||
|
distribution['temurinDistribution']!['findPackageForDownload'] =
|
||||||
|
async () => {
|
||||||
|
throw new Error('No matching version found for SemVer');
|
||||||
|
};
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||||
await expect(
|
await expect(
|
||||||
distribution['findPackageForDownload']('9.0.8')
|
distribution['findPackageForDownload']('9.0.8')
|
||||||
@ -309,6 +352,11 @@ describe('findPackageForDownload', () => {
|
|||||||
},
|
},
|
||||||
AdoptImplementation.Hotspot
|
AdoptImplementation.Hotspot
|
||||||
);
|
);
|
||||||
|
// Mock Temurin to fail so fallback to AdoptOpenJDK is tested
|
||||||
|
distribution['temurinDistribution']!['findPackageForDownload'] =
|
||||||
|
async () => {
|
||||||
|
throw new Error('No matching version found for SemVer');
|
||||||
|
};
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||||
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
|
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
|
||||||
/No matching version found for SemVer */
|
/No matching version found for SemVer */
|
||||||
@ -325,6 +373,11 @@ describe('findPackageForDownload', () => {
|
|||||||
},
|
},
|
||||||
AdoptImplementation.Hotspot
|
AdoptImplementation.Hotspot
|
||||||
);
|
);
|
||||||
|
// Mock Temurin to fail so fallback to AdoptOpenJDK is tested
|
||||||
|
distribution['temurinDistribution']!['findPackageForDownload'] =
|
||||||
|
async () => {
|
||||||
|
throw new Error('No matching version found for SemVer');
|
||||||
|
};
|
||||||
distribution['getAvailableVersions'] = async () => [];
|
distribution['getAvailableVersions'] = async () => [];
|
||||||
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
||||||
/No matching version found for SemVer */
|
/No matching version found for SemVer */
|
||||||
|
|||||||
46
dist/setup/index.js
vendored
46
dist/setup/index.js
vendored
@ -77815,17 +77815,54 @@ const path_1 = __importDefault(__nccwpck_require__(71017));
|
|||||||
const semver_1 = __importDefault(__nccwpck_require__(11383));
|
const semver_1 = __importDefault(__nccwpck_require__(11383));
|
||||||
const base_installer_1 = __nccwpck_require__(59741);
|
const base_installer_1 = __nccwpck_require__(59741);
|
||||||
const util_1 = __nccwpck_require__(92629);
|
const util_1 = __nccwpck_require__(92629);
|
||||||
|
const installer_1 = __nccwpck_require__(18579);
|
||||||
var AdoptImplementation;
|
var AdoptImplementation;
|
||||||
(function (AdoptImplementation) {
|
(function (AdoptImplementation) {
|
||||||
AdoptImplementation["Hotspot"] = "Hotspot";
|
AdoptImplementation["Hotspot"] = "Hotspot";
|
||||||
AdoptImplementation["OpenJ9"] = "OpenJ9";
|
AdoptImplementation["OpenJ9"] = "OpenJ9";
|
||||||
})(AdoptImplementation || (exports.AdoptImplementation = AdoptImplementation = {}));
|
})(AdoptImplementation || (exports.AdoptImplementation = AdoptImplementation = {}));
|
||||||
class AdoptDistribution extends base_installer_1.JavaBase {
|
class AdoptDistribution extends base_installer_1.JavaBase {
|
||||||
constructor(installerOptions, jvmImpl) {
|
constructor(installerOptions, jvmImpl, temurinDistribution = null) {
|
||||||
super(`Adopt-${jvmImpl}`, installerOptions);
|
super(`Adopt-${jvmImpl}`, installerOptions);
|
||||||
this.jvmImpl = jvmImpl;
|
this.jvmImpl = jvmImpl;
|
||||||
|
if (temurinDistribution !== null &&
|
||||||
|
jvmImpl !== AdoptImplementation.Hotspot) {
|
||||||
|
throw new Error('Only Hotspot JVM is supported by Temurin.');
|
||||||
|
}
|
||||||
|
// Only use the temurin repo for Hotspot JVMs
|
||||||
|
this.temurinDistribution =
|
||||||
|
temurinDistribution !== null && temurinDistribution !== void 0 ? temurinDistribution : (jvmImpl === AdoptImplementation.Hotspot
|
||||||
|
? new installer_1.TemurinDistribution(installerOptions, installer_1.TemurinImplementation.Hotspot)
|
||||||
|
: null);
|
||||||
}
|
}
|
||||||
findPackageForDownload(version) {
|
findPackageForDownload(version) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (this.jvmImpl === AdoptImplementation.Hotspot) {
|
||||||
|
core.notice("AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration.");
|
||||||
|
}
|
||||||
|
if (this.jvmImpl === AdoptImplementation.Hotspot &&
|
||||||
|
this.temurinDistribution !== null) {
|
||||||
|
try {
|
||||||
|
return yield this.temurinDistribution.findPackageForDownload(version);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// Log the failure but always fall back to legacy AdoptOpenJDK for resilience
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
if (error instanceof Error && error.name === 'VersionNotFoundError') {
|
||||||
|
core.notice('The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' +
|
||||||
|
'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Log other errors for debugging but gracefully fall back
|
||||||
|
core.debug(`Temurin lookup failed: ${errorMessage}. Falling back to AdoptOpenJDK API.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// failed to find a Temurin version, so fall back to AdoptOpenJDK
|
||||||
|
return this.findPackageForDownloadOldAdoptOpenJdk(version);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
findPackageForDownloadOldAdoptOpenJdk(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const availableVersionsRaw = yield this.getAvailableVersions();
|
const availableVersionsRaw = yield this.getAvailableVersions();
|
||||||
const availableVersionsWithBinaries = availableVersionsRaw
|
const availableVersionsWithBinaries = availableVersionsRaw
|
||||||
@ -78223,7 +78260,9 @@ class JavaBase {
|
|||||||
parts.push(`(showing first ${maxVersionsToShow} of ${availableVersions.length} versions, enable debug mode to see all)`);
|
parts.push(`(showing first ${maxVersionsToShow} of ${availableVersions.length} versions, enable debug mode to see all)`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Error(parts.join('\n'));
|
const error = new Error(parts.join('\n'));
|
||||||
|
error.name = 'VersionNotFoundError';
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
setJavaDefault(version, toolPath) {
|
setJavaDefault(version, toolPath) {
|
||||||
const majorVersion = version.split('.')[0];
|
const majorVersion = version.split('.')[0];
|
||||||
@ -80195,6 +80234,9 @@ class TemurinDistribution extends base_installer_1.JavaBase {
|
|||||||
super(`Temurin-${jvmImpl}`, installerOptions);
|
super(`Temurin-${jvmImpl}`, installerOptions);
|
||||||
this.jvmImpl = jvmImpl;
|
this.jvmImpl = jvmImpl;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @internal For cross-distribution reuse only. Not intended as a public API.
|
||||||
|
*/
|
||||||
findPackageForDownload(version) {
|
findPackageForDownload(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const availableVersionsRaw = yield this.getAvailableVersions();
|
const availableVersionsRaw = yield this.getAvailableVersions();
|
||||||
|
|||||||
15
package-lock.json
generated
15
package-lock.json
generated
@ -6470,21 +6470,6 @@
|
|||||||
"node": ">=16.0.0"
|
"node": ">=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/xml-naming": {
|
|
||||||
"version": "0.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.1.0.tgz",
|
|
||||||
"integrity": "sha512-k8KO9hrMyNk6tUWqUfkTEZbezRRpONVOzUTnc97VnCvyj6Tf9lyUR9EDAIeiVLv56jsMcoXEwjW8Kv5yPY52lw==",
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/NaturalIntelligence"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/xmlbuilder2": {
|
"node_modules/xmlbuilder2": {
|
||||||
"version": "4.0.3",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/xmlbuilder2/-/xmlbuilder2-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/xmlbuilder2/-/xmlbuilder2-4.0.3.tgz",
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import {
|
|||||||
MAX_PAGINATION_PAGES,
|
MAX_PAGINATION_PAGES,
|
||||||
validatePaginationUrl
|
validatePaginationUrl
|
||||||
} from '../../util';
|
} from '../../util';
|
||||||
|
import {TemurinDistribution, TemurinImplementation} from '../temurin/installer';
|
||||||
|
|
||||||
export enum AdoptImplementation {
|
export enum AdoptImplementation {
|
||||||
Hotspot = 'Hotspot',
|
Hotspot = 'Hotspot',
|
||||||
@ -28,15 +29,72 @@ export enum AdoptImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AdoptDistribution extends JavaBase {
|
export class AdoptDistribution extends JavaBase {
|
||||||
|
private readonly temurinDistribution: TemurinDistribution | null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
installerOptions: JavaInstallerOptions,
|
installerOptions: JavaInstallerOptions,
|
||||||
private readonly jvmImpl: AdoptImplementation
|
private readonly jvmImpl: AdoptImplementation,
|
||||||
|
temurinDistribution: TemurinDistribution | null = null
|
||||||
) {
|
) {
|
||||||
super(`Adopt-${jvmImpl}`, installerOptions);
|
super(`Adopt-${jvmImpl}`, installerOptions);
|
||||||
|
|
||||||
|
if (
|
||||||
|
temurinDistribution !== null &&
|
||||||
|
jvmImpl !== AdoptImplementation.Hotspot
|
||||||
|
) {
|
||||||
|
throw new Error('Only Hotspot JVM is supported by Temurin.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only use the temurin repo for Hotspot JVMs
|
||||||
|
this.temurinDistribution =
|
||||||
|
temurinDistribution ??
|
||||||
|
(jvmImpl === AdoptImplementation.Hotspot
|
||||||
|
? new TemurinDistribution(
|
||||||
|
installerOptions,
|
||||||
|
TemurinImplementation.Hotspot
|
||||||
|
)
|
||||||
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async findPackageForDownload(
|
protected async findPackageForDownload(
|
||||||
version: string
|
version: string
|
||||||
|
): Promise<JavaDownloadRelease> {
|
||||||
|
if (this.jvmImpl === AdoptImplementation.Hotspot) {
|
||||||
|
core.notice(
|
||||||
|
"AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.jvmImpl === AdoptImplementation.Hotspot &&
|
||||||
|
this.temurinDistribution !== null
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
return await this.temurinDistribution.findPackageForDownload(version);
|
||||||
|
} catch (error) {
|
||||||
|
// Log the failure but always fall back to legacy AdoptOpenJDK for resilience
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : String(error);
|
||||||
|
if (error instanceof Error && error.name === 'VersionNotFoundError') {
|
||||||
|
core.notice(
|
||||||
|
'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' +
|
||||||
|
'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Log other errors for debugging but gracefully fall back
|
||||||
|
core.debug(
|
||||||
|
`Temurin lookup failed: ${errorMessage}. Falling back to AdoptOpenJDK API.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// failed to find a Temurin version, so fall back to AdoptOpenJDK
|
||||||
|
return this.findPackageForDownloadOldAdoptOpenJdk(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async findPackageForDownloadOldAdoptOpenJdk(
|
||||||
|
version: string
|
||||||
): Promise<JavaDownloadRelease> {
|
): Promise<JavaDownloadRelease> {
|
||||||
const availableVersionsRaw = await this.getAvailableVersions();
|
const availableVersionsRaw = await this.getAvailableVersions();
|
||||||
const availableVersionsWithBinaries = availableVersionsRaw
|
const availableVersionsWithBinaries = availableVersionsRaw
|
||||||
|
|||||||
@ -292,7 +292,9 @@ export abstract class JavaBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Error(parts.join('\n'));
|
const error = new Error(parts.join('\n'));
|
||||||
|
error.name = 'VersionNotFoundError';
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setJavaDefault(version: string, toolPath: string) {
|
protected setJavaDefault(version: string, toolPath: string) {
|
||||||
|
|||||||
@ -34,7 +34,10 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
super(`Temurin-${jvmImpl}`, installerOptions);
|
super(`Temurin-${jvmImpl}`, installerOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async findPackageForDownload(
|
/**
|
||||||
|
* @internal For cross-distribution reuse only. Not intended as a public API.
|
||||||
|
*/
|
||||||
|
public async findPackageForDownload(
|
||||||
version: string
|
version: string
|
||||||
): Promise<JavaDownloadRelease> {
|
): Promise<JavaDownloadRelease> {
|
||||||
const availableVersionsRaw = await this.getAvailableVersions();
|
const availableVersionsRaw = await this.getAvailableVersions();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user