Compare commits

...

5 Commits

Author SHA1 Message Date
Bruno Borges
3f1ca98f01 Make OpenJDK tests platform independent
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2c93ae0c-bbf5-40f5-bf6e-40168d0e267f
2026-07-28 15:23:20 -04:00
Bruno Borges
25b4db53ec Rename OpenJDK distribution to oracle-openjdk
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2c93ae0c-bbf5-40f5-bf6e-40168d0e267f
2026-07-28 15:23:19 -04:00
Bruno Borges
97050e97fa Merge branch 'main' into copilot/add-openjdk-jdk-distribution 2026-07-28 15:20:54 -04:00
Copilot
089b010dc8 Add force-download option for reproducible JDK builds (#1148)
* Initial plan

* Add force-download input

* Build force-download action bundles

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Bruno Borges <brborges@microsoft.com>
2026-07-28 14:43:47 -04:00
Copilot
e07d36bbdd Set GRAALVM_HOME for GraalVM distributions (#1146)
* Initial plan

* Set GRAALVM_HOME for GraalVM distributions

* Rebuild setup action bundle

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-07-27 22:27:24 -04:00
16 changed files with 144 additions and 23 deletions

View File

@@ -56,6 +56,8 @@ For more details, see the full release notes on the [releases page](https://git
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
- `force-download`: Set to `true` to always download Java and replace any matching version in the tool cache. This can help make builds reproducible when a runner image has modified a pre-installed JDK, such as its `cacerts` file. Default value: `false`.
- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `true`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.
- `problem-matcher`: Set to `false` to disable Java problem matcher annotations (compiler diagnostics and uncaught exceptions). Default value: `true`. See [Java problem matcher](docs/advanced-usage.md#java-problem-matcher-compiler-annotations) for details and annotation limits.
@@ -146,7 +148,7 @@ Currently, the following distributions are supported:
| `corretto` | [Amazon Corretto Build of OpenJDK](https://aws.amazon.com/corretto/) | [`corretto` license](https://aws.amazon.com/corretto/faqs/)
| `semeru` | [IBM Semeru Runtime Open Edition](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) | [`semeru` license](https://openjdk.java.net/legal/gplv2+ce.html) |
| `oracle` | [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) | [`oracle` license](https://java.com/freeuselicense)
| `openjdk` | [OpenJDK](https://jdk.java.net/) | [`openjdk` license](https://openjdk.org/legal/gplv2+ce.html)
| `oracle-openjdk` | [Oracle OpenJDK](https://jdk.java.net/) | [`oracle-openjdk` license](https://openjdk.org/legal/gplv2+ce.html)
| `dragonwell` | [Alibaba Dragonwell JDK](https://dragonwell-jdk.io/) | [`dragonwell` license](https://www.aliyun.com/product/dragonwell/)
| `sapmachine` | [SAP SapMachine JDK/JRE](https://sapmachine.io/) | [`sapmachine` license](https://github.com/SAP/SapMachine/blob/sapmachine/LICENSE)
| `graalvm` | [Oracle GraalVM](https://www.graalvm.org/) | [`graalvm` license](https://www.oracle.com/downloads/licenses/graal-free-license.html)
@@ -158,6 +160,7 @@ Currently, the following distributions are supported:
> [!NOTE]
> - The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
> - AdoptOpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` and `adopt-openj9`, to `temurin` and `semeru` respectively, to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
> - Oracle OpenJDK builds are created and hosted by Oracle under GPLv2+CE. After a limited number of releases, Oracle archives these builds and no longer provides security updates. To continue receiving security patches, users must move to Oracle JDK or choose a different vendor.
> - For Azul Zulu OpenJDK, architecture `arm64` is mapped to `aarch64` when querying the Azul Metadata API.
> - To comply with the GraalVM Free Terms and Conditions (GFTC) license, it is recommended to use GraalVM JDK 17 version 17.0.12, as this is the only version of GraalVM JDK 17 available under the GFTC license. Additionally, it is encouraged to consider upgrading to GraalVM JDK 21, which offers the latest features and improvements.
> - GraalVM Community is available as `distribution: 'graalvm-community'` for stable JDK 17 and later releases published on GitHub.

View File

@@ -443,6 +443,35 @@ describe('setupJava', () => {
);
});
it('should download java when force-download is enabled, even if the version is cached', async () => {
mockJavaBase = new EmptyJavaBase({
version: actualJavaVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false,
forceDownload: true
});
const findInToolcache = jest.fn(() => ({
version: actualJavaVersion,
path: javaPathInstalled
}));
mockJavaBase['findInToolcache'] = findInToolcache;
await expect(mockJavaBase.setupJava()).resolves.toEqual({
version: actualJavaVersion,
path: javaPathInstalled
});
expect(findInToolcache).not.toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
expect(spyCoreInfo).toHaveBeenCalledWith(
`Java ${actualJavaVersion} was downloaded`
);
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
});
it.each([
[
{

View File

@@ -166,6 +166,29 @@ describe('GraalVMDistribution', () => {
});
});
describe('setJavaDefault', () => {
it('should set GRAALVM_HOME for Oracle GraalVM', () => {
(distribution as any).setJavaDefault('17.0.5', '/cached/java/path');
expect(core.exportVariable).toHaveBeenCalledWith(
'GRAALVM_HOME',
'/cached/java/path'
);
});
it('should set GRAALVM_HOME for GraalVM Community', () => {
(communityDistribution as any).setJavaDefault(
'17.0.5',
'/cached/java/path'
);
expect(core.exportVariable).toHaveBeenCalledWith(
'GRAALVM_HOME',
'/cached/java/path'
);
});
});
describe('downloadTool', () => {
const javaRelease = {
version: '17.0.5',

View File

@@ -208,6 +208,29 @@ describe('setupJava', () => {
);
});
it('java is unpacked from jdkfile when force-download is enabled', async () => {
const inputs = {
version: actualJavaVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false,
forceDownload: true
};
mockJavaBase = new LocalDistribution(inputs, expectedJdkFile);
await expect(mockJavaBase.setupJava()).resolves.toEqual({
version: actualJavaVersion,
path: javaPath
});
expect(spyGetToolcachePath).not.toHaveBeenCalled();
expect(spyUtilsExtractJdkFile).toHaveBeenCalledWith(expectedJdkFile);
expect(spyTcCacheDir).toHaveBeenCalled();
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
});
it("java is resolved from toolcache, jdkfile doesn't exist", async () => {
const inputs = {
version: actualJavaVersion,

View File

@@ -54,14 +54,19 @@ const archivePage = `
function createDistribution(
version = '26',
architecture = 'x64',
packageType = 'jdk'
packageType = 'jdk',
useFixturePlatform = true
) {
return new OpenJdkDistribution({
const distribution = new OpenJdkDistribution({
version,
architecture,
packageType,
checkLatest: false
});
if (useFixturePlatform) {
distribution['getPlatform'] = jest.fn(() => 'linux');
}
return distribution;
}
describe('OpenJdkDistribution', () => {
@@ -148,13 +153,13 @@ describe('OpenJdkDistribution', () => {
await expect(
createDistribution()['findPackageForDownload']('24')
).rejects.toThrow(
"No matching version found for SemVer '24'.\nDistribution: OpenJDK"
"No matching version found for SemVer '24'.\nDistribution: Oracle OpenJDK"
);
});
it.each([
['jre', 'OpenJDK provides only the `jdk` package type'],
['jdk+fx', 'OpenJDK provides only the `jdk` package type']
['jre', 'Oracle OpenJDK provides only the `jdk` package type'],
['jdk+fx', 'Oracle OpenJDK provides only the `jdk` package type']
])('rejects the %s package type', async (packageType, message) => {
await expect(
createDistribution('26', 'x64', packageType)['findPackageForDownload'](
@@ -170,7 +175,7 @@ describe('OpenJdkDistribution', () => {
});
it('maps supported platforms', () => {
const distribution = createDistribution();
const distribution = createDistribution('26', 'x64', 'jdk', false);
expect(distribution['getPlatform']('linux')).toBe('linux');
expect(distribution['getPlatform']('darwin')).toBe('macos');
@@ -199,7 +204,7 @@ describe('OpenJdkDistribution', () => {
});
it('is registered in the distribution factory', () => {
const distribution = getJavaDistribution('openjdk', {
const distribution = getJavaDistribution('oracle-openjdk', {
version: '26',
architecture: 'x64',
packageType: 'jdk',

View File

@@ -30,6 +30,10 @@ inputs:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
required: false
default: false
force-download:
description: 'Set this option to always download Java and replace any matching version in the tool cache'
required: false
default: false
set-default:
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.'
required: false

View File

@@ -97311,6 +97311,7 @@ const INPUT_DISTRIBUTION = 'distribution';
const INPUT_JDK_FILE = 'jdk-file';
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
const INPUT_CHECK_LATEST = 'check-latest';
const INPUT_FORCE_DOWNLOAD = 'force-download';
const INPUT_SET_DEFAULT = 'set-default';
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
const INPUT_VERIFY_SIGNATURE = 'verify-signature';

28
dist/setup/index.js vendored
View File

@@ -72088,6 +72088,7 @@ const INPUT_DISTRIBUTION = 'distribution';
const INPUT_JDK_FILE = 'jdk-file';
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
const INPUT_CHECK_LATEST = 'check-latest';
const INPUT_FORCE_DOWNLOAD = 'force-download';
const INPUT_SET_DEFAULT = 'set-default';
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
@@ -129290,6 +129291,7 @@ class JavaBase {
stable;
latest;
checkLatest;
forceDownload;
setDefault;
verifySignature;
verifySignaturePublicKey;
@@ -129307,6 +129309,7 @@ class JavaBase {
this.architecture = installerOptions.architecture || external_os_default().arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.forceDownload = installerOptions.forceDownload ?? false;
this.setDefault =
installerOptions.setDefault !== undefined
? installerOptions.setDefault
@@ -129318,7 +129321,7 @@ class JavaBase {
if (this.verifySignature && !this.supportsSignatureVerification()) {
throw new Error(`Input 'verify-signature' is not supported for distribution '${this.distribution}'.`);
}
let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava && !this.checkLatest && !this.latest) {
info(`Resolved Java ${foundJava.version} from tool-cache`);
}
@@ -129342,7 +129345,8 @@ class JavaBase {
}
const javaRelease = await this.findPackageForDownload(this.version);
info(`Resolved latest version as ${javaRelease.version}`);
if (foundJava?.version === javaRelease.version) {
if (!this.forceDownload &&
foundJava?.version === javaRelease.version) {
info(`Resolved Java ${foundJava.version} from tool-cache`);
}
else {
@@ -129617,7 +129621,7 @@ class LocalDistribution extends JavaBase {
if (this.latest) {
throw new Error("The 'latest' version alias is not supported for the 'jdkfile' distribution. Please specify a concrete version.");
}
let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava) {
info(`Resolved Java ${foundJava.version} from tool-cache`);
}
@@ -131328,6 +131332,10 @@ class GraalVMDistribution extends JavaBase {
throw error;
}
}
setJavaDefault(version, toolPath) {
super.setJavaDefault(version, toolPath);
exportVariable('GRAALVM_HOME', toolPath);
}
async findPackageForDownload(range) {
this.validateVersionRange(range);
const arch = this.getSupportedArchitecture();
@@ -131885,11 +131893,11 @@ class KonaDistribution extends JavaBase {
const OPENJDK_BASE_URL = 'https://jdk.java.net';
class OpenJdkDistribution extends JavaBase {
constructor(installerOptions) {
super('OpenJDK', installerOptions);
super('Oracle OpenJDK', installerOptions);
}
async findPackageForDownload(range) {
if (this.packageType !== 'jdk') {
throw new Error('OpenJDK provides only the `jdk` package type');
throw new Error('Oracle OpenJDK provides only the `jdk` package type');
}
const arch = this.distributionArchitecture();
if (!['x64', 'aarch64'].includes(arch)) {
@@ -132014,7 +132022,7 @@ var JavaDistribution;
JavaDistribution["GraalVMCommunity"] = "graalvm-community";
JavaDistribution["JetBrains"] = "jetbrains";
JavaDistribution["Kona"] = "kona";
JavaDistribution["OpenJdk"] = "openjdk";
JavaDistribution["OracleOpenJdk"] = "oracle-openjdk";
})(JavaDistribution || (JavaDistribution = {}));
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
switch (distributionName) {
@@ -132053,7 +132061,7 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
return new JetBrainsDistribution(installerOptions);
case JavaDistribution.Kona:
return new KonaDistribution(installerOptions);
case JavaDistribution.OpenJdk:
case JavaDistribution.OracleOpenJdk:
return new OpenJdkDistribution(installerOptions);
default:
return null;
@@ -132144,6 +132152,7 @@ async function run() {
const cache = getInput(INPUT_CACHE);
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
const forceDownload = util_getBooleanInput(INPUT_FORCE_DOWNLOAD, false);
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
@@ -132175,6 +132184,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
@@ -132193,6 +132203,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
@@ -132227,11 +132238,12 @@ function getJdkFileInput() {
return jdkFile || deprecatedJdkFile;
}
async function installVersion(version, options, toolchainId = 0) {
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
const { distributionName, jdkFile, architecture, packageType, checkLatest, forceDownload, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
const installerOptions = {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,

View File

@@ -7,6 +7,7 @@ export const INPUT_DISTRIBUTION = 'distribution';
export const INPUT_JDK_FILE = 'jdk-file';
export const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
export const INPUT_CHECK_LATEST = 'check-latest';
export const INPUT_FORCE_DOWNLOAD = 'force-download';
export const INPUT_SET_DEFAULT = 'set-default';
export const INPUT_PROBLEM_MATCHER = 'problem-matcher';
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';

View File

@@ -25,6 +25,7 @@ export abstract class JavaBase {
protected stable: boolean;
protected latest: boolean;
protected checkLatest: boolean;
protected forceDownload: boolean;
protected setDefault: boolean;
protected verifySignature: boolean;
protected verifySignaturePublicKey: string | undefined;
@@ -46,6 +47,7 @@ export abstract class JavaBase {
this.architecture = installerOptions.architecture || os.arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.forceDownload = installerOptions.forceDownload ?? false;
this.setDefault =
installerOptions.setDefault !== undefined
? installerOptions.setDefault
@@ -68,7 +70,7 @@ export abstract class JavaBase {
);
}
let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava && !this.checkLatest && !this.latest) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else {
@@ -91,7 +93,10 @@ export abstract class JavaBase {
}
const javaRelease = await this.findPackageForDownload(this.version);
core.info(`Resolved latest version as ${javaRelease.version}`);
if (foundJava?.version === javaRelease.version) {
if (
!this.forceDownload &&
foundJava?.version === javaRelease.version
) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else {
core.info('Trying to download...');

View File

@@ -3,6 +3,7 @@ export interface JavaInstallerOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
forceDownload?: boolean;
setDefault?: boolean;
verifySignature?: boolean;
verifySignaturePublicKey?: string;

View File

@@ -42,7 +42,7 @@ enum JavaDistribution {
GraalVMCommunity = 'graalvm-community',
JetBrains = 'jetbrains',
Kona = 'kona',
OpenJdk = 'openjdk'
OracleOpenJdk = 'oracle-openjdk'
}
export function getJavaDistribution(
@@ -95,7 +95,7 @@ export function getJavaDistribution(
return new JetBrainsDistribution(installerOptions);
case JavaDistribution.Kona:
return new KonaDistribution(installerOptions);
case JavaDistribution.OpenJdk:
case JavaDistribution.OracleOpenJdk:
return new OpenJdkDistribution(installerOptions);
default:
return null;

View File

@@ -110,6 +110,11 @@ export class GraalVMDistribution extends JavaBase {
}
}
protected setJavaDefault(version: string, toolPath: string): void {
super.setJavaDefault(version, toolPath);
core.exportVariable('GRAALVM_HOME', toolPath);
}
protected async findPackageForDownload(
range: string
): Promise<JavaDownloadRelease> {

View File

@@ -28,7 +28,7 @@ export class LocalDistribution extends JavaBase {
);
}
let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);

View File

@@ -21,14 +21,14 @@ const OPENJDK_BASE_URL = 'https://jdk.java.net';
export class OpenJdkDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
super('OpenJDK', installerOptions);
super('Oracle OpenJDK', installerOptions);
}
protected async findPackageForDownload(
range: string
): Promise<JavaDownloadRelease> {
if (this.packageType !== 'jdk') {
throw new Error('OpenJDK provides only the `jdk` package type');
throw new Error('Oracle OpenJDK provides only the `jdk` package type');
}
const arch = this.distributionArchitecture();

View File

@@ -29,6 +29,10 @@ async function run() {
constants.INPUT_CACHE_DEPENDENCY_PATH
);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const forceDownload = getBooleanInput(
constants.INPUT_FORCE_DOWNLOAD,
false
);
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
const verifySignature = getBooleanInput(
constants.INPUT_VERIFY_SIGNATURE,
@@ -83,6 +87,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
@@ -102,6 +107,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
@@ -159,6 +165,7 @@ async function installVersion(
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
@@ -169,6 +176,7 @@ async function installVersion(
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
@@ -212,6 +220,7 @@ interface installerInputsOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
forceDownload: boolean;
setDefault: boolean;
verifySignature: boolean;
verifySignaturePublicKey: string | undefined;