mirror of
https://github.com/actions/setup-java.git
synced 2025-12-08 17:15:45 +08:00
feat: Add support for .sdkmanrc file in java-version-file parameter (#736)
* chore(e2e-versions): Add e2e test scenario on `setup-java-version-from-file-major-minor-patch-with-dist` for `.sdkmanrc` * chore(e2e-versions): Update `setup-java-version-from-file-major-minor-patch-with-dist` test to include the file name of the java-version-file that is used * feat: Add support for `.sdkmanrc` as *Java Version File* * chore: Add test for the latest known sdkman java versions * docs(advanced-usage): Document support for `.sdkmanrc` as java-version-file * chore(docs): Anyone can contribute and maintain 🤷 * Update advanced-usage.md Add example step/file for `.sdkmanrc` * Update advanced-usage.md * Update util.ts * chore: format and rebuild * chore: untouch toolchains.ts * fix check dist error --------- Co-authored-by: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {
|
||||
convertVersionToSemver,
|
||||
getVersionFromFileContent,
|
||||
isVersionSatisfies,
|
||||
isCacheFeatureAvailable,
|
||||
isGhes
|
||||
@@ -82,6 +85,43 @@ describe('convertVersionToSemver', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getVersionFromFileContent', () => {
|
||||
describe('.sdkmanrc', () => {
|
||||
it.each([
|
||||
['java=11.0.20.1-tem', '11.0.20'],
|
||||
['java = 11.0.20.1-tem', '11.0.20'],
|
||||
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'],
|
||||
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match
|
||||
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match
|
||||
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc
|
||||
])('parsing %s should return %s', (content: string, expected: string) => {
|
||||
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
|
||||
describe('known versions', () => {
|
||||
const csv = fs.readFileSync(
|
||||
path.join(__dirname, 'data/sdkman-java-versions.csv'),
|
||||
'utf8'
|
||||
);
|
||||
const versions = csv.split('\n').map(r => r.split(', '));
|
||||
|
||||
it.each(versions)(
|
||||
'parsing %s should return %s',
|
||||
(sdkmanJavaVersion: string, expected: string) => {
|
||||
const asContent = `java=${sdkmanJavaVersion}`;
|
||||
const actual = getVersionFromFileContent(
|
||||
asContent,
|
||||
'openjdk',
|
||||
'.sdkmanrc'
|
||||
);
|
||||
expect(actual).toBe(expected);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isGhes', () => {
|
||||
const pristineEnv = process.env;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user