Unverified Commit 1df8dbef authored by Evgenii Korolevskii's avatar Evgenii Korolevskii Committed by GitHub
Browse files

Add support for java.version file (#426)

parent c3ac5dd0
Loading
Loading
Loading
Loading
+96 −1
Changes for .github/workflows/e2e-versions.yml: 96 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -240,4 +240,99 @@ jobs:
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
        shell: bash

  # Only Microsoft provides AArch64. However, GitHub-hosted runners do not support this architecture.
 No newline at end of file
  setup-java-version-both-version-inputs-presents:
    name: ${{ matrix.distribution }} version (should be from input) - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
        distribution: ['temurin', 'microsoft', 'corretto' ]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Create .java-version file
        shell: bash
        run: echo "8" > .java-version
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: ${{ matrix.distribution }}
          java-version: 11
          java-version-file: '.java-version'
      - name: Verify Java
        run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
        shell: bash

  setup-java-version-from-file-major-notation:
    name: ${{ matrix.distribution }} version from file X - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
        distribution: ['temurin', 'zulu', 'liberica', 'microsoft', 'corretto' ]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Create .java-version file
        shell: bash
        run: echo "11" > .java-version
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: ${{ matrix.distribution }}
          java-version-file: '.java-version'
      - name: Verify Java
        run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
        shell: bash

  setup-java-version-from-file-major-minor-patch-notation:
    name: ${{ matrix.distribution }} version from file X.Y.Z - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
        distribution: [ 'adopt', 'adopt-openj9', 'zulu' ]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Create .java-version file
        shell: bash
        run: echo "11.0.2" > .java-version
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: ${{ matrix.distribution }}
          java-version-file: '.java-version'
      - name: Verify Java
        run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
        shell: bash

  setup-java-version-from-file-major-minor-patch-with-dist:
    name: ${{ matrix.distribution }} version from file 'openjdk64-11.0.2' - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
        distribution: ['adopt', 'zulu', 'liberica'  ]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Create .java-version file
        shell: bash
        run: echo "openjdk64-11.0.2" > .java-version
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: ${{ matrix.distribution }}
          java-version-file: '.java-version'
      - name: Verify Java
        run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
        shell: bash
+3 −1
Changes for README.md: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ This action allows you to work with Java and Scala projects.

## Usage

  - `java-version`: _(required)_ The Java version to set up. Takes a whole or [semver](#supported-version-syntax) Java version.
  - `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.

  - `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).
   
  - `distribution`: _(required)_ Java [distribution](#supported-distributions).

+2 −1
Changes for action.yml: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@ author: 'GitHub'
inputs:
  java-version:
    description: 'The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file'
    required: true
  java-version-file:
    description: 'The path to the `.java-version` file. See examples of supported syntax in README file'
  distribution:
    description: 'Java distribution. See the list of supported distributions in README file'
    required: true
+32 −2
Changes for dist/cleanup/index.js: 32 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -68480,9 +68480,10 @@ else {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
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;
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
exports.INPUT_ARCHITECTURE = 'architecture';
exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_DISTRIBUTION = 'distribution';
@@ -68505,6 +68506,7 @@ exports.MVN_SETTINGS_FILE = 'settings.xml';
exports.MVN_TOOLCHAINS_FILE = 'toolchains.xml';
exports.INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
exports.INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
/***/ }),
@@ -68622,7 +68624,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
exports.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
const os_1 = __importDefault(__nccwpck_require__(2037));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs = __importStar(__nccwpck_require__(7147));
@@ -68718,6 +68720,34 @@ function isCacheFeatureAvailable() {
    return true;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName) {
    var _a, _b, _c, _d, _e;
    const javaVersionRegExp = /(?<version>(?<=(^|\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
        : '';
    if (!fileContent) {
        return null;
    }
    core.debug(`Version from file '${fileContent}'`);
    const tentativeVersion = avoidOldNotation(fileContent);
    const rawVersion = tentativeVersion.split('-')[0];
    let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
    core.debug(`Range version from file is '${version}'`);
    if (!version) {
        return null;
    }
    if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
        const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
        version = semver.major(coerceVersion).toString();
    }
    return version.toString();
}
exports.getVersionFromFileContent = getVersionFromFileContent;
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content) {
    return content.startsWith('1.') ? content.substring(2) : content;
}
/***/ }),
+86 −21
Changes for dist/setup/index.js: 86 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -103582,9 +103582,10 @@ function isProbablyGradleDaemonProblem(packageManager, error) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
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;
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
exports.INPUT_ARCHITECTURE = 'architecture';
exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_DISTRIBUTION = 'distribution';
@@ -103607,6 +103608,7 @@ exports.MVN_SETTINGS_FILE = 'settings.xml';
exports.MVN_TOOLCHAINS_FILE = 'toolchains.xml';
exports.INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
exports.INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
/***/ }),
@@ -104551,7 +104553,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
            }
            const foundRelease = yield tc.findFromManifest(range, true, manifest, arch);
            if (!foundRelease) {
                throw new Error(`Could not find satisfied version for SemVer ${range}. ${manifest
                throw new Error(`Could not find satisfied version for SemVer ${range}.\nAvailable versions: ${manifest
                    .map(item => item.version)
                    .join(', ')}`);
            }
@@ -105056,7 +105058,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const core = __importStar(__nccwpck_require__(2186));
const auth = __importStar(__nccwpck_require__(3497));
const util_1 = __nccwpck_require__(2629);
@@ -105068,37 +105074,45 @@ const distribution_factory_1 = __nccwpck_require__(924);
function run() {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION, { required: true });
            const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
            const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true });
            const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
            const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
            const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
            const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
            const cache = core.getInput(constants.INPUT_CACHE);
            const checkLatest = util_1.getBooleanInput(constants.INPUT_CHECK_LATEST, false);
            let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
            core.startGroup('Installed distributions');
            if (versions.length !== toolchainIds.length) {
                toolchainIds = [];
            }
            core.startGroup('Installed distributions');
            for (const [index, version] of versions.entries()) {
                const installerOptions = {
            if (!versions.length && !versionFile) {
                throw new Error('java-version or java-version-file input expected');
            }
            const installerInputsOptions = {
                architecture,
                packageType,
                    version,
                    checkLatest
                };
                const distribution = distribution_factory_1.getJavaDistribution(distributionName, installerOptions, jdkFile);
                if (!distribution) {
                    throw new Error(`No supported distribution was found for input ${distributionName}`);
                checkLatest,
                distributionName,
                jdkFile,
                toolchainIds
            };
            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 = util_1.getVersionFromFileContent(content, distributionName);
                core.debug(`Parsed version from file '${version}'`);
                if (!version) {
                    throw new Error(`No supported version was found in file ${versionFile}`);
                }
                const result = yield distribution.setupJava();
                yield toolchains.configureToolchains(version, distributionName, result.path, toolchainIds[index]);
                core.info('');
                core.info('Java configuration:');
                core.info(`  Distribution: ${distributionName}`);
                core.info(`  Version: ${result.version}`);
                core.info(`  Path: ${result.path}`);
                core.info('');
                yield installVersion(version, installerInputsOptions);
            }
            for (const [index, version] of versions.entries()) {
                yield installVersion(version, installerInputsOptions, index);
            }
            core.endGroup();
            const matchersPath = path.join(__dirname, '..', '..', '.github');
@@ -105114,6 +105128,29 @@ function run() {
    });
}
run();
function installVersion(version, options, toolchainId = 0) {
    return __awaiter(this, void 0, void 0, function* () {
        const { distributionName, jdkFile, architecture, packageType, checkLatest, toolchainIds } = options;
        const installerOptions = {
            architecture,
            packageType,
            checkLatest,
            version
        };
        const distribution = distribution_factory_1.getJavaDistribution(distributionName, installerOptions, jdkFile);
        if (!distribution) {
            throw new Error(`No supported distribution was found for input ${distributionName}`);
        }
        const result = yield distribution.setupJava();
        yield toolchains.configureToolchains(version, distributionName, result.path, toolchainIds[toolchainId]);
        core.info('');
        core.info('Java configuration:');
        core.info(`  Distribution: ${distributionName}`);
        core.info(`  Version: ${result.version}`);
        core.info(`  Path: ${result.path}`);
        core.info('');
    });
}
/***/ }),
@@ -105315,7 +105352,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
exports.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
const os_1 = __importDefault(__nccwpck_require__(2037));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs = __importStar(__nccwpck_require__(7147));
@@ -105411,6 +105448,34 @@ function isCacheFeatureAvailable() {
    return true;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName) {
    var _a, _b, _c, _d, _e;
    const javaVersionRegExp = /(?<version>(?<=(^|\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
        : '';
    if (!fileContent) {
        return null;
    }
    core.debug(`Version from file '${fileContent}'`);
    const tentativeVersion = avoidOldNotation(fileContent);
    const rawVersion = tentativeVersion.split('-')[0];
    let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
    core.debug(`Range version from file is '${version}'`);
    if (!version) {
        return null;
    }
    if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
        const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
        version = semver.major(coerceVersion).toString();
    }
    return version.toString();
}
exports.getVersionFromFileContent = getVersionFromFileContent;
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content) {
    return content.startsWith('1.') ? content.substring(2) : content;
}
/***/ }),
Loading