Unverified Commit 089b010d authored by Copilot's avatar Copilot Committed by GitHub
Browse files

Add force-download option for reproducible JDK builds (#1148)

* Initial plan

* Add force-download input

* Build force-download action bundles

---------

Co-authored-by: default avatarcopilot-swe-agent[bot] <[email protected]>
Co-authored-by: default avatarBruno Borges <[email protected]>
parent e07d36bb
Loading
Loading
Loading
Loading
+2
Changes for README.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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.
+29
Changes for __tests__/distributors/base-installer.test.ts: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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([
    [
      {
+23
Changes for __tests__/distributors/local-installer.test.ts: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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,
+4
Changes for action.yml: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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
+1
Changes for dist/cleanup/index.js: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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';
Loading