From 7abdf1c01e22749cbcbc2a7d6da6726907f46f6f Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Mon, 4 Mar 2024 12:07:27 +0530 Subject: [PATCH 1/6] added support for tool version file --- dist/cleanup/index.js | 10 ++++++++-- dist/setup/index.js | 12 +++++++++--- src/setup-java.ts | 6 +++++- src/util.ts | 11 +++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 971673a5..0bdc0310 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -87887,9 +87887,15 @@ function isCacheFeatureAvailable() { return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; -function getVersionFromFileContent(content, distributionName) { +function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; - const javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + let javaVersionRegExp; + if (versionFile == '.tool-versions') { + javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + } + else { + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } 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 : ''; diff --git a/dist/setup/index.js b/dist/setup/index.js index f8c70dab..2936d56d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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}`); @@ -125261,9 +125261,15 @@ function isCacheFeatureAvailable() { return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; -function getVersionFromFileContent(content, distributionName) { +function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; - const javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + let javaVersionRegExp; + if (versionFile == '.tool-versions') { + javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + } + else { + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } 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 : ''; diff --git a/src/setup-java.ts b/src/setup-java.ts index 35a315df..73baf33a 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -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) { diff --git a/src/util.ts b/src/util.ts index 94be2347..a4c77faa 100644 --- a/src/util.ts +++ b/src/util.ts @@ -115,9 +115,16 @@ export function isCacheFeatureAvailable(): boolean { export function getVersionFromFileContent( content: string, - distributionName: string + distributionName: string, + versionFile: string ): string | null { - const javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + let javaVersionRegExp: RegExp; + if (versionFile == '.tool-versions') { + javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + } else { + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } + const fileContent = content.match(javaVersionRegExp)?.groups?.version ? (content.match(javaVersionRegExp)?.groups?.version as string) : ''; From a7f2ec40007d79e424f0b70efc555859d03ba96f Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Mon, 4 Mar 2024 13:20:49 +0530 Subject: [PATCH 2/6] testing with one regex --- dist/cleanup/index.js | 13 ++++++------- dist/setup/index.js | 13 ++++++------- src/util.ts | 13 +++++++------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 0bdc0310..54fe296b 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -87889,13 +87889,12 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; - let javaVersionRegExp; - if (versionFile == '.tool-versions') { - javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - } - else { - javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - } + const javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + // if (versionFile == '.tool-versions') { + // javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + // } else { + // javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + // } 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 : ''; diff --git a/dist/setup/index.js b/dist/setup/index.js index 2936d56d..66091b9f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -125263,13 +125263,12 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; - let javaVersionRegExp; - if (versionFile == '.tool-versions') { - javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - } - else { - javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - } + const javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + // if (versionFile == '.tool-versions') { + // javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + // } else { + // javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + // } 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 : ''; diff --git a/src/util.ts b/src/util.ts index a4c77faa..7f792080 100644 --- a/src/util.ts +++ b/src/util.ts @@ -118,12 +118,13 @@ export function getVersionFromFileContent( distributionName: string, versionFile: string ): string | null { - let javaVersionRegExp: RegExp; - if (versionFile == '.tool-versions') { - javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - } else { - javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - } + const javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + + // if (versionFile == '.tool-versions') { + // javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + // } else { + // javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + // } const fileContent = content.match(javaVersionRegExp)?.groups?.version ? (content.match(javaVersionRegExp)?.groups?.version as string) From 12fa539aa2fa404059c60954f4c5dfb3a4f1283d Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Mon, 4 Mar 2024 13:27:16 +0530 Subject: [PATCH 3/6] working regex --- dist/cleanup/index.js | 13 +++++++------ dist/setup/index.js | 13 +++++++------ src/util.ts | 13 ++++++------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 54fe296b..0bdc0310 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -87889,12 +87889,13 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; - const javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - // if (versionFile == '.tool-versions') { - // javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - // } else { - // javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - // } + let javaVersionRegExp; + if (versionFile == '.tool-versions') { + javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + } + else { + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } 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 : ''; diff --git a/dist/setup/index.js b/dist/setup/index.js index 66091b9f..2936d56d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -125263,12 +125263,13 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; - const javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - // if (versionFile == '.tool-versions') { - // javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - // } else { - // javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - // } + let javaVersionRegExp; + if (versionFile == '.tool-versions') { + javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + } + else { + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } 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 : ''; diff --git a/src/util.ts b/src/util.ts index 7f792080..a4c77faa 100644 --- a/src/util.ts +++ b/src/util.ts @@ -118,13 +118,12 @@ export function getVersionFromFileContent( distributionName: string, versionFile: string ): string | null { - const javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - - // if (versionFile == '.tool-versions') { - // javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - // } else { - // javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - // } + let javaVersionRegExp: RegExp; + if (versionFile == '.tool-versions') { + javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; + } else { + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } const fileContent = content.match(javaVersionRegExp)?.groups?.version ? (content.match(javaVersionRegExp)?.groups?.version as string) From 3ac7f4d7acd105c4415de639b562df294b8423b2 Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Mon, 4 Mar 2024 13:36:34 +0530 Subject: [PATCH 4/6] Checked for the file extension --- dist/cleanup/index.js | 5 ++++- dist/setup/index.js | 5 ++++- src/util.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 0bdc0310..f8989c28 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -87893,9 +87893,12 @@ function getVersionFromFileContent(content, distributionName, versionFile) { if (versionFile == '.tool-versions') { javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; } - else { + else if (versionFile == '.java-version') { javaVersionRegExp = /(?(?<=(^|\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 : ''; diff --git a/dist/setup/index.js b/dist/setup/index.js index 2936d56d..bcc80163 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -125267,9 +125267,12 @@ function getVersionFromFileContent(content, distributionName, versionFile) { if (versionFile == '.tool-versions') { javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; } - else { + else if (versionFile == '.java-version') { javaVersionRegExp = /(?(?<=(^|\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 : ''; diff --git a/src/util.ts b/src/util.ts index a4c77faa..4d61574e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,6 +8,7 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; import {INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION} from './constants'; import {OutgoingHttpHeaders} from 'http'; +import {error} from 'console'; export function getTempDir() { const tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir(); @@ -121,8 +122,10 @@ export function getVersionFromFileContent( let javaVersionRegExp: RegExp; if (versionFile == '.tool-versions') { javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - } else { + } else if (versionFile == '.java-version') { javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } else { + throw new Error('Invalid version file'); } const fileContent = content.match(javaVersionRegExp)?.groups?.version From 7ac17397e842e255f893e612d144cda3855e1b1e Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Mon, 4 Mar 2024 14:05:16 +0530 Subject: [PATCH 5/6] added e2e checks for tool version --- .github/workflows/e2e-versions.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-versions.yml b/.github/workflows/e2e-versions.yml index 1f9d6e77..8b9e1119 100644 --- a/.github/workflows/e2e-versions.yml +++ b/.github/workflows/e2e-versions.yml @@ -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 @@ -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 @@ -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 @@ -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 From c2eed4c7f8f081fe5213b104fb87afba94593c20 Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Tue, 5 Mar 2024 12:48:13 +0530 Subject: [PATCH 6/6] removed error warning --- src/util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 4d61574e..4f4616e4 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,7 +8,6 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; import {INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION} from './constants'; import {OutgoingHttpHeaders} from 'http'; -import {error} from 'console'; export function getTempDir() { const tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();