Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added .tool-versions file support #606

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c3eb4ca
Merge pull request #1 from actions/main
mahabaleshwars Mar 4, 2024
7abdf1c
added support for tool version file
mahabaleshwars Mar 4, 2024
a7f2ec4
testing with one regex
mahabaleshwars Mar 4, 2024
12fa539
working regex
mahabaleshwars Mar 4, 2024
3ac7f4d
Checked for the file extension
mahabaleshwars Mar 4, 2024
7ac1739
added e2e checks for tool version
mahabaleshwars Mar 4, 2024
c2eed4c
removed error warning
mahabaleshwars Mar 5, 2024
d6dce30
updated regex to support early version
mahabaleshwars Mar 7, 2024
15bd552
updated regex for early version support
mahabaleshwars Mar 7, 2024
091c706
updated regex for early version
mahabaleshwars Mar 7, 2024
23f648d
updated regex to accept early versions
mahabaleshwars Mar 8, 2024
108d337
added coreinfo to analyze
mahabaleshwars Mar 8, 2024
600bab6
updated the regex
mahabaleshwars Mar 8, 2024
7e1d245
updated regex
mahabaleshwars Mar 8, 2024
7c2ba30
new regex for early version
mahabaleshwars Mar 8, 2024
4963182
updated regex to match the new version file format
mahabaleshwars Mar 8, 2024
5633ed7
new regex
mahabaleshwars Mar 8, 2024
0bd564a
changed the regex
mahabaleshwars Mar 8, 2024
dc07897
redex updated
mahabaleshwars Mar 8, 2024
ac5ac98
used java version regex
mahabaleshwars Mar 8, 2024
00ea4e3
regex updated
mahabaleshwars Mar 8, 2024
3a44440
regex modified
mahabaleshwars Mar 8, 2024
ae1e7f4
regex updated
mahabaleshwars Mar 8, 2024
4ef246e
regex updated
mahabaleshwars Mar 8, 2024
8c268be
regex updated
mahabaleshwars Mar 8, 2024
c5831e8
updated regex to support early versions
mahabaleshwars Mar 8, 2024
0d65cda
Regex updated to support all java versions
mahabaleshwars Mar 8, 2024
4253d87
Documentation updated to add tool version description
mahabaleshwars Mar 11, 2024
33cfd28
Documentation updated for the tool version file
mahabaleshwars Mar 12, 2024
b71bea4
update the advanced doc and readme file to specify tool version changes
mahabaleshwars Mar 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/e2e-versions.yml
Expand Up @@ -288,19 +288,23 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
distribution: ['temurin', 'microsoft', 'corretto']
java-version-file: ['.java-version', '.tool-versions']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create .java-version file
shell: bash
run: echo "8" > .java-version
- name: Create .tool-versions file
shell: bash
run: echo "java 8" > .tool-versions
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version: 11
java-version-file: '.java-version'
java-version-file: ${{matrix.java-version-file }}
- name: Verify Java
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
shell: bash
Expand All @@ -313,18 +317,22 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
distribution: ['temurin', 'zulu', 'liberica', 'microsoft', 'corretto']
java-version-file: ['.java-version', '.tool-versions']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create .java-version file
shell: bash
run: echo "11" > .java-version
- name: Create .tool-versions file
shell: bash
run: echo "java 11" > .tool-versions
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: '.java-version'
java-version-file: ${{matrix.java-version-file }}
- name: Verify Java
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
shell: bash
Expand All @@ -337,18 +345,22 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
distribution: ['adopt', 'adopt-openj9', 'zulu']
java-version-file: ['.java-version', '.tool-versions']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create .java-version file
shell: bash
run: echo "11.0.2" > .java-version
- name: Create .tool-versions file
shell: bash
run: echo "java 11.0.2" > .tool-versions
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: '.java-version'
java-version-file: ${{matrix.java-version-file }}
- name: Verify Java
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
shell: bash
Expand All @@ -361,18 +373,22 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
distribution: ['adopt', 'zulu', 'liberica']
java-version-file: ['.java-version', '.tool-versions']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create .java-version file
shell: bash
run: echo "openjdk64-11.0.2" > .java-version
- name: Create .tool-versions file
shell: bash
run: echo "java openjdk64-11.0.2" > .tool-versions
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: '.java-version'
java-version-file: ${{matrix.java-version-file }}
- name: Verify Java
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
shell: bash
13 changes: 11 additions & 2 deletions dist/cleanup/index.js
Expand Up @@ -87887,9 +87887,18 @@ function isCacheFeatureAvailable() {
return false;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName) {
function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e;
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
let javaVersionRegExp;
if (versionFile == '.tool-versions') {
javaVersionRegExp = /^java\s+(?:\S+-)?v?(?<version>[^\s]+)$/m;
}
else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
else {
throw new Error('Invalid version file');
}
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
: '';
Expand Down
15 changes: 12 additions & 3 deletions dist/setup/index.js
Expand Up @@ -124907,7 +124907,7 @@ function run() {
if (!versions.length) {
core.debug('java-version input is empty, looking for java-version-file input');
const content = fs_1.default.readFileSync(versionFile).toString().trim();
const version = (0, util_1.getVersionFromFileContent)(content, distributionName);
const version = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
core.debug(`Parsed version from file '${version}'`);
if (!version) {
throw new Error(`No supported version was found in file ${versionFile}`);
Expand Down Expand Up @@ -125261,9 +125261,18 @@ function isCacheFeatureAvailable() {
return false;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName) {
function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e;
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
let javaVersionRegExp;
if (versionFile == '.tool-versions') {
javaVersionRegExp = /^java\s+(?:\S+-)?v?(?<version>[^\s]+)$/m;
}
Copy link

@rtyley rtyley Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this regex will not accept full java versions commonly generated in asdf using latest - eg:

asdf local java latest:corretto-21

...will generate a file with this line:

java corretto-21.0.2.13.1

The regex doesn't recognise this, so setup-java will fail with this message:

Error: No supported version was found in file .tool-versions

If we play around with the regex, we can see that we have to edit the string down to java corretto-21.0.2 in order to get it to work:

image

else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
else {
throw new Error('Invalid version file');
}
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
: '';
Expand Down
6 changes: 5 additions & 1 deletion src/setup-java.ts
Expand Up @@ -55,7 +55,11 @@ async function run() {
);
const content = fs.readFileSync(versionFile).toString().trim();

const version = getVersionFromFileContent(content, distributionName);
const version = getVersionFromFileContent(
content,
distributionName,
versionFile
);
core.debug(`Parsed version from file '${version}'`);

if (!version) {
Expand Down
13 changes: 11 additions & 2 deletions src/util.ts
Expand Up @@ -115,9 +115,18 @@ export function isCacheFeatureAvailable(): boolean {

export function getVersionFromFileContent(
content: string,
distributionName: string
distributionName: string,
versionFile: string
): string | null {
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
let javaVersionRegExp: RegExp;
if (versionFile == '.tool-versions') {
javaVersionRegExp = /^java\s+(?:\S+-)?v?(?<version>[^\s]+)$/m;
} else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} else {
throw new Error('Invalid version file');
}

const fileContent = content.match(javaVersionRegExp)?.groups?.version
? (content.match(javaVersionRegExp)?.groups?.version as string)
: '';
Expand Down