Unverified Commit 60d2c8e1 authored by Bruno Borges's avatar Bruno Borges Committed by GitHub
Browse files

Compare JDK version reports across main, v6, and v5 (#1331)

Co-authored-by: default avatarCopilot App <[email protected]>
parent 3fc1c6e6
Loading
Loading
Loading
Loading
+78 −10
Changes for .github/workflows/latest-jdk-versions.yml: 78 added lines, 10 removed lines.
Original line number Diff line number Diff line
# Daily report of the exact JDK version each distribution currently resolves
# for every major from Java 6 through the newest GA release, and `latest`, on every operating
# system and architecture setup-java supports for it. Versions are resolved
# from vendor metadata only; no JDK is downloaded.
# from vendor metadata only; no JDK is downloaded. Compare main and the latest
# v6/v5 tags using each revision's own installers and locked dependencies.
name: Latest JDK versions report

on:
@@ -16,6 +17,8 @@ on:
  pull_request:
    paths:
      - 'src/reports/**'
      - 'scripts/build-report-resolver.mjs'
      - '__tests__/latest-versions-report.test.ts'
      - '.github/workflows/latest-jdk-versions.yml'

permissions:
@@ -54,14 +57,56 @@ jobs:
          path: lib/latest-versions-report/
          retention-days: 1

  build-resolvers:
    name: Build resolver (${{ matrix.setup-java }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        setup-java: [main, v6, v5]
    steps:
      - name: Checkout report tooling
        uses: actions/checkout@v7
        with:
          persist-credentials: false
      - name: Checkout setup-java revision
        uses: actions/checkout@v7
        with:
          repository: actions/setup-java
          ref: ${{ matrix.setup-java }}
          path: resolver-source
          persist-credentials: false
      - name: Setup Node.js
        uses: actions/setup-node@v7
        with:
          node-version: '24.x'
          cache: npm
          cache-dependency-path: resolver-source/package-lock.json
      - name: Install revision dependencies
        working-directory: resolver-source
        run: npm ci
      - name: Bundle revision metadata resolver
        run: node scripts/build-report-resolver.mjs resolver-source "$SETUP_JAVA_REF" resolver
        env:
          SETUP_JAVA_REF: ${{ matrix.setup-java }}
      - name: Upload revision metadata resolver
        uses: actions/upload-artifact@v7
        with:
          name: jdk-metadata-resolver-${{ matrix.setup-java }}
          path: resolver/
          retention-days: 1

  resolve:
    name: Resolve versions (${{ matrix.platform }})
    needs: build
    name: Resolve versions (${{ matrix.setup-java }}, ${{ matrix.platform }})
    needs: [build, build-resolvers]
    if: ${{ !cancelled() && needs.build.result == 'success' }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        setup-java: [main, v6, v5]
        platform: [linux, macos, windows, solaris]
        include:
          - os: ubuntu-latest
            platform: linux
@@ -82,27 +127,39 @@ jobs:
        with:
          name: latest-versions-report-tool
          path: tool
      - name: Download revision metadata resolver
        uses: actions/download-artifact@v8
        with:
          name: jdk-metadata-resolver-${{ matrix.setup-java }}
          path: resolver
      - name: Resolve latest versions without downloading
        run: node tool/index.js resolve "results/$REPORT_PLATFORM.json"
        run: node tool/index.js resolve "results/$SETUP_JAVA_REF-$REPORT_PLATFORM.json"
        env:
          GITHUB_TOKEN: ${{ github.token }}
          REPORT_VERSIONS: ${{ inputs.java-versions }}
          REPORT_PLATFORM: ${{ matrix.platform }}
          REPORT_RESOLVER: resolver
          SETUP_JAVA_REF: ${{ matrix.setup-java }}
      - name: Upload resolved versions
        uses: actions/upload-artifact@v7
        with:
          name: latest-jdk-versions-${{ matrix.platform }}
          name: latest-jdk-versions-${{ matrix.setup-java }}-${{ matrix.platform }}
          path: results/
          retention-days: 1

  # Installers pick musl builds on Alpine, which can resolve to other versions.
  resolve-alpine:
    name: Resolve versions (alpine)
    needs: build
    name: Resolve versions (${{ matrix.setup-java }}, alpine)
    needs: [build, build-resolvers]
    if: ${{ !cancelled() && needs.build.result == 'success' }}
    runs-on: ubuntu-latest
    timeout-minutes: 30
    container:
      image: node:24-alpine
    strategy:
      fail-fast: false
      matrix:
        setup-java: [main, v6, v5]
    defaults:
      run:
        shell: sh
@@ -112,21 +169,28 @@ jobs:
        with:
          name: latest-versions-report-tool
          path: tool
      - name: Download revision metadata resolver
        uses: actions/download-artifact@v8
        with:
          name: jdk-metadata-resolver-${{ matrix.setup-java }}
          path: resolver
      - name: Resolve latest versions without downloading
        run: node tool/index.js resolve results/alpine.json
        run: node tool/index.js resolve "results/$SETUP_JAVA_REF-alpine.json"
        env:
          GITHUB_TOKEN: ${{ github.token }}
          REPORT_VERSIONS: ${{ inputs.java-versions }}
          REPORT_RESOLVER: resolver
          SETUP_JAVA_REF: ${{ matrix.setup-java }}
      - name: Upload resolved versions
        uses: actions/upload-artifact@v7
        with:
          name: latest-jdk-versions-alpine
          name: latest-jdk-versions-${{ matrix.setup-java }}-alpine
          path: results/
          retention-days: 1

  report:
    name: Report
    needs: [build, resolve, resolve-alpine]
    needs: [build, build-resolvers, resolve, resolve-alpine]
    if: ${{ !cancelled() && needs.build.result == 'success' }}
    runs-on: ubuntu-latest
    steps:
@@ -146,8 +210,12 @@ jobs:
          path: results
          merge-multiple: true
      - name: Write report
        if: ${{ !cancelled() }}
        run: node tool/index.js summarize results latest-jdk-versions.md
        env:
          REPORT_REFS: main,v6,v5
      - name: Upload report
        if: ${{ !cancelled() }}
        uses: actions/upload-artifact@v7
        with:
          name: latest-jdk-versions-report
+3 −1
Changes for README.md: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -246,7 +246,9 @@ When `check-latest` is `false`, the action first tries the runner tool cache for

GitHub-hosted runners primarily pre-cache Eclipse Temurin JDKs. See the installed Java versions for [Ubuntu](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md#java), [Windows](https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md#java), and [macOS](https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md#java). On a fresh GitHub-hosted runner, requests for other distributions usually miss the tool cache and resolve from remote metadata. For broad version ranges such as a major version (`21`, `25`), this often behaves similarly to `check-latest: true` because the action downloads the latest available release that satisfies the range.

To see which exact version a request resolves to today, open the summary of the latest run of the daily [Latest JDK versions report](https://github.com/actions/setup-java/actions/workflows/latest-jdk-versions.yml) workflow. For every supported distribution, it lists the version that `setup-java` currently resolves from vendor metadata for every major from Java 6 through the newest stable GA release (including non-LTS releases), plus `latest`, on every operating system and architecture the action supports for that distribution, including Alpine Linux and Solaris. Because vendors publish builds per platform, the same request can resolve to different versions on different platforms. The report doesn't download any JDKs. Floating vendor URLs are marked when their exact version cannot be established from metadata alone. It shows what a job installs on a tool-cache miss or with `check-latest: true`.
To see which exact version a request resolves to today, open the summary of the latest run of the daily [Latest JDK versions report](https://github.com/actions/setup-java/actions/workflows/latest-jdk-versions.yml) workflow. It compares `setup-java@main`, the latest `setup-java@v6`, and the latest `setup-java@v5`, with separate sections and the exact commit checked for each. Each revision uses its own installers and locked dependencies to resolve vendor metadata for every major from Java 6 through the newest stable GA release (including non-LTS releases), plus `latest`, across its distributions, operating systems and architectures, including Alpine Linux and Solaris. Older revisions without capability maps probe all candidate architectures; unsupported combinations and version syntax (such as `latest` in v5) are marked `n/a`. Distribution support and resolved versions can differ between action revisions as well as platforms. Missing reports and lookup failures are shown explicitly. The report doesn't download any JDKs. Floating vendor URLs are marked when their exact version cannot be established from metadata alone. It shows what a job installs on a tool-cache miss or with `check-latest: true`.

The `latest-jdk-versions-report` artifact contains the full Markdown report and per-revision/platform JSON results. If the combined report exceeds GitHub's job-summary size limit, the summary shows an overview pointing to this artifact instead.

## Download integrity and signatures

+300 −3
Changes for __tests__/latest-versions-report.test.ts: 300 added lines, 3 removed lines.
Original line number Diff line number Diff line
import {afterEach, describe, expect, it, jest} from '@jest/globals';
import {HttpClient} from '@actions/http-client';
import {HttpClient, HttpClientResponse} from '@actions/http-client';
import fs from 'fs';
import os from 'os';
import path from 'path';
import {IncomingMessage} from 'http';
import {Socket} from 'net';
import {JavaBase} from '../src/distributions/base-installer.js';
import {
  currentResolver,
  loadMetadataResolver,
  type MetadataResolver
} from '../src/reports/resolver.js';
import {
  classifyResolutionError,
  getDefaultVersions,
@@ -27,7 +37,12 @@ function report(
  platform: string,
  results: VersionResolution[]
): ResolutionReport {
  return {platform, generatedAt: '2026-11-18T06:30:00.000Z', results};
  return {
    source: {ref: 'main'},
    platform,
    generatedAt: '2026-11-18T06:30:00.000Z',
    results
  };
}

function tableRows(markdown: string, distribution: string): string[] {
@@ -38,6 +53,7 @@ function tableRows(markdown: string, distribution: string): string[] {
describe('latest versions report', () => {
  afterEach(() => {
    jest.restoreAllMocks();
    jest.useRealTimers();
  });

  it('includes every major from Java 6 through GA, including non-LTS releases but not EA', async () => {
@@ -226,7 +242,7 @@ describe('latest versions report', () => {
      classifyResolutionError(
        new Error('Oracle JDK is only supported for JDK 17 and later')
      )
    ).toBe('unavailable');
    ).toBe('unsupported');
    expect(
      classifyResolutionError(
        new Error(
@@ -358,4 +374,285 @@ describe('latest versions report', () => {
      '| `zulu` | `25` | Linux x64 | socket hang up |'
    );
  });

  it('uses the selected revision without substituting main for unsupported version syntax', async () => {
    const mainFactory = jest.spyOn(currentResolver, 'getJavaDistribution');
    const lookup = jest.fn(async () => ({
      version: '21.0.8+9',
      url: 'https://example.com/jdk.tar.gz'
    }));
    const legacy: MetadataResolver = {
      source: {ref: 'v5', sha: 'a'.repeat(40), version: '5.6.0'},
      distributions: ['adopt'],
      getJavaDistribution: (_distribution, options) => {
        if (options.version === 'latest') {
          throw new Error("The string 'latest' is not valid SemVer notation");
        }
        return {
          version: options.version,
          http: new HttpClient(),
          findPackageForDownload: lookup
        };
      },
      createSolarisInstaller: () => {
        throw new Error('Unexpected Solaris lookup');
      }
    };
    const resolved = await resolveLatestVersions({
      resolver: legacy,
      distributions: legacy.distributions,
      versions: ['21', 'latest'],
      architectures: ['x64']
    });

    expect(resolved.source).toEqual(legacy.source);
    expect(resolved.results).toEqual([
      expect.objectContaining({
        distribution: 'adopt',
        versionSpec: '21',
        version: '21.0.8+9'
      }),
      expect.objectContaining({
        distribution: 'adopt',
        versionSpec: 'latest',
        status: 'unsupported'
      })
    ]);
    expect(lookup).toHaveBeenCalledTimes(1);
    expect(lookup).toHaveBeenCalledWith('21');
    expect(mainFactory).not.toHaveBeenCalled();
    expect(getSupportedArchitectures('adopt', 'linux', legacy)).toContain(
      's390x'
    );
    expect(getSupportedArchitectures('redhat', 'linux', legacy)).toEqual([]);
  });

  it('marks legacy mutable Oracle URLs as floating instead of reporting a major as exact', async () => {
    const response = new IncomingMessage(new Socket());
    response.headers['last-modified'] = 'Tue, 27 Oct 2026 00:00:00 GMT';
    jest
      .spyOn(HttpClient.prototype, 'head')
      .mockResolvedValue(new HttpClientResponse(response));
    jest.spyOn(HttpClient.prototype, 'getJson').mockResolvedValue({
      statusCode: 200,
      headers: {},
      result: {releaseVersion: '25.0.1', licenseDetails: {licenseType: 'NFTC'}}
    });
    const resolved = await resolveLatestVersions({
      resolver: {
        ...currentResolver,
        source: {ref: 'v5'},
        getJavaDistribution: () => ({
          version: '25',
          http: new HttpClient(),
          findPackageForDownload: async () => ({
            version: '25',
            url: 'https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.tar.gz'
          })
        })
      },
      distributions: ['oracle'],
      versions: ['25'],
      architectures: ['x64']
    });

    expect(resolved.results[0]).toMatchObject({
      status: 'resolved',
      floating: true,
      advertisedVersion: '25.0.1',
      publishedAt: '2026-10-27'
    });
  });

  it('refuses to install if a revision crosses the metadata boundary', async () => {
    const download = jest.fn();
    const installer = {
      version: '21',
      http: new HttpClient(),
      downloadTool: download,
      async findPackageForDownload() {
        this.downloadTool();
        return {version: '21', url: 'https://example.com/jdk.tar.gz'};
      }
    };
    const resolved = await resolveLatestVersions({
      resolver: {...currentResolver, getJavaDistribution: () => installer},
      distributions: ['temurin'],
      versions: ['21'],
      architectures: ['x64']
    });
    expect(resolved.results[0]).toMatchObject({
      status: 'error',
      message: 'JDK download/install is forbidden in the versions report.'
    });
    expect(download).not.toHaveBeenCalled();
  });

  it('records stalled legacy endpoints as errors and does not retry them for every major', async () => {
    jest.useFakeTimers();
    const request = jest
      .spyOn(HttpClient.prototype, 'getJson')
      .mockImplementation(() => new Promise(() => {}));
    const dispose = jest.spyOn(HttpClient.prototype, 'dispose');
    const pending = resolveLatestVersions({
      resolver: {
        ...currentResolver,
        getJavaDistribution: (_distribution, options) => ({
          version: options.version,
          http: new HttpClient(),
          async findPackageForDownload() {
            await this.http.getJson('https://example.com/retired-api');
            throw new Error('Unreachable');
          }
        })
      },
      distributions: ['temurin'],
      versions: ['17', '21'],
      architectures: ['x64']
    });
    await jest.advanceTimersByTimeAsync(60_000);
    const resolved = await pending;
    expect(resolved.results).toEqual([
      expect.objectContaining({
        versionSpec: '17',
        status: 'error',
        message: expect.stringContaining('Metadata request timed out')
      }),
      expect.objectContaining({
        versionSpec: '21',
        status: 'error',
        message: expect.stringContaining('Metadata request timed out')
      })
    ]);
    expect(request).toHaveBeenCalledTimes(1);
    expect(dispose).toHaveBeenCalledTimes(1);
  });

  it('keeps different revision results and failures separate, including missing runners', () => {
    const main = report('linux', [
      result({distribution: 'temurin', versionSpec: '21', version: '21.0.13+9'})
    ]);
    const v6 = {
      ...report('linux', [
        result({
          distribution: 'temurin',
          versionSpec: '21',
          version: '21.0.12+7'
        })
      ]),
      source: {ref: 'v6', sha: 'b'.repeat(40), version: '6.0.0'}
    };
    const v5 = {
      ...report('linux', [
        result({
          distribution: 'adopt',
          versionSpec: '21',
          status: 'unavailable'
        }),
        result({
          distribution: 'temurin',
          versionSpec: '21',
          status: 'error',
          message: 'metadata failed'
        })
      ]),
      source: {ref: 'v5', sha: 'a'.repeat(40), version: '5.6.0'},
      targets: {adopt: {linux: ['x64'], windows: ['x64']}}
    };
    const markdown = renderMarkdownReport([main, v6, v5]);
    const mainSection = markdown
      .split('<summary>setup-java@main</summary>')[1]
      .split('</details>')[0];
    const v6Section = markdown
      .split('<summary>setup-java@v6</summary>')[1]
      .split('</details>')[0];
    const v5Section = markdown
      .split('<summary>setup-java@v5</summary>')[1]
      .split('</details>')[0];
    expect(mainSection).toContain('`21.0.13+9`');
    expect(mainSection).not.toContain('Needs attention');
    expect(v6Section).toContain('`21.0.12+7`');
    expect(v6Section).not.toContain('`21.0.13+9`');
    expect(v5Section).toContain('metadata failed');
    expect(v5Section).toContain('## `adopt` ❗');
    expect(v5Section).toContain(
      'Not checked, because no runner reported these platforms: Windows (x64).'
    );
    expect(markdown).toContain(
      `https://github.com/actions/setup-java/commit/${'a'.repeat(40)}`
    );
  });

  it('shows missing revisions and rejects mixed commits within one revision', () => {
    const main = report('linux', []);
    expect(
      renderMarkdownReport([main], {expectedRefs: ['main', 'v6', 'v5']})
    ).toContain('| `v5` | - | - | Not checked: no reports received |');
    expect(() =>
      renderMarkdownReport([
        {...main, source: {ref: 'v6', sha: 'a'.repeat(40)}},
        {...main, source: {ref: 'v6', sha: 'b'.repeat(40)}}
      ])
    ).toThrow("Reports for 'v6' were produced from different revisions.");
  });

  it.each(['module', 'commonjs'])(
    'loads a separate %s resolver with its provenance',
    async type => {
      const directory = fs.mkdtempSync(
        path.join(os.tmpdir(), 'setup-java resolver-')
      );
      try {
        fs.writeFileSync(
          path.join(directory, 'package.json'),
          JSON.stringify({type})
        );
        const source = {ref: 'v5', sha: 'a'.repeat(40), version: '5.6.0'};
        fs.writeFileSync(
          path.join(directory, 'index.js'),
          `
        const source = ${JSON.stringify(source)};
        const distributions = ['adopt'];
        const getJavaDistribution = () => 'selected checkout';
        const createSolarisInstaller = () => null;
        ${type === 'module' ? 'export' : 'module.exports ='}
        {source, distributions, getJavaDistribution, createSolarisInstaller};
      `
        );
        const loaded = await loadMetadataResolver(directory);
        expect(loaded.source).toEqual(source);
        expect(
          loaded.getJavaDistribution('adopt', {
            version: '21',
            architecture: 'x64',
            packageType: 'jdk',
            checkLatest: true
          })
        ).toBe('selected checkout');
      } finally {
        fs.rmSync(directory, {recursive: true, force: true});
      }
    }
  );

  it('fails explicitly instead of falling back to main when the resolver bundle is invalid', async () => {
    const directory = fs.mkdtempSync(
      path.join(os.tmpdir(), 'setup-java resolver-')
    );
    try {
      fs.writeFileSync(
        path.join(directory, 'package.json'),
        '{"type":"module"}'
      );
      fs.writeFileSync(
        path.join(directory, 'index.js'),
        'export const source = {ref: "v5"};'
      );
      await expect(loadMetadataResolver(directory)).rejects.toThrow(
        'Invalid metadata resolver bundle'
      );
    } finally {
      fs.rmSync(directory, {recursive: true, force: true});
    }
  });
});
+96
Changes for scripts/build-report-resolver.mjs: 96 added lines, 0 removed lines.
Original line number Diff line number Diff line
import fs from 'node:fs';
import path from 'node:path';
import {execFileSync} from 'node:child_process';
import {createRequire} from 'node:module';

const [checkout, ref, destination] = process.argv.slice(2);
if (!checkout || !ref || !destination) {
  throw new Error(
    'Usage: node scripts/build-report-resolver.mjs <checkout> <ref> <output-dir>'
  );
}

const root = path.resolve(checkout);
const output = path.resolve(destination);
const ts = createRequire(path.join(root, 'package.json'))('typescript');
const packageJson = JSON.parse(
  fs.readFileSync(path.join(root, 'package.json'), 'utf8')
);
const source = {
  ref,
  sha: execFileSync('git', ['rev-parse', 'HEAD'], {
    cwd: root,
    encoding: 'utf8'
  }).trim(),
  version: packageJson.version
};
const capabilityFile = path.join(root, 'src/distributions/platform-types.ts');
const packageFile = path.join(root, 'src/distributions/package-types.ts');
const enumFile = fs.existsSync(packageFile)
  ? packageFile
  : path.join(root, 'src/distributions/distribution-factory.ts');
const syntax = ts.createSourceFile(
  enumFile,
  fs.readFileSync(enumFile, 'utf8'),
  ts.ScriptTarget.Latest,
  true
);
const declaration = syntax.statements.find(
  statement =>
    ts.isEnumDeclaration(statement) &&
    statement.name.text === 'JavaDistribution'
);
if (!declaration) {
  throw new Error(`Cannot find the distribution enum in ${enumFile}`);
}
const distributions = declaration.members
  .map(member => {
    if (!member.initializer || !ts.isStringLiteral(member.initializer)) {
      throw new Error(`Expected a string-valued distribution in ${enumFile}`);
    }
    return member.initializer.text;
  })
  .filter(value => value !== 'jdkfile');

// Keep source and dependencies from the selected checkout. Only this small
// reporting entrypoint is injected; no installer or version matcher is replaced.
const entrypoint = path.join(root, 'report-resolver-entry.js');
fs.writeFileSync(
  entrypoint,
  `
export {getJavaDistribution} from './src/distributions/distribution-factory.ts';
import {LibericaDistributions} from './src/distributions/liberica/installer.ts';
${fs.existsSync(capabilityFile) ? "export {JAVA_PLATFORM_CAPABILITIES as capabilities} from './src/distributions/platform-types.ts';" : ''}
export const source = ${JSON.stringify(source)};
export const distributions = ${JSON.stringify(distributions)};
export function createSolarisInstaller(options) {
  const installer = new LibericaDistributions(options);
  const getPlatformOption = installer.getPlatformOption.bind(installer);
  installer.getPlatformOption = () => getPlatformOption('sunos');
  return installer;
}
`,
  {flag: 'wx'}
);
try {
  execFileSync(
    process.execPath,
    [
      path.join(root, 'node_modules/@vercel/ncc/dist/ncc/cli.js'),
      'build',
      entrypoint,
      '-o',
      output
    ],
    {cwd: root, stdio: 'inherit'}
  );
  // v5 is CommonJS even when the artifact is loaded from an ESM workspace.
  fs.writeFileSync(
    path.join(output, 'package.json'),
    JSON.stringify({
      type: packageJson.type ?? 'commonjs'
    })
  );
} finally {
  fs.rmSync(entrypoint, {force: true});
}
+252 −73

File changed.

Preview size limit exceeded, changes collapsed.

Loading