mirror of
https://github.com/actions/setup-java.git
synced 2026-11-14 07:52:24 +00:00
Architecture validation for JDK file installs (#1324)
* Enhance architecture validation and error handling * Improve architecture normalization and validation for custom tokens * Refactor architecture validation to consolidate error handling for invalid tokens
This commit is contained in:
@@ -272,7 +272,7 @@ describe('findPackageForDownload', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
it.each(['zos', 'z/OS', 'z/os', 'test0987654321=', '++=++', 'myArch'])(
|
it.each(['zos', 'myArch'])(
|
||||||
'incorrect Semeru `%s` architecture throws',
|
'incorrect Semeru `%s` architecture throws',
|
||||||
async (arch: string) => {
|
async (arch: string) => {
|
||||||
const distribution = new SemeruDistribution({
|
const distribution = new SemeruDistribution({
|
||||||
|
|||||||
@@ -31,6 +31,36 @@ describe('Java platform capabilities', () => {
|
|||||||
expect(normalizeArchitecture(input)).toBe(expected);
|
expect(normalizeArchitecture(input)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each(['constructor', 'Constructor'])(
|
||||||
|
'preserves custom architecture token %s for jdkfile',
|
||||||
|
architecture => {
|
||||||
|
expect(normalizeArchitecture(architecture)).toBe(architecture);
|
||||||
|
expect(validateJavaPlatform('jdkfile', 'linux', architecture, '17')).toBe(
|
||||||
|
architecture
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
'x64<<end\nvalue\nend',
|
||||||
|
'z/OS',
|
||||||
|
'z/os',
|
||||||
|
'test0987654321=',
|
||||||
|
'++=++',
|
||||||
|
'../x64',
|
||||||
|
'x64\\other',
|
||||||
|
'x64 other',
|
||||||
|
'-x64',
|
||||||
|
'_x64'
|
||||||
|
])('rejects invalid architecture token %s', architecture => {
|
||||||
|
const message = `Unsupported architecture value: ${JSON.stringify(architecture)}`;
|
||||||
|
|
||||||
|
expect(() => normalizeArchitecture(architecture)).toThrow(message);
|
||||||
|
expect(() =>
|
||||||
|
validateJavaPlatform('jdkfile', 'linux', architecture, '17')
|
||||||
|
).toThrow(message);
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['linux', false, 'linux-glibc'],
|
['linux', false, 'linux-glibc'],
|
||||||
['linux', true, 'linux-musl'],
|
['linux', true, 'linux-musl'],
|
||||||
|
|||||||
Vendored
+11
-2
@@ -31545,6 +31545,8 @@ const CANONICAL_ARCHITECTURES = [
|
|||||||
'riscv64',
|
'riscv64',
|
||||||
's390x'
|
's390x'
|
||||||
];
|
];
|
||||||
|
// Used in environment-variable names and tool-cache paths.
|
||||||
|
const ARCHITECTURE_TOKEN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
||||||
const PLATFORM_ALIASES = {
|
const PLATFORM_ALIASES = {
|
||||||
darwin: 'macos',
|
darwin: 'macos',
|
||||||
linux: 'linux',
|
linux: 'linux',
|
||||||
@@ -31554,10 +31556,17 @@ const PLATFORM_ALIASES = {
|
|||||||
function normalizeArchitecture(architecture) {
|
function normalizeArchitecture(architecture) {
|
||||||
const trimmedArchitecture = architecture.trim();
|
const trimmedArchitecture = architecture.trim();
|
||||||
const normalizedArchitecture = trimmedArchitecture.toLowerCase();
|
const normalizedArchitecture = trimmedArchitecture.toLowerCase();
|
||||||
return (ARCHITECTURE_ALIASES[normalizedArchitecture] ??
|
const alias = Object.prototype.hasOwnProperty.call(ARCHITECTURE_ALIASES, normalizedArchitecture)
|
||||||
|
? ARCHITECTURE_ALIASES[normalizedArchitecture]
|
||||||
|
: undefined;
|
||||||
|
const result = alias ??
|
||||||
(CANONICAL_ARCHITECTURES.includes(normalizedArchitecture)
|
(CANONICAL_ARCHITECTURES.includes(normalizedArchitecture)
|
||||||
? normalizedArchitecture
|
? normalizedArchitecture
|
||||||
: trimmedArchitecture));
|
: trimmedArchitecture);
|
||||||
|
if (!ARCHITECTURE_TOKEN.test(result)) {
|
||||||
|
throw new Error(`Unsupported architecture value: ${JSON.stringify(architecture)}`);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
function normalizePlatform(platform) {
|
function normalizePlatform(platform) {
|
||||||
return PLATFORM_ALIASES[platform];
|
return PLATFORM_ALIASES[platform];
|
||||||
|
|||||||
@@ -659,9 +659,10 @@ runner, distribution, JDK size, network, and cache eviction pressure.
|
|||||||
|
|
||||||
The `architecture` input is normalized before setup-java checks the tool cache
|
The `architecture` input is normalized before setup-java checks the tool cache
|
||||||
or contacts a vendor. `amd64`, `ia32`, `arm`, and `arm64` are accepted aliases
|
or contacts a vendor. `amd64`, `ia32`, `arm`, and `arm64` are accepted aliases
|
||||||
for `x64`, `x86`, `armv7`, and `aarch64`. The table lists the combinations
|
for `x64`, `x86`, `armv7`, and `aarch64`. Every value must be one token that
|
||||||
setup-java validates up front; an individual Java patch release can still be
|
starts with a letter or digit and contains only letters, digits, `_`, or `-`.
|
||||||
absent from a vendor catalog.
|
The table lists the combinations setup-java validates up front; an individual
|
||||||
|
Java patch release can still be absent from a vendor catalog.
|
||||||
|
|
||||||
| Distribution | Linux | macOS | Windows | Other / version restrictions |
|
| Distribution | Linux | macOS | Windows | Other / version restrictions |
|
||||||
| --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
|
|||||||
@@ -192,6 +192,9 @@ const CANONICAL_ARCHITECTURES: readonly JavaArchitecture[] = [
|
|||||||
's390x'
|
's390x'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Used in environment-variable names and tool-cache paths.
|
||||||
|
const ARCHITECTURE_TOKEN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
||||||
|
|
||||||
const PLATFORM_ALIASES: Readonly<
|
const PLATFORM_ALIASES: Readonly<
|
||||||
Partial<Record<NodeJS.Platform, JavaPlatform>>
|
Partial<Record<NodeJS.Platform, JavaPlatform>>
|
||||||
> = {
|
> = {
|
||||||
@@ -204,14 +207,27 @@ const PLATFORM_ALIASES: Readonly<
|
|||||||
export function normalizeArchitecture(architecture: string): string {
|
export function normalizeArchitecture(architecture: string): string {
|
||||||
const trimmedArchitecture = architecture.trim();
|
const trimmedArchitecture = architecture.trim();
|
||||||
const normalizedArchitecture = trimmedArchitecture.toLowerCase();
|
const normalizedArchitecture = trimmedArchitecture.toLowerCase();
|
||||||
return (
|
const alias = Object.prototype.hasOwnProperty.call(
|
||||||
ARCHITECTURE_ALIASES[normalizedArchitecture] ??
|
ARCHITECTURE_ALIASES,
|
||||||
|
normalizedArchitecture
|
||||||
|
)
|
||||||
|
? ARCHITECTURE_ALIASES[normalizedArchitecture]
|
||||||
|
: undefined;
|
||||||
|
const result =
|
||||||
|
alias ??
|
||||||
(CANONICAL_ARCHITECTURES.includes(
|
(CANONICAL_ARCHITECTURES.includes(
|
||||||
normalizedArchitecture as JavaArchitecture
|
normalizedArchitecture as JavaArchitecture
|
||||||
)
|
)
|
||||||
? normalizedArchitecture
|
? normalizedArchitecture
|
||||||
: trimmedArchitecture)
|
: trimmedArchitecture);
|
||||||
|
|
||||||
|
if (!ARCHITECTURE_TOKEN.test(result)) {
|
||||||
|
throw new Error(
|
||||||
|
`Unsupported architecture value: ${JSON.stringify(architecture)}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizePlatform(
|
export function normalizePlatform(
|
||||||
|
|||||||
Reference in New Issue
Block a user