mirror of
https://github.com/actions/setup-java.git
synced 2026-11-20 19:33:06 +00:00
Compare commits
2 Commits
copilot/re
...
e1ce3a3428
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1ce3a3428 | ||
|
|
ce75feb3d3 |
@@ -89,7 +89,7 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `gpg-passphrase-env-var`: Environment variable name for the GPG private key passphrase. Default is GPG\_PASSPHRASE.
|
- `gpg-passphrase-env-var`: Environment variable name for the GPG private key passphrase. Default is GPG\_PASSPHRASE.
|
||||||
|
|
||||||
- `mvn-toolchain-id`: Name of Maven Toolchain ID if the default name of `${distribution}_${java-version}` is not wanted.
|
- `mvn-toolchain-id`: Name of Maven Toolchain ID if the default name of `${distribution}_${java-version}` is not wanted. When supplied, the number of IDs must match the number of Java versions.
|
||||||
|
|
||||||
- `mvn-toolchain-vendor`: Name of Maven Toolchain Vendor if the default name of `${distribution}` is not wanted.
|
- `mvn-toolchain-vendor`: Name of Maven Toolchain Vendor if the default name of `${distribution}` is not wanted.
|
||||||
|
|
||||||
|
|||||||
@@ -1007,3 +1007,67 @@ describe('toolchains tests', () => {
|
|||||||
expect((contents.match(/<toolchain>/g) || []).length).toBe(runs.length);
|
expect((contents.match(/<toolchain>/g) || []).length).toBe(runs.length);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('validateToolchainIds', () => {
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
name: 'uses generated IDs when no custom IDs are supplied',
|
||||||
|
versions: ['17', '21'],
|
||||||
|
versionFile: '',
|
||||||
|
toolchainIds: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'accepts one custom ID for a single Java version',
|
||||||
|
versions: ['21'],
|
||||||
|
versionFile: '',
|
||||||
|
toolchainIds: ['custom-21']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'accepts one custom ID per Java version',
|
||||||
|
versions: ['17', '21'],
|
||||||
|
versionFile: '',
|
||||||
|
toolchainIds: ['custom-17', 'custom-21']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'accepts one custom ID with java-version-file',
|
||||||
|
versions: [],
|
||||||
|
versionFile: '.java-version',
|
||||||
|
toolchainIds: ['custom-file-version']
|
||||||
|
}
|
||||||
|
])('$name', ({versions, versionFile, toolchainIds}) => {
|
||||||
|
expect(() =>
|
||||||
|
toolchains.validateToolchainIds(versions, versionFile, toolchainIds)
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
name: 'rejects fewer IDs than Java versions',
|
||||||
|
versions: ['17', '21'],
|
||||||
|
versionFile: '',
|
||||||
|
toolchainIds: ['custom-17'],
|
||||||
|
expectedMessage:
|
||||||
|
'The number of Maven toolchain IDs (1) must match the number of Java versions (2)'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'rejects extra IDs for a single Java version',
|
||||||
|
versions: ['21'],
|
||||||
|
versionFile: '',
|
||||||
|
toolchainIds: ['custom-21', 'custom-extra'],
|
||||||
|
expectedMessage:
|
||||||
|
'The number of Maven toolchain IDs (2) must match the number of Java versions (1)'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'rejects extra IDs with java-version-file',
|
||||||
|
versions: [],
|
||||||
|
versionFile: '.java-version',
|
||||||
|
toolchainIds: ['custom-file-version', 'custom-extra'],
|
||||||
|
expectedMessage:
|
||||||
|
'The number of Maven toolchain IDs (2) must match the number of Java versions (1)'
|
||||||
|
}
|
||||||
|
])('$name', ({versions, versionFile, toolchainIds, expectedMessage}) => {
|
||||||
|
expect(() =>
|
||||||
|
toolchains.validateToolchainIds(versions, versionFile, toolchainIds)
|
||||||
|
).toThrow(expectedMessage);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -57,9 +57,73 @@ const {
|
|||||||
isCacheFeatureAvailable,
|
isCacheFeatureAvailable,
|
||||||
isGhes,
|
isGhes,
|
||||||
validatePaginationUrl,
|
validatePaginationUrl,
|
||||||
getLatestMajorVersion
|
getLatestMajorVersion,
|
||||||
|
getBooleanInput
|
||||||
} = await import('../src/util.js');
|
} = await import('../src/util.js');
|
||||||
|
|
||||||
|
describe('getBooleanInput', () => {
|
||||||
|
let inputs: Record<string, string>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
inputs = {};
|
||||||
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
|
(name: string) => inputs[name] ?? ''
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['true', true],
|
||||||
|
['TRUE', true],
|
||||||
|
['TrUe', true],
|
||||||
|
[' true ', true],
|
||||||
|
['false', false],
|
||||||
|
['FALSE', false],
|
||||||
|
['FaLsE', false],
|
||||||
|
[' false ', false]
|
||||||
|
])('parses %j as %s', (value: string, expected: boolean) => {
|
||||||
|
inputs['boolean-input'] = value;
|
||||||
|
|
||||||
|
expect(getBooleanInput('boolean-input')).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[undefined, false],
|
||||||
|
[false, false],
|
||||||
|
[true, true]
|
||||||
|
])(
|
||||||
|
'uses the configured default %s when the input is omitted',
|
||||||
|
(defaultValue: boolean | undefined, expected: boolean) => {
|
||||||
|
expect(getBooleanInput('boolean-input', defaultValue)).toBe(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it('uses the configured default for a whitespace-only input', () => {
|
||||||
|
inputs['boolean-input'] = ' ';
|
||||||
|
|
||||||
|
expect(getBooleanInput('boolean-input', true)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
'check-latest',
|
||||||
|
'force-download',
|
||||||
|
'set-default',
|
||||||
|
'verify-signature',
|
||||||
|
'overwrite-settings',
|
||||||
|
'show-download-progress',
|
||||||
|
'problem-matcher'
|
||||||
|
])('rejects an invalid value for %s', inputName => {
|
||||||
|
inputs[inputName] = 'ture';
|
||||||
|
|
||||||
|
expect(() => getBooleanInput(inputName)).toThrow(
|
||||||
|
`Invalid value 'ture' for boolean input '${inputName}'. Expected 'true' or 'false'.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('isVersionSatisfies', () => {
|
describe('isVersionSatisfies', () => {
|
||||||
it.each([
|
it.each([
|
||||||
['x', '11.0.0', true],
|
['x', '11.0.0', true],
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||||
mvn-toolchain-id:
|
mvn-toolchain-id:
|
||||||
description: 'Name of Maven Toolchain ID if the default name of "${distribution}_${java-version}" is not wanted. See examples of supported syntax in Advanced Usage file'
|
description: 'Name of Maven Toolchain ID if the default name of "${distribution}_${java-version}" is not wanted. When supplied, the number of IDs must match the number of Java versions. See examples of supported syntax in Advanced Usage file'
|
||||||
required: false
|
required: false
|
||||||
mvn-toolchain-vendor:
|
mvn-toolchain-vendor:
|
||||||
description: 'Name of Maven Toolchain Vendor if the default name of "${distribution}" is not wanted. See examples of supported syntax in Advanced Usage file'
|
description: 'Name of Maven Toolchain Vendor if the default name of "${distribution}" is not wanted. See examples of supported syntax in Advanced Usage file'
|
||||||
|
|||||||
13
dist/cleanup/index.js
vendored
13
dist/cleanup/index.js
vendored
@@ -97365,7 +97365,18 @@ function getTempDir() {
|
|||||||
return tempDirectory;
|
return tempDirectory;
|
||||||
}
|
}
|
||||||
function util_getBooleanInput(inputName, defaultValue = false) {
|
function util_getBooleanInput(inputName, defaultValue = false) {
|
||||||
return ((core.getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE');
|
const inputValue = core.getInput(inputName);
|
||||||
|
const normalizedValue = inputValue.trim().toLowerCase();
|
||||||
|
if (!normalizedValue) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if (normalizedValue === 'true') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (normalizedValue === 'false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw new Error(`Invalid value '${inputValue}' for boolean input '${inputName}'. Expected 'true' or 'false'.`);
|
||||||
}
|
}
|
||||||
function getVersionFromToolcachePath(toolPath) {
|
function getVersionFromToolcachePath(toolPath) {
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
|
|||||||
28
dist/setup/index.js
vendored
28
dist/setup/index.js
vendored
@@ -128364,7 +128364,18 @@ function getTempDir() {
|
|||||||
return tempDirectory;
|
return tempDirectory;
|
||||||
}
|
}
|
||||||
function util_getBooleanInput(inputName, defaultValue = false) {
|
function util_getBooleanInput(inputName, defaultValue = false) {
|
||||||
return ((getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE');
|
const inputValue = getInput(inputName);
|
||||||
|
const normalizedValue = inputValue.trim().toLowerCase();
|
||||||
|
if (!normalizedValue) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if (normalizedValue === 'true') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (normalizedValue === 'false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw new Error(`Invalid value '${inputValue}' for boolean input '${inputName}'. Expected 'true' or 'false'.`);
|
||||||
}
|
}
|
||||||
function getVersionFromToolcachePath(toolPath) {
|
function getVersionFromToolcachePath(toolPath) {
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
@@ -128865,6 +128876,15 @@ async function write(directory, settings, overwriteSettings) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function validateToolchainIds(versions, versionFile, toolchainIds) {
|
||||||
|
if (!toolchainIds.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const versionCount = versions.length || (versionFile ? 1 : 0);
|
||||||
|
if (versionCount !== toolchainIds.length) {
|
||||||
|
throw new Error(`The number of Maven toolchain IDs (${toolchainIds.length}) must match the number of Java versions (${versionCount})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
async function configureToolchains(version, distributionName, jdkHome, toolchainId) {
|
async function configureToolchains(version, distributionName, jdkHome, toolchainId) {
|
||||||
const vendor = getInput(INPUT_MVN_TOOLCHAIN_VENDOR) || distributionName;
|
const vendor = getInput(INPUT_MVN_TOOLCHAIN_VENDOR) || distributionName;
|
||||||
const id = toolchainId || `${vendor}_${version}`;
|
const id = toolchainId || `${vendor}_${version}`;
|
||||||
@@ -132191,14 +132211,12 @@ async function run() {
|
|||||||
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
|
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
|
||||||
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
|
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
|
||||||
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
||||||
let toolchainIds = getMultilineInput(INPUT_MVN_TOOLCHAIN_ID);
|
const toolchainIds = getMultilineInput(INPUT_MVN_TOOLCHAIN_ID);
|
||||||
startGroup('Installed distributions');
|
startGroup('Installed distributions');
|
||||||
if (versions.length !== toolchainIds.length) {
|
|
||||||
toolchainIds = [];
|
|
||||||
}
|
|
||||||
if (!versions.length && !versionFile) {
|
if (!versions.length && !versionFile) {
|
||||||
throw new Error('java-version or java-version-file input expected');
|
throw new Error('java-version or java-version-file input expected');
|
||||||
}
|
}
|
||||||
|
validateToolchainIds(versions, versionFile, toolchainIds);
|
||||||
if (!versions.length) {
|
if (!versions.length) {
|
||||||
core_debug('java-version input is empty, looking for java-version-file input');
|
core_debug('java-version input is empty, looking for java-version-file input');
|
||||||
const content = external_fs_default().readFileSync(versionFile).toString().trim();
|
const content = external_fs_default().readFileSync(versionFile).toString().trim();
|
||||||
|
|||||||
@@ -980,7 +980,7 @@ steps:
|
|||||||
- run: java --version
|
- run: java --version
|
||||||
```
|
```
|
||||||
|
|
||||||
In case you install multiple versions of Java at once you can use the same syntax as used in `java-versions`. Please note that you have to declare an ID for all Java versions that will be installed or the `mvn-toolchain-id` instruction will be skipped wholesale due to mapping ambiguities.
|
When installing multiple Java versions, use the same multiline syntax as `java-version`. You must declare exactly one ID for every Java version that will be installed. The action fails before installing a JDK unless the number of `mvn-toolchain-id` entries matches the number of `java-version` entries, or is exactly one when `java-version-file` is used.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -40,18 +40,18 @@ async function run() {
|
|||||||
);
|
);
|
||||||
const verifySignaturePublicKey =
|
const verifySignaturePublicKey =
|
||||||
core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
||||||
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
const toolchainIds = core.getMultilineInput(
|
||||||
|
constants.INPUT_MVN_TOOLCHAIN_ID
|
||||||
|
);
|
||||||
|
|
||||||
core.startGroup('Installed distributions');
|
core.startGroup('Installed distributions');
|
||||||
|
|
||||||
if (versions.length !== toolchainIds.length) {
|
|
||||||
toolchainIds = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!versions.length && !versionFile) {
|
if (!versions.length && !versionFile) {
|
||||||
throw new Error('java-version or java-version-file input expected');
|
throw new Error('java-version or java-version-file input expected');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toolchains.validateToolchainIds(versions, versionFile, toolchainIds);
|
||||||
|
|
||||||
if (!versions.length) {
|
if (!versions.length) {
|
||||||
core.debug(
|
core.debug(
|
||||||
'java-version input is empty, looking for java-version-file input'
|
'java-version input is empty, looking for java-version-file input'
|
||||||
|
|||||||
@@ -14,6 +14,23 @@ interface JdkInfo {
|
|||||||
jdkHome: string;
|
jdkHome: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function validateToolchainIds(
|
||||||
|
versions: string[],
|
||||||
|
versionFile: string,
|
||||||
|
toolchainIds: string[]
|
||||||
|
) {
|
||||||
|
if (!toolchainIds.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionCount = versions.length || (versionFile ? 1 : 0);
|
||||||
|
if (versionCount !== toolchainIds.length) {
|
||||||
|
throw new Error(
|
||||||
|
`The number of Maven toolchain IDs (${toolchainIds.length}) must match the number of Java versions (${versionCount})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function configureToolchains(
|
export async function configureToolchains(
|
||||||
version: string,
|
version: string,
|
||||||
distributionName: string,
|
distributionName: string,
|
||||||
|
|||||||
17
src/util.ts
17
src/util.ts
@@ -20,8 +20,21 @@ export function getTempDir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBooleanInput(inputName: string, defaultValue = false) {
|
export function getBooleanInput(inputName: string, defaultValue = false) {
|
||||||
return (
|
const inputValue = core.getInput(inputName);
|
||||||
(core.getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE'
|
const normalizedValue = inputValue.trim().toLowerCase();
|
||||||
|
|
||||||
|
if (!normalizedValue) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if (normalizedValue === 'true') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (normalizedValue === 'false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Invalid value '${inputValue}' for boolean input '${inputName}'. Expected 'true' or 'false'.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user