Skip to content

Commit 1df8dbe

Browse files
Add support for java.version file (#426)
1 parent c3ac5dd commit 1df8dbe

File tree

10 files changed

+360
-58
lines changed

10 files changed

+360
-58
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,99 @@ jobs:
240240
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
241241
shell: bash
242242

243-
# Only Microsoft provides AArch64. However, GitHub-hosted runners do not support this architecture.
243+
setup-java-version-both-version-inputs-presents:
244+
name: ${{ matrix.distribution }} version (should be from input) - ${{ matrix.os }}
245+
runs-on: ${{ matrix.os }}
246+
strategy:
247+
fail-fast: false
248+
matrix:
249+
os: [macos-latest, windows-latest, ubuntu-latest]
250+
distribution: ['temurin', 'microsoft', 'corretto' ]
251+
steps:
252+
- name: Checkout
253+
uses: actions/checkout@v3
254+
- name: Create .java-version file
255+
shell: bash
256+
run: echo "8" > .java-version
257+
- name: setup-java
258+
uses: ./
259+
id: setup-java
260+
with:
261+
distribution: ${{ matrix.distribution }}
262+
java-version: 11
263+
java-version-file: '.java-version'
264+
- name: Verify Java
265+
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
266+
shell: bash
267+
268+
setup-java-version-from-file-major-notation:
269+
name: ${{ matrix.distribution }} version from file X - ${{ matrix.os }}
270+
runs-on: ${{ matrix.os }}
271+
strategy:
272+
fail-fast: false
273+
matrix:
274+
os: [macos-latest, windows-latest, ubuntu-latest]
275+
distribution: ['temurin', 'zulu', 'liberica', 'microsoft', 'corretto' ]
276+
steps:
277+
- name: Checkout
278+
uses: actions/checkout@v3
279+
- name: Create .java-version file
280+
shell: bash
281+
run: echo "11" > .java-version
282+
- name: setup-java
283+
uses: ./
284+
id: setup-java
285+
with:
286+
distribution: ${{ matrix.distribution }}
287+
java-version-file: '.java-version'
288+
- name: Verify Java
289+
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
290+
shell: bash
291+
292+
setup-java-version-from-file-major-minor-patch-notation:
293+
name: ${{ matrix.distribution }} version from file X.Y.Z - ${{ matrix.os }}
294+
runs-on: ${{ matrix.os }}
295+
strategy:
296+
fail-fast: false
297+
matrix:
298+
os: [macos-latest, windows-latest, ubuntu-latest]
299+
distribution: [ 'adopt', 'adopt-openj9', 'zulu' ]
300+
steps:
301+
- name: Checkout
302+
uses: actions/checkout@v3
303+
- name: Create .java-version file
304+
shell: bash
305+
run: echo "11.0.2" > .java-version
306+
- name: setup-java
307+
uses: ./
308+
id: setup-java
309+
with:
310+
distribution: ${{ matrix.distribution }}
311+
java-version-file: '.java-version'
312+
- name: Verify Java
313+
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
314+
shell: bash
315+
316+
setup-java-version-from-file-major-minor-patch-with-dist:
317+
name: ${{ matrix.distribution }} version from file 'openjdk64-11.0.2' - ${{ matrix.os }}
318+
runs-on: ${{ matrix.os }}
319+
strategy:
320+
fail-fast: false
321+
matrix:
322+
os: [macos-latest, windows-latest, ubuntu-latest]
323+
distribution: ['adopt', 'zulu', 'liberica' ]
324+
steps:
325+
- name: Checkout
326+
uses: actions/checkout@v3
327+
- name: Create .java-version file
328+
shell: bash
329+
run: echo "openjdk64-11.0.2" > .java-version
330+
- name: setup-java
331+
uses: ./
332+
id: setup-java
333+
with:
334+
distribution: ${{ matrix.distribution }}
335+
java-version-file: '.java-version'
336+
- name: Verify Java
337+
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
338+
shell: bash

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ This action allows you to work with Java and Scala projects.
2323

2424
## Usage
2525

26-
- `java-version`: _(required)_ The Java version to set up. Takes a whole or [semver](#supported-version-syntax) Java version.
26+
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
27+
28+
- `java-version-file`: The path to the `.java-version` file. See more details in [about `.java-version` file](docs/advanced-usage.md#Java-version-file).
2729

2830
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
2931

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: 'GitHub'
55
inputs:
66
java-version:
77
description: 'The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file'
8-
required: true
8+
java-version-file:
9+
description: 'The path to the `.java-version` file. See examples of supported syntax in README file'
910
distribution:
1011
description: 'Java distribution. See the list of supported distributions in README file'
1112
required: true

dist/cleanup/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68480,9 +68480,10 @@ else {
6848068480
"use strict";
6848168481

6848268482
Object.defineProperty(exports, "__esModule", ({ value: true }));
68483-
exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
68483+
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
6848468484
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
6848568485
exports.INPUT_JAVA_VERSION = 'java-version';
68486+
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
6848668487
exports.INPUT_ARCHITECTURE = 'architecture';
6848768488
exports.INPUT_JAVA_PACKAGE = 'java-package';
6848868489
exports.INPUT_DISTRIBUTION = 'distribution';
@@ -68505,6 +68506,7 @@ exports.MVN_SETTINGS_FILE = 'settings.xml';
6850568506
exports.MVN_TOOLCHAINS_FILE = 'toolchains.xml';
6850668507
exports.INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
6850768508
exports.INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
68509+
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
6850868510

6850968511

6851068512
/***/ }),
@@ -68622,7 +68624,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6862268624
return (mod && mod.__esModule) ? mod : { "default": mod };
6862368625
};
6862468626
Object.defineProperty(exports, "__esModule", ({ value: true }));
68625-
exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
68627+
exports.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
6862668628
const os_1 = __importDefault(__nccwpck_require__(2037));
6862768629
const path_1 = __importDefault(__nccwpck_require__(1017));
6862868630
const fs = __importStar(__nccwpck_require__(7147));
@@ -68718,6 +68720,34 @@ function isCacheFeatureAvailable() {
6871868720
return true;
6871968721
}
6872068722
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
68723+
function getVersionFromFileContent(content, distributionName) {
68724+
var _a, _b, _c, _d, _e;
68725+
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
68726+
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
68727+
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
68728+
: '';
68729+
if (!fileContent) {
68730+
return null;
68731+
}
68732+
core.debug(`Version from file '${fileContent}'`);
68733+
const tentativeVersion = avoidOldNotation(fileContent);
68734+
const rawVersion = tentativeVersion.split('-')[0];
68735+
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
68736+
core.debug(`Range version from file is '${version}'`);
68737+
if (!version) {
68738+
return null;
68739+
}
68740+
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
68741+
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
68742+
version = semver.major(coerceVersion).toString();
68743+
}
68744+
return version.toString();
68745+
}
68746+
exports.getVersionFromFileContent = getVersionFromFileContent;
68747+
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
68748+
function avoidOldNotation(content) {
68749+
return content.startsWith('1.') ? content.substring(2) : content;
68750+
}
6872168751

6872268752

6872368753
/***/ }),

0 commit comments

Comments
 (0)