This commit is contained in:
Augusto Melo 2023-02-12 17:26:48 -05:00 committed by GitHub
commit c7e2742eb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45238 additions and 4816 deletions

View File

@ -351,3 +351,222 @@ jobs:
- name: Verify Java
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
shell: bash
setup-java-version-from-pom-spring-boot-specification:
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 pom.xml file
shell: bash
run: |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
echo "<project>" >> pom.xml
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
echo " <groupId>com.test</groupId>" >> pom.xml
echo " <artifactId>Test</artifactId>" >> pom.xml
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
echo " <name>Test</name>" >> pom.xml
echo " <properties>" >> pom.xml
echo " <java.version>11</java.version>" >> pom.xml
echo " </properties>" >> pom.xml
echo " <dependencies>" >> pom.xml
echo " </dependencies>" >> pom.xml
echo " <build>" >> pom.xml
echo " <plugins>" >> pom.xml
echo " <plugin>" >> pom.xml
echo " <groupId>org.springframework.boot</groupId>" >> pom.xml
echo " <artifactId>spring-boot-maven-plugin</artifactId>" >> pom.xml
echo " </plugin>" >> pom.xml
echo " </plugins>" >> pom.xml
echo " </build>" >> pom.xml
echo "</project>" >> pom.xml
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: 'pom.xml'
- name: Verify Java
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
shell: bash
setup-java-version-from-pom-maven-compiler-source-specification:
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 pom.xml file
shell: bash
run: |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
echo "<project>" >> pom.xml
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
echo " <groupId>foo.bar</groupId>" >> pom.xml
echo " <artifactId>FooBarr</artifactId>" >> pom.xml
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
echo " <properties>" >> pom.xml
echo " <maven.compiler.source>1.8</maven.compiler.source>" >> pom.xml
echo " <maven.compiler.target>1.8</maven.compiler.target>" >> pom.xml
echo " </properties>" >> pom.xml
echo " <build>" >> pom.xml
echo " <plugins>" >> pom.xml
echo " <plugin>" >> pom.xml
echo " <groupId>org.apache.maven.plugins</groupId>" >> pom.xml
echo " <artifactId>maven-compiler-plugin</artifactId>" >> pom.xml
echo " <version>3.10.1</version>" >> pom.xml
echo " </plugin>" >> pom.xml
echo " </plugins>" >> pom.xml
echo " </build>" >> pom.xml
echo "</project>" >> pom.xml
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: 'pom.xml'
- name: Verify Java
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
shell: bash
setup-java-version-from-pom-maven-compiler-release-specification:
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 pom.xml file
shell: bash
run: |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
echo "<project>" >> pom.xml
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
echo " <groupId>foo.bar</groupId>" >> pom.xml
echo " <artifactId>FooBarr</artifactId>" >> pom.xml
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
echo " <properties>" >> pom.xml
echo " <maven.compiler.release>8</maven.compiler.release>" >> pom.xml
echo " </properties>" >> pom.xml
echo " <build>" >> pom.xml
echo " <plugins>" >> pom.xml
echo " <plugin>" >> pom.xml
echo " <groupId>org.apache.maven.plugins</groupId>" >> pom.xml
echo " <artifactId>maven-compiler-plugin</artifactId>" >> pom.xml
echo " <version>3.10.1</version>" >> pom.xml
echo " </plugin>" >> pom.xml
echo " </plugins>" >> pom.xml
echo " </build>" >> pom.xml
echo "</project>" >> pom.xml
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: 'pom.xml'
- name: Verify Java
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
shell: bash
setup-java-version-from-pom-maven-compiler-configuration-source-specification:
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 pom.xml file
shell: bash
run: |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
echo "<project>" >> pom.xml
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
echo " <groupId>foo.bar</groupId>" >> pom.xml
echo " <artifactId>FooBarr</artifactId>" >> pom.xml
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
echo " <build>" >> pom.xml
echo " <plugins>" >> pom.xml
echo " <plugin>" >> pom.xml
echo " <groupId>org.apache.maven.plugins</groupId>" >> pom.xml
echo " <artifactId>maven-compiler-plugin</artifactId>" >> pom.xml
echo " <version>3.10.1</version>" >> pom.xml
echo " <configuration>" >> pom.xml
echo " <source>1.8</source>" >> pom.xml
echo " <target>1.8</target>" >> pom.xml
echo " </configuration>" >> pom.xml
echo " </plugin>" >> pom.xml
echo " </plugins>" >> pom.xml
echo " </build>" >> pom.xml
echo "</project>" >> pom.xml
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: 'pom.xml'
- name: Verify Java
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
shell: bash
setup-java-version-from-pom-maven-compiler-configuration-release-specification:
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 pom.xml file
shell: bash
run: |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
echo "<project>" >> pom.xml
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
echo " <groupId>foo.bar</groupId>" >> pom.xml
echo " <artifactId>FooBarr</artifactId>" >> pom.xml
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
echo " <build>" >> pom.xml
echo " <plugins>" >> pom.xml
echo " <plugin>" >> pom.xml
echo " <groupId>org.apache.maven.plugins</groupId>" >> pom.xml
echo " <artifactId>maven-compiler-plugin</artifactId>" >> pom.xml
echo " <version>3.10.1</version>" >> pom.xml
echo " <configuration>" >> pom.xml
echo " <release>11</release>" >> pom.xml
echo " </configuration>" >> pom.xml
echo " </plugin>" >> pom.xml
echo " </plugins>" >> pom.xml
echo " </build>" >> pom.xml
echo "</project>" >> pom.xml
- name: setup-java
uses: ./
id: setup-java
with:
distribution: ${{ matrix.distribution }}
java-version-file: 'pom.xml'
- name: Verify Java
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
shell: bash

40004
dist/cleanup/index.js vendored

File diff suppressed because it is too large Load Diff

4927
dist/setup/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -482,12 +482,20 @@ steps:
## Java-version file
If the `java-version-file` input is specified, the action will try to extract the version from the file and install it.
Action is able to recognize all variants of the version description according to [jenv](https://github.com/jenv/jenv).
Valid entry options:
```
major versions: 8, 11, 16, 17
more specific versions: 1.8.0.2, 17.0, 11.0, 11.0.4, 8.0.232, 8.0.282+8
early access (EA) versions: 15-ea, 15.0.0-ea, 15.0.0-ea.2, 15.0.0+2-ea
versions with specified distribution: openjdk64-11.0.2
```
If the file contains multiple versions, only the first one will be recognized.
It is able to parse the following files as `java-version-file`:
- `.java-version`: Action is able to recognize all variants of the version description according to [jenv](https://github.com/jenv/jenv).
Valid entry options:
```
major versions: 8, 11, 16, 17
more specific versions: 1.8.0.2, 17.0, 11.0, 11.0.4, 8.0.232, 8.0.282+8
early access (EA) versions: 15-ea, 15.0.0-ea, 15.0.0-ea.2, 15.0.0+2-ea
versions with specified distribution: openjdk64-11.0.2
```
If the file contains multiple versions, only the first one will be recognized.
- `pom.xml`
- Spring Boot: `<java.version>` under project properties.
- Maven compiler plugin
- Setting the [source](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html).
- Setting the [release](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html).

4789
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,8 @@
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.6.1",
"semver": "^7.3.4",
"xmlbuilder2": "^2.4.0"
"xmlbuilder2": "^2.4.0",
"xpath": "0.0.32"
},
"devDependencies": {
"@types/jest": "^27.0.2",

View File

@ -47,7 +47,7 @@ async function run() {
.toString()
.trim();
const version = getVersionFromFileContent(content, distributionName);
const version = getVersionFromFileContent(versionFile, content, distributionName);
core.debug(`Parsed version from file '${version}'`);
if (!version) {

View File

@ -1,12 +1,15 @@
import os from 'os';
import os, { version } from 'os';
import path from 'path';
import * as fs from 'fs';
import * as semver from 'semver';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import { create as xmlCreate } from 'xmlbuilder2';
import { select } from 'xpath';
import * as tc from '@actions/tool-cache';
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
export function getTempDir() {
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
@ -101,13 +104,23 @@ export function isCacheFeatureAvailable(): boolean {
}
export function getVersionFromFileContent(
fileName: string,
content: string,
distributionName: string
): string | null {
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
const fileContent = content.match(javaVersionRegExp)?.groups?.version
? (content.match(javaVersionRegExp)?.groups?.version as string)
: '';
let fileContent = null;
core.debug(`Getting version from: '${fileName}'`);
if (fileName.includes('.java-version')) {
fileContent = parseJavaVersionFile(content);
} else if (fileName.includes('pom.xml')) {
fileContent = parsePomXmlFile(content);
} else {
throw new Error(
`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`
);
}
if (!fileContent) {
return null;
}
@ -133,6 +146,67 @@ export function getVersionFromFileContent(
return version.toString();
}
function parseJavaVersionFile(content: string): string | null {
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
const fileContent = content.match(javaVersionRegExp)?.groups?.version
? (content.match(javaVersionRegExp)?.groups?.version as string)
: '';
if (!fileContent) {
return null;
}
return fileContent;
}
function parsePomXmlFile(xmlString: string): string | null {
const xmlDoc = xmlCreate(xmlString);
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
for (var definitionType of versionDefinitionTypes) {
var version = definitionType(xmlDoc);
if (version !== null) {
return version;
}
}
return null;
}
function getByMavenCompilerSpecification(xmlDoc: XMLBuilder): string | null {
const possibleTags = [
'//properties/maven.compiler.source',
'//configuration/source',
'//properties/maven.compiler.release',
'//configuration/release'
];
for (var tag of possibleTags) {
const version = getVersionByTagName(xmlDoc, tag);
if (version !== null) {
return version;
}
}
return null;
}
function getBySpringBootSpecification(xmlDoc: XMLBuilder): string | null {
return getVersionByTagName(xmlDoc, '//properties/java.version');
}
function getVersionByTagName(xmlDoc: XMLBuilder, xpathQuery: string): string | null {
const element = select(`string(${xpathQuery})`, xmlDoc.node as any);
core.debug(`Found: '${element}' using xpath query: '${xpathQuery}'`);
if (element == undefined || element.length == 0) {
return null;
}
return element.toString();
}
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content: string): string {
return content.startsWith('1.') ? content.substring(2) : content;