mirror of
https://github.com/actions/setup-java.git
synced 2026-11-20 15:40:41 +08:00
Compare JDK version reports across main, v6, and v5 (#1331)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot App
parent
3fc1c6e612
commit
60d2c8e17e
@@ -1,7 +1,8 @@
|
|||||||
# Daily report of the exact JDK version each distribution currently resolves
|
# 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
|
# 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
|
# 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
|
name: Latest JDK versions report
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -16,6 +17,8 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- 'src/reports/**'
|
- 'src/reports/**'
|
||||||
|
- 'scripts/build-report-resolver.mjs'
|
||||||
|
- '__tests__/latest-versions-report.test.ts'
|
||||||
- '.github/workflows/latest-jdk-versions.yml'
|
- '.github/workflows/latest-jdk-versions.yml'
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
@@ -54,14 +57,56 @@ jobs:
|
|||||||
path: lib/latest-versions-report/
|
path: lib/latest-versions-report/
|
||||||
retention-days: 1
|
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:
|
resolve:
|
||||||
name: Resolve versions (${{ matrix.platform }})
|
name: Resolve versions (${{ matrix.setup-java }}, ${{ matrix.platform }})
|
||||||
needs: build
|
needs: [build, build-resolvers]
|
||||||
|
if: ${{ !cancelled() && needs.build.result == 'success' }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
setup-java: [main, v6, v5]
|
||||||
|
platform: [linux, macos, windows, solaris]
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
platform: linux
|
platform: linux
|
||||||
@@ -82,27 +127,39 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: latest-versions-report-tool
|
name: latest-versions-report-tool
|
||||||
path: 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
|
- 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:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
REPORT_VERSIONS: ${{ inputs.java-versions }}
|
REPORT_VERSIONS: ${{ inputs.java-versions }}
|
||||||
REPORT_PLATFORM: ${{ matrix.platform }}
|
REPORT_PLATFORM: ${{ matrix.platform }}
|
||||||
|
REPORT_RESOLVER: resolver
|
||||||
|
SETUP_JAVA_REF: ${{ matrix.setup-java }}
|
||||||
- name: Upload resolved versions
|
- name: Upload resolved versions
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: latest-jdk-versions-${{ matrix.platform }}
|
name: latest-jdk-versions-${{ matrix.setup-java }}-${{ matrix.platform }}
|
||||||
path: results/
|
path: results/
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
# Installers pick musl builds on Alpine, which can resolve to other versions.
|
# Installers pick musl builds on Alpine, which can resolve to other versions.
|
||||||
resolve-alpine:
|
resolve-alpine:
|
||||||
name: Resolve versions (alpine)
|
name: Resolve versions (${{ matrix.setup-java }}, alpine)
|
||||||
needs: build
|
needs: [build, build-resolvers]
|
||||||
|
if: ${{ !cancelled() && needs.build.result == 'success' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
container:
|
container:
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
setup-java: [main, v6, v5]
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: sh
|
shell: sh
|
||||||
@@ -112,21 +169,28 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: latest-versions-report-tool
|
name: latest-versions-report-tool
|
||||||
path: 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
|
- 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:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
REPORT_VERSIONS: ${{ inputs.java-versions }}
|
REPORT_VERSIONS: ${{ inputs.java-versions }}
|
||||||
|
REPORT_RESOLVER: resolver
|
||||||
|
SETUP_JAVA_REF: ${{ matrix.setup-java }}
|
||||||
- name: Upload resolved versions
|
- name: Upload resolved versions
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: latest-jdk-versions-alpine
|
name: latest-jdk-versions-${{ matrix.setup-java }}-alpine
|
||||||
path: results/
|
path: results/
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
report:
|
report:
|
||||||
name: Report
|
name: Report
|
||||||
needs: [build, resolve, resolve-alpine]
|
needs: [build, build-resolvers, resolve, resolve-alpine]
|
||||||
if: ${{ !cancelled() && needs.build.result == 'success' }}
|
if: ${{ !cancelled() && needs.build.result == 'success' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -146,8 +210,12 @@ jobs:
|
|||||||
path: results
|
path: results
|
||||||
merge-multiple: true
|
merge-multiple: true
|
||||||
- name: Write report
|
- name: Write report
|
||||||
|
if: ${{ !cancelled() }}
|
||||||
run: node tool/index.js summarize results latest-jdk-versions.md
|
run: node tool/index.js summarize results latest-jdk-versions.md
|
||||||
|
env:
|
||||||
|
REPORT_REFS: main,v6,v5
|
||||||
- name: Upload report
|
- name: Upload report
|
||||||
|
if: ${{ !cancelled() }}
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: latest-jdk-versions-report
|
name: latest-jdk-versions-report
|
||||||
|
|||||||
@@ -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.
|
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
|
## Download integrity and signatures
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
import {afterEach, describe, expect, it, jest} from '@jest/globals';
|
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 {JavaBase} from '../src/distributions/base-installer.js';
|
||||||
|
import {
|
||||||
|
currentResolver,
|
||||||
|
loadMetadataResolver,
|
||||||
|
type MetadataResolver
|
||||||
|
} from '../src/reports/resolver.js';
|
||||||
import {
|
import {
|
||||||
classifyResolutionError,
|
classifyResolutionError,
|
||||||
getDefaultVersions,
|
getDefaultVersions,
|
||||||
@@ -27,7 +37,12 @@ function report(
|
|||||||
platform: string,
|
platform: string,
|
||||||
results: VersionResolution[]
|
results: VersionResolution[]
|
||||||
): ResolutionReport {
|
): 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[] {
|
function tableRows(markdown: string, distribution: string): string[] {
|
||||||
@@ -38,6 +53,7 @@ function tableRows(markdown: string, distribution: string): string[] {
|
|||||||
describe('latest versions report', () => {
|
describe('latest versions report', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
|
jest.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('includes every major from Java 6 through GA, including non-LTS releases but not EA', async () => {
|
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(
|
classifyResolutionError(
|
||||||
new Error('Oracle JDK is only supported for JDK 17 and later')
|
new Error('Oracle JDK is only supported for JDK 17 and later')
|
||||||
)
|
)
|
||||||
).toBe('unavailable');
|
).toBe('unsupported');
|
||||||
expect(
|
expect(
|
||||||
classifyResolutionError(
|
classifyResolutionError(
|
||||||
new Error(
|
new Error(
|
||||||
@@ -358,4 +374,285 @@ describe('latest versions report', () => {
|
|||||||
'| `zulu` | `25` | Linux x64 | socket hang up |'
|
'| `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});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
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});
|
||||||
|
}
|
||||||
+261
-82
@@ -2,21 +2,22 @@ import * as core from '@actions/core';
|
|||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {getJavaDistribution} from '../distributions/distribution-factory.js';
|
|
||||||
import type {JavaBase} from '../distributions/base-installer.js';
|
|
||||||
import type {JavaDownloadRelease} from '../distributions/base-models.js';
|
import type {JavaDownloadRelease} from '../distributions/base-models.js';
|
||||||
import {LibericaDistributions} from '../distributions/liberica/installer.js';
|
|
||||||
import {JavaDistribution} from '../distributions/package-types.js';
|
import {JavaDistribution} from '../distributions/package-types.js';
|
||||||
import {
|
import {
|
||||||
isAlpineLinux,
|
isAlpineLinux,
|
||||||
JAVA_PLATFORM_CAPABILITIES,
|
normalizePlatform
|
||||||
JavaPlatform,
|
|
||||||
normalizePlatform,
|
|
||||||
validateJavaPlatform
|
|
||||||
} from '../distributions/platform-types.js';
|
} from '../distributions/platform-types.js';
|
||||||
import {isMainModule} from '../is-main-module.js';
|
import {isMainModule} from '../is-main-module.js';
|
||||||
import {RetryingHttpClient} from '../retrying-http-client.js';
|
import {RetryingHttpClient} from '../retrying-http-client.js';
|
||||||
import {getLatestMajorVersion} from '../util.js';
|
import {getLatestMajorVersion} from '../util.js';
|
||||||
|
import {
|
||||||
|
type ActionSource,
|
||||||
|
type MetadataResolver,
|
||||||
|
currentResolver,
|
||||||
|
getResolverArchitectures,
|
||||||
|
loadMetadataResolver
|
||||||
|
} from './resolver.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports the exact JDK version each distribution currently resolves for a set
|
* Reports the exact JDK version each distribution currently resolves for a set
|
||||||
@@ -26,12 +27,11 @@ import {getLatestMajorVersion} from '../util.js';
|
|||||||
|
|
||||||
// Zulu's supported JDK catalog starts at Java 6, including non-LTS releases.
|
// Zulu's supported JDK catalog starts at Java 6, including non-LTS releases.
|
||||||
const FIRST_MAJOR_VERSION = 6;
|
const FIRST_MAJOR_VERSION = 6;
|
||||||
export const REPORTED_DISTRIBUTIONS: string[] = Object.values(
|
export const REPORTED_DISTRIBUTIONS = currentResolver.distributions;
|
||||||
JavaDistribution
|
|
||||||
).filter(distribution => distribution !== JavaDistribution.JdkFile);
|
|
||||||
|
|
||||||
const PACKAGE_TYPE = 'jdk';
|
const PACKAGE_TYPE = 'jdk';
|
||||||
const CONCURRENCY = 6;
|
const CONCURRENCY = 6;
|
||||||
|
const METADATA_TIMEOUT_MS = 60_000;
|
||||||
const ORACLE_RELEASES_URL = 'https://java.oraclecloud.com/currentJavaReleases';
|
const ORACLE_RELEASES_URL = 'https://java.oraclecloud.com/currentJavaReleases';
|
||||||
const MUSL_PLATFORM = 'linux-musl';
|
const MUSL_PLATFORM = 'linux-musl';
|
||||||
const PLATFORM_LABELS: Record<string, string> = {
|
const PLATFORM_LABELS: Record<string, string> = {
|
||||||
@@ -78,8 +78,11 @@ export interface VersionResolution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ResolutionReport {
|
export interface ResolutionReport {
|
||||||
|
source: ActionSource;
|
||||||
platform: string;
|
platform: string;
|
||||||
generatedAt: string;
|
generatedAt: string;
|
||||||
|
/** Expected platform/architecture probes, from this revision rather than main. */
|
||||||
|
targets?: Record<string, Record<string, string[]>>;
|
||||||
results: VersionResolution[];
|
results: VersionResolution[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,13 +92,6 @@ interface ReleaseResolver {
|
|||||||
findPackageForDownload(range: string): Promise<JavaDownloadRelease>;
|
findPackageForDownload(range: string): Promise<JavaDownloadRelease>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metadata resolution does not require a Solaris runner or executing its JDK.
|
|
||||||
class SolarisLibericaDistribution extends LibericaDistributions {
|
|
||||||
protected override getPlatformOption() {
|
|
||||||
return super.getPlatformOption('sunos');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Alpine is reported separately because installers pick musl builds there. */
|
/** Alpine is reported separately because installers pick musl builds there. */
|
||||||
export function getReportPlatform(
|
export function getReportPlatform(
|
||||||
platform: NodeJS.Platform = process.platform,
|
platform: NodeJS.Platform = process.platform,
|
||||||
@@ -113,25 +109,21 @@ export function getReportPlatform(
|
|||||||
*/
|
*/
|
||||||
export function getSupportedArchitectures(
|
export function getSupportedArchitectures(
|
||||||
distribution: string,
|
distribution: string,
|
||||||
platform: string
|
platform: string,
|
||||||
|
resolver: MetadataResolver = currentResolver
|
||||||
): string[] {
|
): string[] {
|
||||||
const capability =
|
return getResolverArchitectures(resolver, distribution, platform);
|
||||||
JAVA_PLATFORM_CAPABILITIES[distribution as JavaDistribution];
|
|
||||||
if (!capability || capability.unrestricted) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const os = (platform === MUSL_PLATFORM ? 'linux' : platform) as JavaPlatform;
|
|
||||||
return [
|
|
||||||
...new Set(
|
|
||||||
(capability.platforms[os] ?? []).map(item =>
|
|
||||||
typeof item === 'string' ? item : item.architecture
|
|
||||||
)
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function classifyResolutionError(error: unknown): ResolutionStatus {
|
export function classifyResolutionError(error: unknown): ResolutionStatus {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
if (
|
||||||
|
/not supported|only supported|does not support|unsupported|not valid SemVer/i.test(
|
||||||
|
message
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return 'unsupported';
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
(error instanceof Error && error.name === 'VersionNotFoundError') ||
|
(error instanceof Error && error.name === 'VersionNotFoundError') ||
|
||||||
/no matching version|no \w+ release for|could not determine the latest available|not supported|only supported|does not support|not available|could not find|unsupported/i.test(
|
/no matching version|no \w+ release for|could not determine the latest available|not supported|only supported|does not support|not available|could not find|unsupported/i.test(
|
||||||
@@ -148,7 +140,9 @@ export function classifyResolutionError(error: unknown): ResolutionStatus {
|
|||||||
* fetch a vendor's whole release list for every request, and JetBrains probes
|
* fetch a vendor's whole release list for every request, and JetBrains probes
|
||||||
* each release URL with HEAD, so resolving many version/architecture
|
* each release URL with HEAD, so resolving many version/architecture
|
||||||
* combinations would otherwise repeat identical requests and exhaust API rate
|
* combinations would otherwise repeat identical requests and exhaust API rate
|
||||||
* limits. Installers only read the status and headers of HEAD responses.
|
* limits. Failed requests are also retained for this snapshot so an obsolete
|
||||||
|
* endpoint does not stall every major-version probe. Installers only read the
|
||||||
|
* status and headers of HEAD responses.
|
||||||
*/
|
*/
|
||||||
function shareMetadataResponses(
|
function shareMetadataResponses(
|
||||||
http: httpm.HttpClient,
|
http: httpm.HttpClient,
|
||||||
@@ -157,9 +151,29 @@ function shareMetadataResponses(
|
|||||||
const share = <T>(key: string, request: () => Promise<T>): Promise<T> => {
|
const share = <T>(key: string, request: () => Promise<T>): Promise<T> => {
|
||||||
let response = cache.get(key) as Promise<T> | undefined;
|
let response = cache.get(key) as Promise<T> | undefined;
|
||||||
if (!response) {
|
if (!response) {
|
||||||
response = request();
|
response = new Promise<T>((resolve, reject) => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
http.dispose();
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
`Metadata request timed out after ${METADATA_TIMEOUT_MS} ms: ${key.split('\n')[0]}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, METADATA_TIMEOUT_MS);
|
||||||
|
Promise.resolve()
|
||||||
|
.then(request)
|
||||||
|
.then(
|
||||||
|
value => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve(value);
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
cache.set(key, response);
|
cache.set(key, response);
|
||||||
response.catch(() => cache.delete(key));
|
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
@@ -225,7 +239,8 @@ async function resolveOne(
|
|||||||
platform: string,
|
platform: string,
|
||||||
architecture: string,
|
architecture: string,
|
||||||
cache: Map<string, Promise<unknown>>,
|
cache: Map<string, Promise<unknown>>,
|
||||||
http: httpm.HttpClient
|
http: httpm.HttpClient,
|
||||||
|
metadataResolver: MetadataResolver
|
||||||
): Promise<VersionResolution> {
|
): Promise<VersionResolution> {
|
||||||
const base = {
|
const base = {
|
||||||
distribution: distributionName,
|
distribution: distributionName,
|
||||||
@@ -234,7 +249,7 @@ async function resolveOne(
|
|||||||
architecture
|
architecture
|
||||||
};
|
};
|
||||||
|
|
||||||
let installer: JavaBase | null;
|
let installer: unknown;
|
||||||
try {
|
try {
|
||||||
const installerOptions = {
|
const installerOptions = {
|
||||||
version: versionSpec,
|
version: versionSpec,
|
||||||
@@ -250,20 +265,18 @@ async function resolveOne(
|
|||||||
message: `No Solaris metadata resolver for '${distributionName}'.`
|
message: `No Solaris metadata resolver for '${distributionName}'.`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
validateJavaPlatform(
|
installer =
|
||||||
distributionName,
|
await metadataResolver.createSolarisInstaller(installerOptions);
|
||||||
'sunos',
|
|
||||||
architecture,
|
|
||||||
versionSpec
|
|
||||||
);
|
|
||||||
installer = new SolarisLibericaDistribution(installerOptions);
|
|
||||||
} else {
|
} else {
|
||||||
installer = await getJavaDistribution(distributionName, installerOptions);
|
installer = await metadataResolver.getJavaDistribution(
|
||||||
|
distributionName,
|
||||||
|
installerOptions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
status: 'unsupported',
|
status: classifyResolutionError(error),
|
||||||
message: error instanceof Error ? error.message : String(error)
|
message: error instanceof Error ? error.message : String(error)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -274,15 +287,31 @@ async function resolveOne(
|
|||||||
// `findPackageForDownload` is the metadata step `setupJava` runs right
|
// `findPackageForDownload` is the metadata step `setupJava` runs right
|
||||||
// before downloading; it is protected because the action never needs it on
|
// before downloading; it is protected because the action never needs it on
|
||||||
// its own.
|
// its own.
|
||||||
const resolver = installer as unknown as ReleaseResolver;
|
if (!isReleaseResolver(installer)) {
|
||||||
|
throw new Error(`Invalid metadata resolver for '${distributionName}'.`);
|
||||||
|
}
|
||||||
|
const resolver = installer;
|
||||||
|
// Fail closed if a resolver ever crosses the metadata/download boundary.
|
||||||
|
const forbidInstall = () => {
|
||||||
|
throw new Error(
|
||||||
|
'JDK download/install is forbidden in the versions report.'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
Object.defineProperties(installer, {
|
||||||
|
setupJava: {value: forbidInstall},
|
||||||
|
downloadTool: {value: forbidInstall}
|
||||||
|
});
|
||||||
shareMetadataResponses(resolver.http, cache);
|
shareMetadataResponses(resolver.http, cache);
|
||||||
try {
|
try {
|
||||||
const release = await resolver.findPackageForDownload(resolver.version);
|
const release = await resolver.findPackageForDownload(resolver.version);
|
||||||
|
// Older releases returned the requested major without a floating marker.
|
||||||
|
const floating =
|
||||||
|
release.floating || new URL(release.url).pathname.includes('/latest/');
|
||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
status: 'resolved',
|
status: 'resolved',
|
||||||
version: release.version,
|
version: release.version,
|
||||||
...(release.floating
|
...(floating
|
||||||
? {
|
? {
|
||||||
floating: true,
|
floating: true,
|
||||||
...(await describeFloatingRelease(http, distributionName, release))
|
...(await describeFloatingRelease(http, distributionName, release))
|
||||||
@@ -298,6 +327,24 @@ async function resolveOne(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isReleaseResolver(value: unknown): value is ReleaseResolver {
|
||||||
|
return (
|
||||||
|
typeof value === 'object' &&
|
||||||
|
value !== null &&
|
||||||
|
'version' in value &&
|
||||||
|
typeof value.version === 'string' &&
|
||||||
|
'http' in value &&
|
||||||
|
typeof value.http === 'object' &&
|
||||||
|
value.http !== null &&
|
||||||
|
'getJson' in value.http &&
|
||||||
|
typeof value.http.getJson === 'function' &&
|
||||||
|
'head' in value.http &&
|
||||||
|
typeof value.http.head === 'function' &&
|
||||||
|
'findPackageForDownload' in value &&
|
||||||
|
typeof value.findPackageForDownload === 'function'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function runWithConcurrency<T>(
|
async function runWithConcurrency<T>(
|
||||||
tasks: (() => Promise<T>)[],
|
tasks: (() => Promise<T>)[],
|
||||||
limit: number
|
limit: number
|
||||||
@@ -320,6 +367,7 @@ async function runWithConcurrency<T>(
|
|||||||
export async function getDefaultVersions(
|
export async function getDefaultVersions(
|
||||||
http: httpm.HttpClient
|
http: httpm.HttpClient
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
|
shareMetadataResponses(http, new Map());
|
||||||
const latestMajor = await getLatestMajorVersion(http);
|
const latestMajor = await getLatestMajorVersion(http);
|
||||||
if (!Number.isSafeInteger(latestMajor) || latestMajor < FIRST_MAJOR_VERSION) {
|
if (!Number.isSafeInteger(latestMajor) || latestMajor < FIRST_MAJOR_VERSION) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -360,8 +408,11 @@ export async function resolveLatestVersions(options: {
|
|||||||
architectures?: string[];
|
architectures?: string[];
|
||||||
/** Solaris metadata can be resolved on any host; other targets use the host. */
|
/** Solaris metadata can be resolved on any host; other targets use the host. */
|
||||||
platform?: string;
|
platform?: string;
|
||||||
|
resolver?: MetadataResolver;
|
||||||
}): Promise<ResolutionReport> {
|
}): Promise<ResolutionReport> {
|
||||||
|
const resolver = options.resolver ?? currentResolver;
|
||||||
const http = new RetryingHttpClient('actions/setup-java');
|
const http = new RetryingHttpClient('actions/setup-java');
|
||||||
|
shareMetadataResponses(http, new Map());
|
||||||
const hostPlatform = getReportPlatform();
|
const hostPlatform = getReportPlatform();
|
||||||
const platform = options.platform || hostPlatform;
|
const platform = options.platform || hostPlatform;
|
||||||
if (platform !== hostPlatform && platform !== 'solaris') {
|
if (platform !== hostPlatform && platform !== 'solaris') {
|
||||||
@@ -372,7 +423,8 @@ export async function resolveLatestVersions(options: {
|
|||||||
const tasks = options.distributions.map(distribution => async () => {
|
const tasks = options.distributions.map(distribution => async () => {
|
||||||
const architectures = getSupportedArchitectures(
|
const architectures = getSupportedArchitectures(
|
||||||
distribution,
|
distribution,
|
||||||
platform
|
platform,
|
||||||
|
resolver
|
||||||
).filter(
|
).filter(
|
||||||
architecture =>
|
architecture =>
|
||||||
!options.architectures?.length ||
|
!options.architectures?.length ||
|
||||||
@@ -391,7 +443,8 @@ export async function resolveLatestVersions(options: {
|
|||||||
platform,
|
platform,
|
||||||
architecture,
|
architecture,
|
||||||
cache,
|
cache,
|
||||||
http
|
http,
|
||||||
|
resolver
|
||||||
);
|
);
|
||||||
core.info(
|
core.info(
|
||||||
`${distribution} ${versionSpec} (${formatPlatform(result)}): ${
|
`${distribution} ${versionSpec} (${formatPlatform(result)}): ${
|
||||||
@@ -411,8 +464,20 @@ export async function resolveLatestVersions(options: {
|
|||||||
|
|
||||||
const results = (await runWithConcurrency(tasks, CONCURRENCY)).flat();
|
const results = (await runWithConcurrency(tasks, CONCURRENCY)).flat();
|
||||||
return {
|
return {
|
||||||
|
source: resolver.source,
|
||||||
platform,
|
platform,
|
||||||
generatedAt: new Date().toISOString(),
|
generatedAt: new Date().toISOString(),
|
||||||
|
targets: Object.fromEntries(
|
||||||
|
options.distributions.map(distribution => [
|
||||||
|
distribution,
|
||||||
|
Object.fromEntries(
|
||||||
|
PLATFORM_ORDER.map(target => [
|
||||||
|
target,
|
||||||
|
getSupportedArchitectures(distribution, target, resolver)
|
||||||
|
]).filter(([, architectures]) => architectures.length > 0)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
),
|
||||||
results
|
results
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -489,22 +554,25 @@ function getProblems(results: VersionResolution[]): Problem[] {
|
|||||||
/** Supported operating systems for which no runner produced a report. */
|
/** Supported operating systems for which no runner produced a report. */
|
||||||
function getUncheckedPlatforms(
|
function getUncheckedPlatforms(
|
||||||
distribution: string,
|
distribution: string,
|
||||||
reportedPlatforms: Set<string>
|
reportedPlatforms: Set<string>,
|
||||||
|
targets?: Record<string, Record<string, string[]>>
|
||||||
): string[] {
|
): string[] {
|
||||||
const capability =
|
const platforms =
|
||||||
JAVA_PLATFORM_CAPABILITIES[distribution as JavaDistribution];
|
targets?.[distribution] ??
|
||||||
if (!capability || capability.unrestricted) {
|
Object.fromEntries(
|
||||||
return [];
|
PLATFORM_ORDER.map(platform => [
|
||||||
}
|
platform,
|
||||||
const platforms = Object.keys(capability.platforms);
|
getSupportedArchitectures(distribution, platform)
|
||||||
if (platforms.includes('linux')) {
|
])
|
||||||
platforms.push(MUSL_PLATFORM);
|
);
|
||||||
}
|
return Object.entries(platforms)
|
||||||
return platforms
|
.filter(
|
||||||
.filter(platform => !reportedPlatforms.has(platform))
|
([platform, architectures]) =>
|
||||||
|
architectures.length > 0 && !reportedPlatforms.has(platform)
|
||||||
|
)
|
||||||
.map(
|
.map(
|
||||||
platform =>
|
([platform, architectures]) =>
|
||||||
`${PLATFORM_LABELS[platform] ?? platform} (${getSupportedArchitectures(distribution, platform).join(', ')})`
|
`${PLATFORM_LABELS[platform] ?? platform} (${architectures.join(', ')})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +580,7 @@ function escapeTableText(text: string): string {
|
|||||||
return text.replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
|
return text.replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderMarkdownReport(
|
function renderSourceReport(
|
||||||
reports: ResolutionReport[],
|
reports: ResolutionReport[],
|
||||||
options: {runUrl?: string} = {}
|
options: {runUrl?: string} = {}
|
||||||
): string {
|
): string {
|
||||||
@@ -526,7 +594,7 @@ export function renderMarkdownReport(
|
|||||||
.at(-1);
|
.at(-1);
|
||||||
const silentDistributions = findSilentDistributions(results);
|
const silentDistributions = findSilentDistributions(results);
|
||||||
|
|
||||||
const lines: string[] = ['# Latest JDK versions resolved by setup-java', ''];
|
const lines: string[] = [`## setup-java@${reports[0].source.ref}`, ''];
|
||||||
lines.push(
|
lines.push(
|
||||||
`Generated ${generatedAt ? `${generatedAt.replace('T', ' ').slice(0, 16)} UTC` : 'now'} for package type \`${PACKAGE_TYPE}\` on ${PLATFORM_ORDER.filter(
|
`Generated ${generatedAt ? `${generatedAt.replace('T', ' ').slice(0, 16)} UTC` : 'now'} for package type \`${PACKAGE_TYPE}\` on ${PLATFORM_ORDER.filter(
|
||||||
p => reportedPlatforms.has(p)
|
p => reportedPlatforms.has(p)
|
||||||
@@ -535,7 +603,7 @@ export function renderMarkdownReport(
|
|||||||
.join(', ')}.` +
|
.join(', ')}.` +
|
||||||
(options.runUrl ? ` [Workflow run](${options.runUrl}).` : ''),
|
(options.runUrl ? ` [Workflow run](${options.runUrl}).` : ''),
|
||||||
'',
|
'',
|
||||||
'For each distribution, the table lists every operating system and architecture `setup-java` supports and the exact version it resolves from the distribution’s metadata today for each `java-version`. That is what a job installs on a tool-cache miss or with `check-latest: true`. Vendors publish builds per platform, so the same request can resolve to different versions on different platforms. No JDK was downloaded to produce this report.',
|
'For each distribution, the table lists platform/architecture probes and the exact version this revision resolves from the distribution’s metadata today for each `java-version`. That is what a job installs on a tool-cache miss or with `check-latest: true`. Vendors publish builds per platform, so the same request can resolve to different versions on different platforms. No JDK was downloaded to produce this report.',
|
||||||
'',
|
'',
|
||||||
'`—` no matching release is published for this platform · `n/a` `setup-java` does not support this version on this platform · ❗ the lookup failed',
|
'`—` no matching release is published for this platform · `n/a` `setup-java` does not support this version on this platform · ❗ the lookup failed',
|
||||||
''
|
''
|
||||||
@@ -593,7 +661,11 @@ export function renderMarkdownReport(
|
|||||||
}
|
}
|
||||||
lines.push('');
|
lines.push('');
|
||||||
|
|
||||||
const unchecked = getUncheckedPlatforms(distribution, reportedPlatforms);
|
const unchecked = getUncheckedPlatforms(
|
||||||
|
distribution,
|
||||||
|
reportedPlatforms,
|
||||||
|
reports[0]?.targets
|
||||||
|
);
|
||||||
if (unchecked.length > 0) {
|
if (unchecked.length > 0) {
|
||||||
lines.push(
|
lines.push(
|
||||||
`Not checked, because no runner reported these platforms: ${unchecked.join(', ')}.`,
|
`Not checked, because no runner reported these platforms: ${unchecked.join(', ')}.`,
|
||||||
@@ -614,6 +686,76 @@ export function renderMarkdownReport(
|
|||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function renderMarkdownReport(
|
||||||
|
reports: ResolutionReport[],
|
||||||
|
options: {
|
||||||
|
runUrl?: string;
|
||||||
|
expectedRefs?: string[];
|
||||||
|
overviewOnly?: boolean;
|
||||||
|
} = {}
|
||||||
|
): string {
|
||||||
|
const refs = [
|
||||||
|
...new Set([
|
||||||
|
...(options.expectedRefs ?? []),
|
||||||
|
...reports.map(report => report.source.ref)
|
||||||
|
])
|
||||||
|
];
|
||||||
|
const lines = [
|
||||||
|
'# Latest JDK versions by setup-java revision',
|
||||||
|
'',
|
||||||
|
"Each section uses that revision's own installers and dependencies. `v6` and `v5` track the latest major tags, pinned to the commits below for this run. No JDKs are downloaded.",
|
||||||
|
'',
|
||||||
|
"Older revisions may support different distributions, platforms or version syntax. In particular, `latest` is reported as `n/a` when that revision rejects it; it is not substituted with main's behavior. Revisions without capability maps probe all candidate architectures, leaving unsupported or unpublished combinations visible.",
|
||||||
|
'',
|
||||||
|
'| setup-java | Package version | Commit | Result |',
|
||||||
|
'| --- | --- | --- | --- |'
|
||||||
|
];
|
||||||
|
for (const ref of refs) {
|
||||||
|
const group = reports.filter(report => report.source.ref === ref);
|
||||||
|
if (!group.length) {
|
||||||
|
lines.push(`| \`${ref}\` | - | - | Not checked: no reports received |`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const source = group[0].source;
|
||||||
|
if (
|
||||||
|
group.some(
|
||||||
|
report =>
|
||||||
|
report.source.sha !== source.sha ||
|
||||||
|
report.source.version !== source.version
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Reports for '${ref}' were produced from different revisions.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const problems = getProblems(group.flatMap(report => report.results));
|
||||||
|
const platforms = new Set(group.map(report => report.platform));
|
||||||
|
const missing = PLATFORM_ORDER.filter(platform => !platforms.has(platform));
|
||||||
|
lines.push(
|
||||||
|
`| \`${ref}\` | ${source.version ?? 'local'} | ${source.sha ? `[\`${source.sha.slice(0, 12)}\`](https://github.com/actions/setup-java/commit/${source.sha})` : 'local checkout'} | ${platforms.size}/${PLATFORM_ORDER.length} platforms${missing.length ? `; not checked: ${missing.map(platform => PLATFORM_LABELS[platform]).join(', ')}` : ''}${problems.length ? `; ${problems.length} lookup problems` : ''} |`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (options.overviewOnly) {
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
for (const ref of refs) {
|
||||||
|
const group = reports.filter(report => report.source.ref === ref);
|
||||||
|
if (!group.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lines.push(
|
||||||
|
'',
|
||||||
|
'<details>',
|
||||||
|
`<summary>setup-java@${ref}</summary>`,
|
||||||
|
'',
|
||||||
|
renderSourceReport(group, options),
|
||||||
|
'</details>',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
function parseList(value: string | undefined, fallback: string[]): string[] {
|
function parseList(value: string | undefined, fallback: string[]): string[] {
|
||||||
const items = (value ?? '')
|
const items = (value ?? '')
|
||||||
.split(/[,\s]+/)
|
.split(/[,\s]+/)
|
||||||
@@ -638,11 +780,14 @@ function readReports(inputDir: string): ResolutionReport[] {
|
|||||||
export async function run(args: string[]): Promise<void> {
|
export async function run(args: string[]): Promise<void> {
|
||||||
const [command, target, markdownOutput] = args;
|
const [command, target, markdownOutput] = args;
|
||||||
if (command === 'resolve' && target) {
|
if (command === 'resolve' && target) {
|
||||||
|
const resolver = process.env.REPORT_RESOLVER
|
||||||
|
? await loadMetadataResolver(process.env.REPORT_RESOLVER)
|
||||||
|
: currentResolver;
|
||||||
const versions = parseList(process.env.REPORT_VERSIONS, []);
|
const versions = parseList(process.env.REPORT_VERSIONS, []);
|
||||||
const report = await resolveLatestVersions({
|
const report = await resolveLatestVersions({
|
||||||
distributions: parseList(
|
distributions: parseList(
|
||||||
process.env.REPORT_DISTRIBUTIONS,
|
process.env.REPORT_DISTRIBUTIONS,
|
||||||
REPORTED_DISTRIBUTIONS
|
resolver.distributions
|
||||||
),
|
),
|
||||||
versions:
|
versions:
|
||||||
versions.length > 0
|
versions.length > 0
|
||||||
@@ -651,7 +796,8 @@ export async function run(args: string[]): Promise<void> {
|
|||||||
new RetryingHttpClient('actions/setup-java')
|
new RetryingHttpClient('actions/setup-java')
|
||||||
),
|
),
|
||||||
architectures: parseList(process.env.REPORT_ARCHITECTURES, []),
|
architectures: parseList(process.env.REPORT_ARCHITECTURES, []),
|
||||||
platform: process.env.REPORT_PLATFORM
|
platform: process.env.REPORT_PLATFORM,
|
||||||
|
resolver
|
||||||
});
|
});
|
||||||
fs.mkdirSync(path.dirname(path.resolve(target)), {recursive: true});
|
fs.mkdirSync(path.dirname(path.resolve(target)), {recursive: true});
|
||||||
fs.writeFileSync(target, JSON.stringify(report, null, 2));
|
fs.writeFileSync(target, JSON.stringify(report, null, 2));
|
||||||
@@ -659,8 +805,9 @@ export async function run(args: string[]): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command === 'summarize' && target) {
|
if (command === 'summarize' && target) {
|
||||||
const reports = readReports(target);
|
const expectedRefs = parseList(process.env.REPORT_REFS, []);
|
||||||
if (reports.length === 0) {
|
const reports = fs.existsSync(target) ? readReports(target) : [];
|
||||||
|
if (reports.length === 0 && expectedRefs.length === 0) {
|
||||||
throw new Error(`No resolution reports found in '${target}'.`);
|
throw new Error(`No resolution reports found in '${target}'.`);
|
||||||
}
|
}
|
||||||
const {GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_RUN_ID} = process.env;
|
const {GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_RUN_ID} = process.env;
|
||||||
@@ -668,25 +815,57 @@ export async function run(args: string[]): Promise<void> {
|
|||||||
GITHUB_SERVER_URL && GITHUB_REPOSITORY && GITHUB_RUN_ID
|
GITHUB_SERVER_URL && GITHUB_REPOSITORY && GITHUB_RUN_ID
|
||||||
? `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}`
|
? `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}`
|
||||||
: undefined;
|
: undefined;
|
||||||
const markdown = renderMarkdownReport(reports, {runUrl});
|
const markdown = renderMarkdownReport(reports, {
|
||||||
|
runUrl,
|
||||||
|
expectedRefs
|
||||||
|
});
|
||||||
if (markdownOutput) {
|
if (markdownOutput) {
|
||||||
fs.writeFileSync(markdownOutput, markdown);
|
fs.writeFileSync(markdownOutput, markdown);
|
||||||
}
|
}
|
||||||
if (process.env.GITHUB_STEP_SUMMARY) {
|
if (process.env.GITHUB_STEP_SUMMARY) {
|
||||||
await core.summary.addRaw(markdown).write();
|
// GitHub limits a step summary to 1 MiB. Keep the complete report in the
|
||||||
|
// artifact even when many legacy lookup errors make it too large.
|
||||||
|
if (Buffer.byteLength(markdown, 'utf8') > 1_000_000) {
|
||||||
|
core.warning(
|
||||||
|
'The full report exceeds the job summary size limit; showing its overview.'
|
||||||
|
);
|
||||||
|
const overview = renderMarkdownReport(reports, {
|
||||||
|
runUrl,
|
||||||
|
expectedRefs,
|
||||||
|
overviewOnly: true
|
||||||
|
});
|
||||||
|
await core.summary
|
||||||
|
.addRaw(
|
||||||
|
`${overview}\n\nFull per-platform tables are in the \`latest-jdk-versions-report\` artifact${runUrl ? ` on the [workflow run](${runUrl})` : ''}. The full report exceeded GitHub's summary size limit.\n`
|
||||||
|
)
|
||||||
|
.write();
|
||||||
|
} else {
|
||||||
|
await core.summary.addRaw(markdown).write();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
core.info(markdown);
|
core.info(markdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const problem of getProblems(
|
for (const ref of expectedRefs) {
|
||||||
reports.flatMap(report => report.results)
|
if (!reports.some(report => report.source.ref === ref)) {
|
||||||
)) {
|
core.warning(
|
||||||
const scope = [problem.versionSpec, problem.platform]
|
`${ref}: not checked because no resolution reports were received.`
|
||||||
.filter(Boolean)
|
);
|
||||||
.join(', ');
|
}
|
||||||
core.warning(
|
}
|
||||||
`${problem.distribution}${scope ? ` (${scope})` : ''}: ${problem.message}`
|
for (const ref of new Set(reports.map(report => report.source.ref))) {
|
||||||
);
|
for (const problem of getProblems(
|
||||||
|
reports
|
||||||
|
.filter(report => report.source.ref === ref)
|
||||||
|
.flatMap(report => report.results)
|
||||||
|
)) {
|
||||||
|
const scope = [problem.versionSpec, problem.platform]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(', ');
|
||||||
|
core.warning(
|
||||||
|
`${ref}: ${problem.distribution}${scope ? ` (${scope})` : ''}: ${problem.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import {pathToFileURL} from 'url';
|
||||||
|
import path from 'path';
|
||||||
|
import {getJavaDistribution} from '../distributions/distribution-factory.js';
|
||||||
|
import type {JavaInstallerOptions} from '../distributions/base-models.js';
|
||||||
|
import {LibericaDistributions} from '../distributions/liberica/installer.js';
|
||||||
|
import {JavaDistribution} from '../distributions/package-types.js';
|
||||||
|
import {
|
||||||
|
JAVA_PLATFORM_CAPABILITIES,
|
||||||
|
type JavaPlatformCapability
|
||||||
|
} from '../distributions/platform-types.js';
|
||||||
|
|
||||||
|
export interface ActionSource {
|
||||||
|
ref: string;
|
||||||
|
sha?: string;
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MetadataResolver {
|
||||||
|
source: ActionSource;
|
||||||
|
distributions: string[];
|
||||||
|
capabilities?: Record<string, JavaPlatformCapability>;
|
||||||
|
getJavaDistribution(
|
||||||
|
distribution: string,
|
||||||
|
options: JavaInstallerOptions
|
||||||
|
): unknown;
|
||||||
|
createSolarisInstaller(options: JavaInstallerOptions): unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SolarisLibericaDistribution extends LibericaDistributions {
|
||||||
|
protected override getPlatformOption() {
|
||||||
|
return super.getPlatformOption('sunos');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const currentResolver: MetadataResolver = {
|
||||||
|
source: {ref: 'main'},
|
||||||
|
distributions: Object.values(JavaDistribution).filter(
|
||||||
|
distribution => distribution !== JavaDistribution.JdkFile
|
||||||
|
),
|
||||||
|
capabilities: JAVA_PLATFORM_CAPABILITIES,
|
||||||
|
getJavaDistribution,
|
||||||
|
createSolarisInstaller: options => new SolarisLibericaDistribution(options)
|
||||||
|
};
|
||||||
|
|
||||||
|
const LEGACY_ARCHITECTURES = [
|
||||||
|
'x64',
|
||||||
|
'aarch64',
|
||||||
|
'x86',
|
||||||
|
'armv7',
|
||||||
|
'ppc64le',
|
||||||
|
'ppc64',
|
||||||
|
'riscv64',
|
||||||
|
's390x'
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getResolverArchitectures(
|
||||||
|
resolver: MetadataResolver,
|
||||||
|
distribution: string,
|
||||||
|
platform: string
|
||||||
|
): string[] {
|
||||||
|
if (!resolver.distributions.includes(distribution)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
// v5 has no centralized capability map. Probe candidates with its own
|
||||||
|
// installer instead of imposing main's newer support restrictions on it.
|
||||||
|
if (!resolver.capabilities) {
|
||||||
|
if (platform === 'solaris' && distribution !== 'liberica') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return [...LEGACY_ARCHITECTURES];
|
||||||
|
}
|
||||||
|
const capability = resolver.capabilities[distribution];
|
||||||
|
if (!capability || capability.unrestricted) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const os = platform === 'linux-musl' ? 'linux' : platform;
|
||||||
|
const architectures = Object.entries(capability.platforms).find(
|
||||||
|
([name]) => name === os
|
||||||
|
)?.[1];
|
||||||
|
return [
|
||||||
|
...new Set(
|
||||||
|
(architectures ?? []).map(item =>
|
||||||
|
typeof item === 'string' ? item : item.architecture
|
||||||
|
)
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Load the separately bundled checkout, including that revision's dependencies. */
|
||||||
|
export async function loadMetadataResolver(
|
||||||
|
directory: string
|
||||||
|
): Promise<MetadataResolver> {
|
||||||
|
const module: unknown = await import(
|
||||||
|
/* webpackIgnore: true */ pathToFileURL(
|
||||||
|
path.join(path.resolve(directory), 'index.js')
|
||||||
|
).href
|
||||||
|
);
|
||||||
|
// NCC emits ESM for v6/main and CommonJS for v5.
|
||||||
|
const candidate =
|
||||||
|
isRecord(module) && isRecord(module.default) ? module.default : module;
|
||||||
|
if (!isMetadataResolver(candidate)) {
|
||||||
|
throw new Error(`Invalid metadata resolver bundle in '${directory}'.`);
|
||||||
|
}
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMetadataResolver(value: unknown): value is MetadataResolver {
|
||||||
|
return (
|
||||||
|
isRecord(value) &&
|
||||||
|
isRecord(value.source) &&
|
||||||
|
typeof value.source.ref === 'string' &&
|
||||||
|
typeof value.source.sha === 'string' &&
|
||||||
|
/^[a-f0-9]{40}$/.test(value.source.sha) &&
|
||||||
|
typeof value.source.version === 'string' &&
|
||||||
|
Array.isArray(value.distributions) &&
|
||||||
|
value.distributions.every(item => typeof item === 'string') &&
|
||||||
|
(value.capabilities === undefined || isRecord(value.capabilities)) &&
|
||||||
|
typeof value.getJavaDistribution === 'function' &&
|
||||||
|
typeof value.createSolarisInstaller === 'function'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
|
return typeof value === 'object' && value !== null;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user