Compare commits
77 Commits
Author | SHA1 | Date | |
---|---|---|---|
1df8dbefe2 | |||
c3ac5dd0ed | |||
dcd29da2fa | |||
19eeec562b | |||
bd7e5d28eb | |||
6cdf39a6b6 | |||
7db6b4554c | |||
bf2f02c4a7 | |||
de1bb2b0c5 | |||
2c53c1a588 | |||
3617c43588 | |||
a82e6d0020 | |||
fbb269240e | |||
dfcd06a4b9 | |||
e150063ee4 | |||
eb1418aa81 | |||
499ae9c28b | |||
a18c333f3f | |||
26eeac8c9e | |||
cdc5f296eb | |||
b80173ab1e | |||
a96c2ca6ae | |||
7bbeb80d24 | |||
d854b6da19 | |||
749e4491fa | |||
aa53851224 | |||
5b36705a13 | |||
4656cbcede | |||
ef96bec0e4 | |||
8e8bf44561 | |||
40dd195c45 | |||
858120d4a8 | |||
ad9cecf99b | |||
8048bbee47 | |||
9e9f60b996 | |||
46f0194a3b | |||
c69efbe773 | |||
3c69e15101 | |||
bf1c35bd9d | |||
66a84830d9 | |||
8ac768a2cf | |||
2c7a4878f5 | |||
e2f30c1450 | |||
2dfaeac2db | |||
aa24fa78d2 | |||
25d94e7786 | |||
2fc49d780a | |||
e6a4b93088 | |||
821cc3dbd1 | |||
4903eafcd7 | |||
a0500669b7 | |||
d397c16c56 | |||
16cca5479d | |||
7b469c48c4 | |||
2506d21b74 | |||
187f735c38 | |||
48576e577e | |||
fa01820a3b | |||
62808131e1 | |||
ddbbc2fff5 | |||
4fba831118 | |||
11556068a2 | |||
ec303d3bdf | |||
1c449b9ad2 | |||
3e3d8c490f | |||
72dec17e4f | |||
e8f1c8b5ca | |||
05b9e395e1 | |||
fa0272551b | |||
30cdb8c7dd | |||
45b7b136cf | |||
f56009127d | |||
fa513641c0 | |||
83b77aa58b | |||
efcb607a6b | |||
ca584e7011 | |||
69e93308b0 |
134
.github/workflows/e2e-versions.yml
vendored
134
.github/workflows/e2e-versions.yml
vendored
@ -87,6 +87,43 @@ jobs:
|
||||
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
||||
setup-java-multiple-jdks:
|
||||
name: ${{ matrix.distribution }} ${{ matrix.version }} - multiple jdks - ${{ matrix.os }}
|
||||
needs: setup-java-major-versions
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
distribution: ['temurin', 'zulu', 'liberica']
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup-java
|
||||
uses: ./
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
java-version: |
|
||||
11
|
||||
17
|
||||
- name: Verify Java env variables
|
||||
run: |
|
||||
$versionsArr = "11","17"
|
||||
foreach ($version in $versionsArr)
|
||||
{
|
||||
$envName = "JAVA_HOME_${version}_${env:RUNNER_ARCH}"
|
||||
$JavaVersionPath = [Environment]::GetEnvironmentVariable($envName)
|
||||
if (-not (Test-Path "$JavaVersionPath")) {
|
||||
Write-Host "$envName is not found"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
shell: pwsh
|
||||
- name: Verify Java
|
||||
run: bash __tests__/verify-java.sh "17" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
||||
setup-java-ea-versions-zulu:
|
||||
name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
||||
needs: setup-java-major-minor-versions
|
||||
@ -203,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.
|
||||
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
|
||||
|
@ -22,7 +22,7 @@ jobs:
|
||||
steps:
|
||||
- name: Update the ${{ env.TAG_NAME }} tag
|
||||
id: update-major-tag
|
||||
uses: actions/publish-action@v0.1.0
|
||||
uses: actions/publish-action@v0.2.1
|
||||
with:
|
||||
source-tag: ${{ env.TAG_NAME }}
|
||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||
|
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@actions/http-client-2.0.1.dep.yml
generated
Normal file
BIN
.licenses/npm/@actions/http-client-2.0.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/minimatch.dep.yml
generated
BIN
.licenses/npm/minimatch.dep.yml
generated
Binary file not shown.
@ -1,38 +0,0 @@
|
||||
# Contributors
|
||||
|
||||
### Checkin
|
||||
|
||||
- Do checkin source (src)
|
||||
- Do checkin a single index.js file after running `ncc`
|
||||
- Do not checking node_modules
|
||||
|
||||
### NCC
|
||||
|
||||
In order to avoid uploading `node_modules` to the repository, we use [vercel/ncc](https://github.com/vercel/ncc) to create multiple `index.js` files that gets saved under `dist/`.
|
||||
There are two main files that get created
|
||||
- `dist/setup/index.js`
|
||||
- Core `setup-java` logic that downloads and installs an appropriate version of Java
|
||||
- Handling creating a `settings.xml` file to make it easier to publish packages
|
||||
- `dist/cleanup/index/js`
|
||||
- Extra cleanup script that is used to remove GPG keys (needed for certain self-hosted runner scenarios)
|
||||
|
||||
If you're developing locally, after doing `npm install`, you can use the following commands
|
||||
```yaml
|
||||
npm run build # runs tsc along with ncc
|
||||
npm run format # runs prettier --write
|
||||
npm run format-check # runs prettier --check
|
||||
npm run test # runs jest
|
||||
npm run release # add all the necessary ncc files under dist/* to the git staging area
|
||||
```
|
||||
|
||||
Any files generated using `tsc` will be added to `lib/*`, however those files also are not uploaded to the repository and are excluded using `.gitignore`.
|
||||
|
||||
### Testing
|
||||
|
||||
Tests are included under `_tests_/*` and can be run using `npm run-script test`.
|
||||
|
||||
We ask that you include a link to a successful run that utilizes the changes you are working on. For example, if your changes are in the branch `newAwesomeFeature`, then show an example run that uses `setup-python@newAwesomeFeature` or `my-fork@newAwesomeFeature`. This will help speed up testing and help us confirm that there are no breaking changes or bugs.
|
||||
|
||||
### Licensed
|
||||
|
||||
This repository uses a tool called [Licensed](https://github.com/github/licensed) to verify third party dependencies. You may need to locally install licensed and run `licensed cache` to update the dependency cache if you install or update a production dependency. If licensed cache is unable to determine the dependency, you may need to modify the cache file yourself to put the correct license. You should still verify the dependency, licensed is a tool to help, but is not a substitute for human review of dependencies.
|
123
README.md
123
README.md
@ -1,10 +1,8 @@
|
||||
# setup-java
|
||||
# Setup Java
|
||||
|
||||
<p align="left">
|
||||
<a href="https://github.com/actions/setup-java"><img alt="GitHub Actions status" src="https://github.com/actions/setup-java/workflows/Main%20workflow/badge.svg"></a>
|
||||
</p>
|
||||
[](https://github.com/actions/setup-java/actions/workflows/workflow.yml)
|
||||
|
||||
This action provides the following functionality for GitHub Actions runners:
|
||||
The `setup-java` action provides the following functionality for GitHub Actions runners:
|
||||
- Downloading and setting up a requested version of Java. See [Usage](#Usage) for a list of supported distributions
|
||||
- Extracting and caching custom version of Java from a local file
|
||||
- Configuring runner for publishing using Apache Maven
|
||||
@ -13,16 +11,58 @@ This action provides the following functionality for GitHub Actions runners:
|
||||
- Registering problem matchers for error output
|
||||
- Caching dependencies managed by Apache Maven
|
||||
- Caching dependencies managed by Gradle
|
||||
- Caching dependencies managed by sbt
|
||||
- [Maven Toolchains declaration](https://maven.apache.org/guides/mini/guide-using-toolchains.html) for specified JDK versions
|
||||
|
||||
This action allows you to work with Java and Scala projects.
|
||||
|
||||
## V2 vs V1
|
||||
- V2 supports custom distributions and provides support for Zulu OpenJDK, Eclipse Temurin and Adopt OpenJDK out of the box. V1 supports only Zulu OpenJDK
|
||||
- V2 requires you to specify distribution along with the version. V1 defaults to Zulu OpenJDK, only version input is required. Follow [the migration guide](docs/switching-to-v2.md) to switch from V1 to V2
|
||||
|
||||
- V2 supports custom distributions and provides support for Azul Zulu OpenJDK, Eclipse Temurin and AdoptOpenJDK out of the box. V1 supports only Azul Zulu OpenJDK
|
||||
- V2 requires you to specify distribution along with the version. V1 defaults to Azul Zulu OpenJDK, only version input is required. Follow [the migration guide](docs/switching-to-v2.md) to switch from V1 to V2
|
||||
|
||||
## Usage
|
||||
Inputs `java-version` and `distribution` are mandatory. See [Supported distributions](#supported-distributions) section for a list of available options.
|
||||
|
||||
### Basic
|
||||
**Eclipse Temurin**
|
||||
- `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).
|
||||
|
||||
- `java-package`: The packaging variant of the choosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. Default value: `jdk`.
|
||||
|
||||
- `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: `x64`.
|
||||
|
||||
- `jdkFile`: If a use-case requires a custom distribution setup-java uses the compressed JDK from the location pointed by this input and will take care of the installation and caching on the VM.
|
||||
|
||||
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
||||
|
||||
- `cache`: Quick [setup caching](#caching-packages-dependencies) for the dependencies managed through one of the predifined package managers. It can be one of "maven", "gradle" or "sbt".
|
||||
|
||||
#### Maven options
|
||||
The action has a bunch of inputs to generate maven's [settings.xml](https://maven.apache.org/settings.html) on the fly and pass the values to Apache Maven GPG Plugin as well as Apache Maven Toolchains. See [advanced usage](docs/advanced-usage.md) for more.
|
||||
|
||||
- `overwrite-settings`: By default action overwrites the settings.xml. In order to skip generation of file if it exists set this to `false`.
|
||||
|
||||
- `server-id`: ID of the distributionManagement repository in the pom.xml file. Default is `github`.
|
||||
|
||||
- `server-username`: Environment variable name for the username for authentication to the Apache Maven repository. Default is GITHUB_ACTOR.
|
||||
|
||||
- `server-password`: Environment variable name for password or token for authentication to the Apache Maven repository. Default is GITHUB_TOKEN.
|
||||
|
||||
- `settings-path`: Maven related setting to point to the directory where the settings.xml file will be written. Default is ~/.m2.
|
||||
|
||||
- `gpg-private-key`: GPG private key to import. Default is empty string.'
|
||||
|
||||
- `gpg-passphrase`: description: 'Environment variable name for the GPG private key passphrase. Default is GPG_PASSPHRASE.
|
||||
|
||||
- `mvn-toolchain-id`: Name of Maven Toolchain ID if the default name of `${distribution}_${java-version}` is not wanted.
|
||||
|
||||
- `mvn-toolchain-vendor`: Name of Maven Toolchain Vendor if the default name of `${distribution}` is not wanted.
|
||||
|
||||
### Basic Configuration
|
||||
|
||||
#### Eclipse Temurin
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@ -30,18 +70,18 @@ steps:
|
||||
with:
|
||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||
java-version: '17'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java HelloWorldApp.java
|
||||
```
|
||||
|
||||
**Zulu OpenJDK**
|
||||
#### Azul Zulu OpenJDK
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu' # See 'Supported distributions' for available options
|
||||
java-version: '11'
|
||||
- run: java -cp java HelloWorldApp
|
||||
java-version: '17'
|
||||
- run: java HelloWorldApp.java
|
||||
```
|
||||
|
||||
#### Supported version syntax
|
||||
@ -55,22 +95,24 @@ Currently, the following distributions are supported:
|
||||
| Keyword | Distribution | Official site | License
|
||||
|-|-|-|-|
|
||||
| `temurin` | Eclipse Temurin | [Link](https://adoptium.net/) | [Link](https://adoptium.net/about.html)
|
||||
| `zulu` | Zulu OpenJDK | [Link](https://www.azul.com/downloads/zulu-community/?package=jdk) | [Link](https://www.azul.com/products/zulu-and-zulu-enterprise/zulu-terms-of-use/) |
|
||||
| `adopt` or `adopt-hotspot` | Adopt OpenJDK Hotspot | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
||||
| `adopt-openj9` | Adopt OpenJDK OpenJ9 | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
||||
| `zulu` | Azul Zulu OpenJDK | [Link](https://www.azul.com/downloads/zulu-community/?package=jdk) | [Link](https://www.azul.com/products/zulu-and-zulu-enterprise/zulu-terms-of-use/) |
|
||||
| `adopt` or `adopt-hotspot` | AdoptOpenJDK Hotspot | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
||||
| `adopt-openj9` | AdoptOpenJDK OpenJ9 | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
||||
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
|
||||
| `microsoft` | Microsoft Build of OpenJDK | [Link](https://www.microsoft.com/openjdk) | [Link](https://docs.microsoft.com/java/openjdk/faq)
|
||||
| `corretto` | Amazon Corretto Build of OpenJDK | [Link](https://aws.amazon.com/corretto/) | [Link](https://aws.amazon.com/corretto/faqs/)
|
||||
|
||||
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
|
||||
|
||||
**NOTE:** Adopt OpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` to `temurin` to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
|
||||
**NOTE:** AdoptOpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` to `temurin` to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
|
||||
|
||||
**NOTE:** For Azul Zulu OpenJDK architectures x64 and arm64 are mapped to x86 / arm with proper hw_bitness.
|
||||
|
||||
### Caching packages dependencies
|
||||
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle, maven and sbt. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files:
|
||||
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`
|
||||
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/Versions.kt`, `buildSrc/**/Dependencies.kt`, and `gradle/*.versions.toml`
|
||||
- maven: `**/pom.xml`
|
||||
- sbt: `**/build.sbt`
|
||||
- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.{scala,sbt}`
|
||||
|
||||
The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs).
|
||||
|
||||
@ -83,7 +125,7 @@ steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
java-version: '17'
|
||||
cache: 'gradle'
|
||||
- run: ./gradlew build --no-daemon
|
||||
```
|
||||
@ -95,7 +137,7 @@ steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
java-version: '17'
|
||||
cache: 'maven'
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
@ -108,13 +150,14 @@ steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
java-version: '17'
|
||||
cache: 'sbt'
|
||||
- name: Build with SBT
|
||||
run: sbt package
|
||||
```
|
||||
|
||||
### Check latest
|
||||
|
||||
In the basic examples above, the `check-latest` flag defaults to `false`. When set to `false`, the action tries to first resolve a version of Java from the local tool cache on the runner. If unable to find a specific version in the cache, the action will download a version of Java. Use the default or set `check-latest` to `false` if you prefer a faster more consistent setup experience that prioritizes trying to use the cached versions at the expense of newer versions sometimes being available for download.
|
||||
|
||||
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, the latest version of Java will be downloaded. Set `check-latest` to `true` if you want the most up-to-date version of Java to always be used. Setting `check-latest` to `true` has performance implications as downloading versions of Java is slower than using cached versions.
|
||||
@ -127,10 +170,10 @@ steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '11'
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
check-latest: true
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java HelloWorldApp.java
|
||||
```
|
||||
|
||||
### Testing against different Java versions
|
||||
@ -140,7 +183,7 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
java: [ '8', '11', '13', '15' ]
|
||||
java: [ '8', '11', '17' ]
|
||||
name: Java ${{ matrix.Java }} sample
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@ -149,10 +192,29 @@ jobs:
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: ${{ matrix.java }}
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java HelloWorldApp.java
|
||||
```
|
||||
|
||||
### Advanced
|
||||
### Install multiple JDKs
|
||||
|
||||
All versions are added to the PATH. The last version will be used and available globally. Other Java versions can be accessed through env variables with such specification as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
8
|
||||
11
|
||||
15
|
||||
```
|
||||
|
||||
### Using Maven Toolchains
|
||||
In the example above multiple JDKs are installed for the same job. The result after the last JDK is installed is a Maven Toolchains declaration containing references to all three JDKs. The values for `id`, `version`, and `vendor` of the individual Toolchain entries are the given input values for `distribution` and `java-version` (`vendor` being the combination of `${distribution}_${java-version}`) by default.
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
- [Selecting a Java distribution](docs/advanced-usage.md#Selecting-a-Java-distribution)
|
||||
- [Eclipse Temurin](docs/advanced-usage.md#Eclipse-Temurin)
|
||||
- [Adopt](docs/advanced-usage.md#Adopt)
|
||||
@ -168,6 +230,7 @@ jobs:
|
||||
- [Publishing using Apache Maven](docs/advanced-usage.md#Publishing-using-Apache-Maven)
|
||||
- [Publishing using Gradle](docs/advanced-usage.md#Publishing-using-Gradle)
|
||||
- [Hosted Tool Cache](docs/advanced-usage.md#Hosted-Tool-Cache)
|
||||
- [Modifying Maven Toolchains](docs/advanced-usage.md#Modifying-Maven-Toolchains)
|
||||
|
||||
## License
|
||||
|
||||
@ -175,4 +238,4 @@ The scripts and documentation in this project are released under the [MIT Licens
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are welcome! See [Contributor's Guide](CONTRIBUTING.md)
|
||||
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||
|
@ -5,9 +5,10 @@ import * as core from '@actions/core';
|
||||
import os from 'os';
|
||||
|
||||
import * as auth from '../src/auth';
|
||||
import { M2_DIR, MVN_SETTINGS_FILE } from '../src/constants';
|
||||
|
||||
const m2Dir = path.join(__dirname, auth.M2_DIR);
|
||||
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
|
||||
const m2Dir = path.join(__dirname, M2_DIR);
|
||||
const settingsFile = path.join(m2Dir, MVN_SETTINGS_FILE);
|
||||
|
||||
describe('auth tests', () => {
|
||||
let spyOSHomedir: jest.SpyInstance;
|
||||
@ -38,7 +39,7 @@ describe('auth tests', () => {
|
||||
const password = 'TOLKIEN';
|
||||
|
||||
const altHome = path.join(__dirname, 'runner', 'settings');
|
||||
const altSettingsFile = path.join(altHome, auth.SETTINGS_FILE);
|
||||
const altSettingsFile = path.join(altHome, MVN_SETTINGS_FILE);
|
||||
await io.rmRF(altHome); // ensure it doesn't already exist
|
||||
|
||||
await auth.createAuthenticationSettings(id, username, password, altHome, true);
|
||||
|
@ -98,7 +98,7 @@ describe('dependency cache', () => {
|
||||
await expect(restore('gradle')).rejects.toThrowError(
|
||||
`No file in ${projectRoot(
|
||||
workspace
|
||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties], make sure you have checked out the target repository`
|
||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml], make sure you have checked out the target repository`
|
||||
);
|
||||
});
|
||||
it('downloads cache based on build.gradle', async () => {
|
||||
@ -117,6 +117,24 @@ describe('dependency cache', () => {
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||
});
|
||||
it('downloads cache based on libs.versions.toml', async () => {
|
||||
createDirectory(join(workspace, 'gradle'));
|
||||
createFile(join(workspace, 'gradle', 'libs.versions.toml'));
|
||||
|
||||
await restore('gradle');
|
||||
expect(spyCacheRestore).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||
});
|
||||
});
|
||||
it('downloads cache based on buildSrc/Versions.kt', async () => {
|
||||
createDirectory(join(workspace, 'buildSrc'));
|
||||
createFile(join(workspace, 'buildSrc', 'Versions.kt'));
|
||||
|
||||
await restore('gradle');
|
||||
expect(spyCacheRestore).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||
});
|
||||
describe('for sbt', () => {
|
||||
it('throws error if no build.sbt found', async () => {
|
||||
@ -153,6 +171,27 @@ describe('dependency cache', () => {
|
||||
return expect(save('ant')).rejects.toThrowError('unknown package manager specified: ant');
|
||||
});
|
||||
|
||||
it('save with -1 cacheId , should not fail workflow', async () => {
|
||||
spyCacheSave.mockImplementation(() => Promise.resolve(-1));
|
||||
createStateForMissingBuildFile();
|
||||
|
||||
await save('maven');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||
});
|
||||
|
||||
it('saves with error from toolkit, should fail workflow', async () => {
|
||||
spyCacheSave.mockImplementation(() =>
|
||||
Promise.reject(new cache.ValidationError('Validation failed'))
|
||||
);
|
||||
createStateForMissingBuildFile();
|
||||
|
||||
expect.assertions(1);
|
||||
await expect(save('maven')).rejects.toEqual(new cache.ValidationError('Validation failed'));
|
||||
});
|
||||
|
||||
describe('for maven', () => {
|
||||
it('uploads cache even if no pom.xml found', async () => {
|
||||
createStateForMissingBuildFile();
|
||||
@ -205,6 +244,16 @@ describe('dependency cache', () => {
|
||||
createFile(join(workspace, 'build.gradle.kts'));
|
||||
createStateForSuccessfulRestore();
|
||||
|
||||
await save('gradle');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||
});
|
||||
it('uploads cache based on buildSrc/Versions.kt', async () => {
|
||||
createDirectory(join(workspace, 'buildSrc'));
|
||||
createFile(join(workspace, 'buildSrc', 'Versions.kt'));
|
||||
createStateForSuccessfulRestore();
|
||||
|
||||
await save('gradle');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
@ -277,6 +326,11 @@ function createFile(path: string) {
|
||||
fs.writeFileSync(path, '');
|
||||
}
|
||||
|
||||
function createDirectory(path: string) {
|
||||
core.info(`created a directory at ${path}`);
|
||||
fs.mkdirSync(path);
|
||||
}
|
||||
|
||||
function projectRoot(workspace: string): string {
|
||||
if (os.platform() === 'darwin') {
|
||||
return `/private${workspace}`;
|
||||
|
@ -26,7 +26,7 @@ describe('cleanup', () => {
|
||||
resetState();
|
||||
});
|
||||
|
||||
it('does not fail nor warn even when the save provess throws a ReserveCacheError', async () => {
|
||||
it('does not fail nor warn even when the save process throws a ReserveCacheError', async () => {
|
||||
spyCacheSave.mockImplementation((paths: string[], key: string) =>
|
||||
Promise.reject(
|
||||
new cache.ReserveCacheError(
|
||||
|
@ -3,6 +3,8 @@ import { HttpClient } from '@actions/http-client';
|
||||
import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer';
|
||||
import { JavaInstallerOptions } from '../../src/distributions/base-models';
|
||||
|
||||
import os from 'os';
|
||||
|
||||
let manifestData = require('../data/adopt.json') as [];
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
@ -128,6 +130,35 @@ describe('getAvailableVersions', () => {
|
||||
expect(distribution.toolcacheFolderName).toBe(expected);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['amd64', 'x64'],
|
||||
['arm64', 'aarch64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
version: '17',
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
|
||||
|
||||
const distribution = new AdoptDistribution(installerOptions, AdoptImplementation.Hotspot);
|
||||
const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
|
||||
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptopenjdk&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
|
||||
distribution['getPlatformOption'] = () => 'mac';
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
|
@ -12,6 +12,8 @@ import {
|
||||
JavaInstallerResults
|
||||
} from '../../src/distributions/base-models';
|
||||
|
||||
import os from 'os';
|
||||
|
||||
class EmptyJavaBase extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Empty', installerOptions);
|
||||
@ -192,6 +194,8 @@ describe('setupJava', () => {
|
||||
|
||||
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
|
||||
spyCoreSetOutput.mockImplementation(() => undefined);
|
||||
|
||||
jest.spyOn(os, 'arch').mockReturnValue('x86');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -212,6 +216,10 @@ describe('setupJava', () => {
|
||||
[
|
||||
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
|
||||
{ version: installedJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: false },
|
||||
{ version: installedJavaVersion, path: javaPath }
|
||||
]
|
||||
])('should find java locally for %s', (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
@ -237,6 +245,10 @@ describe('setupJava', () => {
|
||||
[
|
||||
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
|
||||
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: '', packageType: 'jre', checkLatest: false },
|
||||
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' }
|
||||
]
|
||||
])('download java with configuration %s', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
@ -244,6 +256,10 @@ describe('setupJava', () => {
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
`JAVA_HOME_${input.version}_${(input.architecture || 'x86').toLocaleUpperCase()}`,
|
||||
expected.path
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
|
||||
@ -256,6 +272,10 @@ describe('setupJava', () => {
|
||||
[
|
||||
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: '11.0.9', path: javaPathInstalled }
|
||||
],
|
||||
[
|
||||
{ version: '11.0.9', architecture: '', packageType: 'jdk', checkLatest: true },
|
||||
{ version: '11.0.9', path: javaPathInstalled }
|
||||
]
|
||||
])('should check the latest java version for %s and resolve locally', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
@ -279,6 +299,10 @@ describe('setupJava', () => {
|
||||
[
|
||||
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||
]
|
||||
])('should check the latest java version for %s and download', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
|
@ -3,6 +3,8 @@ import { JavaInstallerOptions } from '../../src/distributions/base-models';
|
||||
|
||||
import { CorrettoDistribution } from '../../src/distributions/corretto/installer';
|
||||
import * as util from '../../src/util';
|
||||
import os from 'os';
|
||||
import { isGeneratorFunction } from 'util/types';
|
||||
|
||||
const manifestData = require('../data/corretto.json') as [];
|
||||
|
||||
@ -142,10 +144,37 @@ describe('getAvailableVersions', () => {
|
||||
"Could not find satisfied version for SemVer '4'"
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['arm64', 'aarch64'],
|
||||
['amd64', 'x64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const version = '17';
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
version,
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
const distribution = new CorrettoDistribution(installerOptions);
|
||||
mockPlatform(distribution, 'macos');
|
||||
|
||||
const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`;
|
||||
|
||||
const availableVersion = await distribution['findPackageForDownload'](version);
|
||||
expect(availableVersion).not.toBeNull();
|
||||
expect(availableVersion.url).toBe(expectedLink);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const mockPlatform = (distributon: CorrettoDistribution, platform: string) => {
|
||||
distributon['getPlatformOption'] = () => platform;
|
||||
const mockPlatform = (distribution: CorrettoDistribution, platform: string) => {
|
||||
distribution['getPlatformOption'] = () => platform;
|
||||
const mockedExtension = platform === 'windows' ? 'zip' : 'tar.gz';
|
||||
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { LibericaDistributions } from '../../src/distributions/liberica/installer';
|
||||
import { ArchitectureOptions, LibericaVersion } from '../../src/distributions/liberica/models';
|
||||
import { HttpClient } from '@actions/http-client';
|
||||
import os from 'os';
|
||||
|
||||
const manifestData = require('../data/liberica.json') as LibericaVersion[];
|
||||
|
||||
@ -61,6 +62,39 @@ describe('getAvailableVersions', () => {
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
});
|
||||
|
||||
type DistroArch = {
|
||||
bitness: string;
|
||||
arch: string;
|
||||
};
|
||||
it.each([
|
||||
['amd64', { bitness: '64', arch: 'x86' }],
|
||||
['arm64', { bitness: '64', arch: 'arm' }]
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: DistroArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const distribution = new LibericaDistributions({
|
||||
version: '17',
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
const additionalParams =
|
||||
'&installation-type=archive&fields=downloadUrl%2Cversion%2CfeatureVersion%2CinterimVersion%2C' +
|
||||
'updateVersion%2CbuildVersion';
|
||||
distribution['getPlatformOption'] = () => 'macos';
|
||||
|
||||
const buildUrl = `https://api.bell-sw.com/v1/liberica/releases?os=macos&bundle-type=jdk&bitness=${distroArch.bitness}&arch=${distroArch.arch}&build-type=all${additionalParams}`;
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
}
|
||||
);
|
||||
|
||||
it('load available versions', async () => {
|
||||
const distribution = new LibericaDistributions({
|
||||
version: '11',
|
||||
|
@ -1,7 +1,13 @@
|
||||
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
|
||||
import os from 'os';
|
||||
import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
let distribution: MicrosoftDistributions;
|
||||
let spyGetManifestFromRepo: jest.SpyInstance;
|
||||
let spyDebug: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
distribution = new MicrosoftDistributions({
|
||||
@ -10,23 +16,43 @@ describe('findPackageForDownload', () => {
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
spyGetManifestFromRepo = jest.spyOn(httpm.HttpClient.prototype, 'getJson');
|
||||
spyGetManifestFromRepo.mockReturnValue({
|
||||
result: data,
|
||||
statusCode: 200,
|
||||
headers: {}
|
||||
});
|
||||
|
||||
spyDebug = jest.spyOn(core, 'debug');
|
||||
spyDebug.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
'17.x',
|
||||
'17.0.1',
|
||||
'17.0.1+12.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'17.x',
|
||||
'17.0.3',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.3-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'16.0.x',
|
||||
'16.0.2',
|
||||
'16.0.2+7.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'11.0.13',
|
||||
'11.0.13',
|
||||
'11.0.13+8.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'11.0.15',
|
||||
'11.0.15',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.15-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
]
|
||||
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
||||
const result = await distribution['findPackageForDownload'](input);
|
||||
@ -51,38 +77,33 @@ describe('findPackageForDownload', () => {
|
||||
expect(result.url).toBe(url);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['amd64', 'x64'],
|
||||
['arm64', 'aarch64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
||||
|
||||
const version = '17';
|
||||
const distro = new MicrosoftDistributions({
|
||||
version,
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
const result = await distro['findPackageForDownload'](version);
|
||||
const expectedUrl = `https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-${distroArch}.tar.gz`;
|
||||
|
||||
expect(result.url).toBe(expectedUrl);
|
||||
}
|
||||
);
|
||||
|
||||
it('should throw an error', async () => {
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPlatformOption', () => {
|
||||
const distributions = new MicrosoftDistributions({
|
||||
architecture: 'x64',
|
||||
version: '11',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
it.each([
|
||||
['linux', 'tar.gz', 'linux'],
|
||||
['darwin', 'tar.gz', 'macos'],
|
||||
['win32', 'zip', 'windows']
|
||||
])('os version %s -> %s', (input, expectedArchive, expectedOs) => {
|
||||
const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
|
||||
|
||||
expect(actual.archive).toEqual(expectedArchive);
|
||||
expect(actual.os).toEqual(expectedOs);
|
||||
});
|
||||
|
||||
it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
|
||||
'not support os version %s',
|
||||
input => {
|
||||
expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow(
|
||||
/Platform '\w+' is not supported\. Supported platforms: .+/
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { HttpClient } from '@actions/http-client';
|
||||
|
||||
import os from 'os';
|
||||
import {
|
||||
TemurinDistribution,
|
||||
TemurinImplementation
|
||||
@ -109,6 +109,35 @@ describe('getAvailableVersions', () => {
|
||||
expect(distribution.toolcacheFolderName).toBe(expected);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['amd64', 'x64'],
|
||||
['arm64', 'aarch64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(distroArch);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
version: '17',
|
||||
architecture: '',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
|
||||
|
||||
const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot);
|
||||
const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
|
||||
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
|
||||
distribution['getPlatformOption'] = () => 'mac';
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
|
@ -3,6 +3,7 @@ import * as semver from 'semver';
|
||||
import { ZuluDistribution } from '../../src/distributions/zulu/installer';
|
||||
import { IZuluVersions } from '../../src/distributions/zulu/models';
|
||||
import * as utils from '../../src/util';
|
||||
import os from 'os';
|
||||
|
||||
const manifestData = require('../data/zulu-releases-default.json') as [];
|
||||
|
||||
@ -52,6 +53,14 @@ describe('getAvailableVersions', () => {
|
||||
[
|
||||
{ version: '8', architecture: 'x64', packageType: 'jre+fx', checkLatest: false },
|
||||
'?os=macos&ext=tar.gz&bundle_type=jre&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx'
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'arm64', packageType: 'jdk', checkLatest: false },
|
||||
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=arm&hw_bitness=64&release_status=ga'
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'arm', packageType: 'jdk', checkLatest: false },
|
||||
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=arm&hw_bitness=&release_status=ga'
|
||||
]
|
||||
])('build correct url for %s -> %s', async (input, parsedUrl) => {
|
||||
const distribution = new ZuluDistribution(input);
|
||||
@ -64,6 +73,34 @@ describe('getAvailableVersions', () => {
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
});
|
||||
|
||||
type DistroArch = {
|
||||
bitness: string;
|
||||
arch: string;
|
||||
};
|
||||
it.each([
|
||||
['amd64', { bitness: '64', arch: 'x86' }],
|
||||
['arm64', { bitness: '64', arch: 'arm' }]
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: DistroArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const distribution = new ZuluDistribution({
|
||||
version: '17',
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getPlatformOption'] = () => 'macos';
|
||||
const buildUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=${distroArch.arch}&hw_bitness=${distroArch.bitness}&release_status=ga`;
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
}
|
||||
);
|
||||
|
||||
it('load available versions', async () => {
|
||||
const distribution = new ZuluDistribution({
|
||||
version: '11',
|
||||
@ -102,7 +139,7 @@ describe('findPackageForDownload', () => {
|
||||
['15', '15.0.2+7'],
|
||||
['9.0.0', '9.0.0+0'],
|
||||
['9.0', '9.0.1+0'],
|
||||
['8.0.262', '8.0.262+19'], // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18]
|
||||
['8.0.262', '8.0.262+19'], // validate correct choice between [8.0.262.17, 8.0.262.19, 8.0.262.18]
|
||||
['8.0.262+17', '8.0.262+17'],
|
||||
['15.0.1+8', '15.0.1+8'],
|
||||
['15.0.1+9', '15.0.1+9']
|
||||
|
292
__tests__/toolchains.test.ts
Normal file
292
__tests__/toolchains.test.ts
Normal file
@ -0,0 +1,292 @@
|
||||
import * as fs from 'fs';
|
||||
import os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolchains from '../src/toolchains';
|
||||
import { M2_DIR, MVN_TOOLCHAINS_FILE } from '../src/constants';
|
||||
|
||||
const m2Dir = path.join(__dirname, M2_DIR);
|
||||
const toolchainsFile = path.join(m2Dir, MVN_TOOLCHAINS_FILE);
|
||||
|
||||
describe('toolchains tests', () => {
|
||||
let spyOSHomedir: jest.SpyInstance;
|
||||
let spyInfo: jest.SpyInstance;
|
||||
|
||||
beforeEach(async () => {
|
||||
await io.rmRF(m2Dir);
|
||||
spyOSHomedir = jest.spyOn(os, 'homedir');
|
||||
spyOSHomedir.mockReturnValue(__dirname);
|
||||
spyInfo = jest.spyOn(core, 'info');
|
||||
spyInfo.mockImplementation(() => null);
|
||||
}, 300000);
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await io.rmRF(m2Dir);
|
||||
} catch {
|
||||
console.log('Failed to remove test directories');
|
||||
}
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
}, 100000);
|
||||
|
||||
it('creates toolchains.xml in alternate locations', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const altHome = path.join(__dirname, 'runner', 'toolchains');
|
||||
const altToolchainsFile = path.join(altHome, MVN_TOOLCHAINS_FILE);
|
||||
await io.rmRF(altHome); // ensure it doesn't already exist
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: altHome,
|
||||
overwriteSettings: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(false);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(false);
|
||||
|
||||
expect(fs.existsSync(altHome)).toBe(true);
|
||||
expect(fs.existsSync(altToolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(altToolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
);
|
||||
|
||||
await io.rmRF(altHome);
|
||||
}, 100000);
|
||||
|
||||
it('creates toolchains.xml with minimal configuration', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const result = `<?xml version="1.0"?>
|
||||
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>17</version>
|
||||
<vendor>Eclipse Temurin</vendor>
|
||||
<id>temurin_17</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
);
|
||||
expect(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
).toEqual(result);
|
||||
}, 100000);
|
||||
|
||||
it('reuses existing toolchains.xml files', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const originalFile = `<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
<vendor>Sun</vendor>
|
||||
<id>sun_1.6</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
const result = `<?xml version="1.0"?>
|
||||
<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
<vendor>Sun</vendor>
|
||||
<id>sun_1.6</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>17</version>
|
||||
<vendor>Eclipse Temurin</vendor>
|
||||
<id>temurin_17</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
fs.mkdirSync(m2Dir, { recursive: true });
|
||||
fs.writeFileSync(toolchainsFile, originalFile);
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition(
|
||||
originalFile,
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
);
|
||||
expect(
|
||||
toolchains.generateToolchainDefinition(
|
||||
originalFile,
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
).toEqual(result);
|
||||
}, 100000);
|
||||
|
||||
it('does not overwrite existing toolchains.xml files', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const originalFile = `<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
<vendor>Sun</vendor>
|
||||
<id>sun_1.6</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
fs.mkdirSync(m2Dir, { recursive: true });
|
||||
fs.writeFileSync(toolchainsFile, originalFile);
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: false
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(originalFile);
|
||||
}, 100000);
|
||||
|
||||
it('generates valid toolchains.xml with minimal configuration', () => {
|
||||
const jdkInfo = {
|
||||
version: 'JAVA_VERSION',
|
||||
vendor: 'JAVA_VENDOR',
|
||||
id: 'VENDOR_VERSION',
|
||||
jdkHome: 'JAVA_HOME'
|
||||
};
|
||||
|
||||
const expectedToolchains = `<?xml version="1.0"?>
|
||||
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>${jdkInfo.version}</version>
|
||||
<vendor>${jdkInfo.vendor}</vendor>
|
||||
<id>${jdkInfo.id}</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>${jdkInfo.jdkHome}</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
expect(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
).toEqual(expectedToolchains);
|
||||
}, 100000);
|
||||
|
||||
it('creates toolchains.xml with correct id when none is supplied', async () => {
|
||||
const version = '17';
|
||||
const distributionName = 'temurin';
|
||||
const id = 'temurin_17';
|
||||
const jdkHome = '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64';
|
||||
|
||||
await toolchains.configureToolchains(version, distributionName, jdkHome, undefined);
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition('', version, distributionName, id, jdkHome)
|
||||
);
|
||||
}, 100000);
|
||||
});
|
19
action.yml
19
action.yml
@ -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
|
||||
@ -14,9 +15,8 @@ inputs:
|
||||
required: false
|
||||
default: 'jdk'
|
||||
architecture:
|
||||
description: 'The architecture of the package'
|
||||
description: "The architecture of the package (defaults to the action runner's architecture)"
|
||||
required: false
|
||||
default: 'x64'
|
||||
jdkFile:
|
||||
description: 'Path to where the compressed JDK is located'
|
||||
required: false
|
||||
@ -54,11 +54,20 @@ inputs:
|
||||
$GPG_PASSPHRASE.'
|
||||
required: false
|
||||
cache:
|
||||
description: 'Name of the build platform to cache dependencies. It can be "maven" or "gradle".'
|
||||
description: 'Name of the build platform to cache dependencies. It can be "maven", "gradle" or "sbt".'
|
||||
required: false
|
||||
job-status:
|
||||
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
|
||||
default: ${{ job.status }}
|
||||
token:
|
||||
description: The token used to authenticate when fetching version manifests hosted on github.com, such as for the Microsoft Build of OpenJDK. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||
mvn-toolchain-id:
|
||||
description: 'Name of Maven Toolchain ID if the default name of "${distribution}_${java-version}" is not wanted. See examples of supported syntax in Advanced Usage file'
|
||||
required: false
|
||||
mvn-toolchain-vendor:
|
||||
description: 'Name of Maven Toolchain Vendor if the default name of "${distribution}" is not wanted. See examples of supported syntax in Advanced Usage file'
|
||||
required: false
|
||||
outputs:
|
||||
distribution:
|
||||
description: 'Distribution of Java that has been installed'
|
||||
@ -66,6 +75,8 @@ outputs:
|
||||
description: 'Actual version of the java environment that has been installed'
|
||||
path:
|
||||
description: 'Path to where the java environment has been installed (same as $JAVA_HOME)'
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
runs:
|
||||
using: 'node16'
|
||||
main: 'dist/setup/index.js'
|
||||
|
3327
dist/cleanup/index.js
vendored
3327
dist/cleanup/index.js
vendored
File diff suppressed because it is too large
Load Diff
3758
dist/setup/index.js
vendored
3758
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,8 @@
|
||||
- [Publishing using Apache Maven](#Publishing-using-Apache-Maven)
|
||||
- [Publishing using Gradle](#Publishing-using-Gradle)
|
||||
- [Hosted Tool Cache](#Hosted-Tool-Cache)
|
||||
- [Modifying Maven Toolchains](#Modifying-Maven-Toolchains)
|
||||
- [Java-version file](#Java-version-file)
|
||||
|
||||
See [action.yml](../action.yml) for more details on task inputs.
|
||||
|
||||
@ -79,6 +81,22 @@ steps:
|
||||
- run: java -cp java HelloWorldApp
|
||||
```
|
||||
|
||||
### Using Microsoft distribution on GHES
|
||||
|
||||
`setup-java` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading the Microsoft Build of OpenJDK distribution, `setup-java` makes a request to `actions/setup-java` to get available versions on github.com (outside of the appliance). These calls to `actions/setup-java` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`.
|
||||
|
||||
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
||||
|
||||
```yaml
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||
distribution: 'microsoft'
|
||||
java-version: '11'
|
||||
```
|
||||
|
||||
If the runner is not able to access github.com, any Java versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.
|
||||
|
||||
### Amazon Corretto
|
||||
**NOTE:** Amazon Corretto only supports the major version specification.
|
||||
|
||||
@ -347,6 +365,115 @@ See the help docs on [Publishing a Package with Gradle](https://help.github.com/
|
||||
## Hosted Tool Cache
|
||||
GitHub Hosted Runners have a tool cache that comes with some Java versions pre-installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tools cache and this is where you can find the pre-installed versions of Java. `setup-java` works by taking a specific version of Java in this tool cache and adding it to PATH if the version, architecture and distribution match.
|
||||
|
||||
Currently, LTS versions of Adopt OpenJDK (`adopt`) are cached on the GitHub Hosted Runners.
|
||||
Currently, LTS versions of Eclipse Temurin (`temurin`) are cached on the GitHub Hosted Runners.
|
||||
|
||||
The tools cache gets updated on a weekly basis. For information regarding locally cached versions of Java on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments).
|
||||
|
||||
## Modifying Maven Toolchains
|
||||
The `setup-java` action generates a basic [Maven Toolchains declaration](https://maven.apache.org/guides/mini/guide-using-toolchains.html) for specified Java versions by either creating a minimal toolchains file or extending an existing declaration with the additional JDKs.
|
||||
|
||||
### Installing Multiple JDKs With Toolchains
|
||||
Subsequent calls to `setup-java` with distinct distribution and version parameters will continue to extend the toolchains declaration and make all specified Java versions available.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
8
|
||||
11
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: 15
|
||||
```
|
||||
|
||||
The result is a Toolchain with entries for JDKs 8, 11 and 15. You can even combine this with custom JDKs of arbitrary versions:
|
||||
|
||||
```yaml
|
||||
- run: |
|
||||
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: '1.6'
|
||||
architecture: x64
|
||||
```
|
||||
|
||||
This will generate a Toolchains entry with the following values: `version: 1.6`, `vendor: jkdfile`, `id: Oracle_1.6`.
|
||||
|
||||
### Modifying The Toolchain Vendor For JDKs
|
||||
Each JDK provider will receive a default `vendor` using the `distribution` input value but this can be overridden with the `mvn-toolchain-vendor` parameter as follows.
|
||||
|
||||
```yaml
|
||||
- run: |
|
||||
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: '1.6'
|
||||
architecture: x64
|
||||
mvn-toolchain-vendor: 'Oracle'
|
||||
```
|
||||
|
||||
This will generate a Toolchains entry with the following values: `version: 1.6`, `vendor: Oracle`, `id: Oracle_1.6`.
|
||||
|
||||
In case you install multiple versions of Java at once with multi-line `java-version` input setting the `mvn-toolchain-vendor` still only accepts one value and will use this value for installed JDKs as expected when installing multiple versions of the same `distribution`.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
8
|
||||
11
|
||||
mvn-toolchain-vendor: Eclipse Temurin
|
||||
```
|
||||
|
||||
### Modifying The Toolchain ID For JDKs
|
||||
Each JDK provider will receive a default `id` based on the combination of `distribution` and `java-version` in the format of `distribution_java-version` (e.g. `temurin_11`) but this can be overridden with the `mvn-toolchain-id` parameter as follows.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
mvn-toolchain-id: 'some_other_id'
|
||||
- run: java -cp java HelloWorldApp
|
||||
```
|
||||
|
||||
In case you install multiple versions of Java at once you can use the same syntax as used in `java-versions`. Please note that you have to declare an ID for all Java versions that will be installed or the `mvn-toolchain-id` instruction will be skipped wholesale due to mapping ambiguities.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
8
|
||||
11
|
||||
mvn-toolchain-id: |
|
||||
something_else
|
||||
something_other
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
113
docs/contributors.md
Normal file
113
docs/contributors.md
Normal file
@ -0,0 +1,113 @@
|
||||
# Contributors
|
||||
|
||||
Thank you for contributing!
|
||||
|
||||
We have prepared a short guide so that the process of making your contribution is as simple and clear as possible. Please check it out before you contribute!
|
||||
|
||||
## How can I contribute...
|
||||
|
||||
* [Contribute Documentation:green_book:](#contribute-documentation)
|
||||
|
||||
* [Contribute Code :computer:](#contribute-code)
|
||||
|
||||
* [Provide Support on Issues:pencil:](#provide-support-on-issues)
|
||||
|
||||
* [Review Pull Requests:mag:](#review-pull-requests)
|
||||
|
||||
## Contribute documentation
|
||||
|
||||
Documentation is a super important, critical part of this project. Docs are how we keep track of what we're doing, how, and why. It's how we stay on the same page about our policies and how we tell others everything they need to be able to use this project or contribute to it.
|
||||
|
||||
Documentation contributions of any size are welcome! Feel free to contribute even if you're just rewording a sentence to be more clear, or fixing a spelling mistake!
|
||||
|
||||
**How to contribute:**
|
||||
|
||||
Pull requests are the easiest way to contribute changes to git repos at GitHub. They are the preferred contribution method, as they offer a convenient way of commenting and amending the proposed changes.
|
||||
|
||||
- Please check that no one else has already created a pull request with these or similar changes
|
||||
- Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request
|
||||
- Make sure your changes are formatted properly and consistently with the rest of the documentation
|
||||
- Re-read what you wrote, and run a spellchecker on it to make sure you didn't miss anything
|
||||
- If your pull request is connected to an open issue, please, leave a link to this issue in the `Related issue:` section
|
||||
- If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then push them. The pull request gets automatically updated
|
||||
|
||||
**Once you've filed the pull request:**
|
||||
|
||||
- Maintainers will review your pull request
|
||||
- If a maintainer requests changes, first of all, try to think about this request critically and only after that implement and request another review
|
||||
- If your PR gets accepted, it will soon be merged into the main branch. But your contribution will take effect only after the release of a new version of the action and updating the major tag
|
||||
> Sometimes maintainers reject pull requests and that's ok! Usually, along with rejection, we supply the reason for it. Nonetheless, we still really appreciate you taking the time to do it, and we don't take that lightly :heart:
|
||||
|
||||
## Contribute code
|
||||
|
||||
We like code commits a lot! They're super handy, and they keep the project going and doing the work it needs to do to be useful to others.
|
||||
|
||||
Code contributions of just about any size are acceptable!
|
||||
|
||||
The main difference between code contributions and documentation contributions is that contributing code requires the inclusion of relevant tests for the code being added or changed. Contributions without accompanying tests will be held off until a test is added unless the maintainers consider the specific tests to be either impossible or way too much of a burden for such a contribution.
|
||||
|
||||
**How to contribute:**
|
||||
|
||||
Pull requests are the easiest way to contribute changes to git repos at GitHub. They are the preferred contribution method, as they offer a convenient way of commenting and amending the proposed changes.
|
||||
|
||||
- Please check that no one else has already created a pull request with these or similar changes
|
||||
- Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request
|
||||
- Make sure your changes are well formatted and that all tests are passing
|
||||
- If your pull request is connected to an open issue, please, leave a link to this issue in the `Related issue:` section
|
||||
- If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then push them. The pull request gets automatically updated
|
||||
|
||||
**Learn more about how to work with the repository:**
|
||||
|
||||
- To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder
|
||||
- To comply with the code style, **you need to run the `format` script**
|
||||
- To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build
|
||||
|
||||
**Learn more about how to implement tests:**
|
||||
|
||||
Adding or changing tests is an integral part of making a change to the code.
|
||||
Unit tests are in the `__tests__` folder, and end-to-end tests are in the `workflows` folder, particularly take a look at the files with `e2e` prefix, for instance, [e2e-cache.yml](https://github.com/actions/setup-java/blob/main/.github/workflows/e2e-cache.yml).
|
||||
|
||||
- The contributor can add various types of tests (like unit tests or end-to-end tests), which, in his opinion, will be necessary and sufficient for testing new or changed functionality
|
||||
- Tests should cover a successful execution, as well as some edge cases and possible errors
|
||||
- As already mentioned, pull requests without tests will be considered more carefully by maintainers. If you are sure that in this situation the tests are not needed or cannot be implemented with a commensurate effort - please add this clarification message to your pull request
|
||||
|
||||
**Once you've filed the pull request:**
|
||||
|
||||
- CI will start automatically with some checks. Wait until the end of the execution and make sure that all checks passed successfully. If some checks fail, you can open them one by one, try to find the reason for failing and make changes to your code to resolve the problem
|
||||
- Maintainers will review your pull request
|
||||
- If a maintainer requests changes, first of all, try to think about his request critically and only after that implement and request another review
|
||||
- If your PR gets accepted, it will soon be merged into the main branch. But your contribution will take effect only after the release of a new version of the action and updating the major tag
|
||||
> Sometimes maintainers reject pull requests and that's ok! Usually, along with rejection, we supply the reason for it. Nonetheless, we still really appreciate you taking the time to do it, and we don't take that lightly :heart:
|
||||
|
||||
## Provide support on issues
|
||||
|
||||
Helping out other users with their questions is an awesome way of contributing to any community. It's not uncommon for most of the issues on open source projects to be support-related questions by users trying to understand something they ran into or find their way around a known bug.
|
||||
|
||||
**To help other folks out with their questions:**
|
||||
|
||||
- Go to the [issue tracker](https://github.com/actions/setup-java/issues)
|
||||
- Read through the list until you find something that you're familiar enough with to answer to
|
||||
- Respond to the issue with whatever details are needed to clarify the question, or get more details about what's going on
|
||||
- Once the discussion wraps up and things are clarified, ask the original issue filer (or a maintainer) to close it for you
|
||||
|
||||
*Some notes on picking up support issues:*
|
||||
|
||||
- Avoid responding to issues you don't know you can answer accurately
|
||||
- Try to refer to past issues with accepted answers as much as possible. Link to them from your replies
|
||||
- Be kind and patient with users. Often, folks who have run into confusing things might be upset or impatient. This is natural. If you feel uncomfortable in conversation with them, it's better to stay away or withdraw from the issue.
|
||||
|
||||
> If some user is violating our code of conduct [standards](https://github.com/actions/setup-java/blob/main/CODE_OF_CONDUCT.md#our-standards), refer to the [enforcement](https://github.com/actions/setup-java/blob/main/CODE_OF_CONDUCT.md#enforcement) section of the Code of Conduct to resolve the conflict
|
||||
|
||||
|
||||
## Review pull requests
|
||||
|
||||
|
||||
Another great way to contribute is is to review pull request. Please, be extra kind: people who submit code/doc contributions are putting themselves in a pretty vulnerable position, and have put time and care into what they've done (even if that's not obvious to you!) Please, always respond with respect, and be understanding, but don't feel like you need to sacrifice your standards for their sake, either.
|
||||
|
||||
**How to review:**
|
||||
|
||||
- Go to the [pull requests](https://github.com/actions/setup-java/pulls)
|
||||
- Make sure you're familiar with the code or documentation is updated, unless it's a minor change (spellchecking, minor formatting, etc.)
|
||||
- Review changes using the GitHub functionality. You can ask a clarifying question, point out an error or suggest an alternative.
|
||||
> Note: You may ask for minor changes - "nitpicks", but consider whether they are real blockers to merging or not
|
||||
- Submit your review, which may include comments, an approval, or a changes request
|
3555
package-lock.json
generated
3555
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-java",
|
||||
"version": "3.1.1",
|
||||
"version": "3.4.1",
|
||||
"private": true,
|
||||
"description": "setup java action",
|
||||
"main": "dist/setup/index.js",
|
||||
@ -24,8 +24,8 @@
|
||||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^2.0.2",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/cache": "^3.0.4",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/glob": "^0.2.0",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
@ -38,9 +38,9 @@
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.25",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.5",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"prettier": "^1.19.1",
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.2.3"
|
||||
|
@ -10,15 +10,12 @@ import * as constants from './constants';
|
||||
import * as gpg from './gpg';
|
||||
import { getBooleanInput } from './util';
|
||||
|
||||
export const M2_DIR = '.m2';
|
||||
export const SETTINGS_FILE = 'settings.xml';
|
||||
|
||||
export async function configureAuthentication() {
|
||||
const id = core.getInput(constants.INPUT_SERVER_ID);
|
||||
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
||||
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) || path.join(os.homedir(), M2_DIR);
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) || path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(constants.INPUT_OVERWRITE_SETTINGS, true);
|
||||
const gpgPrivateKey =
|
||||
core.getInput(constants.INPUT_GPG_PRIVATE_KEY) || constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
||||
@ -54,7 +51,7 @@ export async function createAuthenticationSettings(
|
||||
overwriteSettings: boolean,
|
||||
gpgPassphrase: string | undefined = undefined
|
||||
) {
|
||||
core.info(`Creating ${SETTINGS_FILE} with server-id: ${id}`);
|
||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
// otherwise use the home/.m2/ path
|
||||
await io.mkdirP(settingsDirectory);
|
||||
@ -106,7 +103,7 @@ export function generate(
|
||||
}
|
||||
|
||||
async function write(directory: string, settings: string, overwriteSettings: boolean) {
|
||||
const location = path.join(directory, SETTINGS_FILE);
|
||||
const location = path.join(directory, constants.MVN_SETTINGS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
|
21
src/cache.ts
21
src/cache.ts
@ -31,14 +31,24 @@ const supportedPackageManager: PackageManager[] = [
|
||||
id: 'gradle',
|
||||
path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
|
||||
pattern: [
|
||||
'**/*.gradle*',
|
||||
'**/gradle-wrapper.properties',
|
||||
'buildSrc/**/Versions.kt',
|
||||
'buildSrc/**/Dependencies.kt',
|
||||
'gradle/*.versions.toml'
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'sbt',
|
||||
path: [
|
||||
join(os.homedir(), '.ivy2', 'cache'),
|
||||
join(os.homedir(), '.sbt'),
|
||||
getCoursierCachePath()
|
||||
getCoursierCachePath(),
|
||||
// Some files should not be cached to avoid resolution problems.
|
||||
// In particular the resolution of snapshots (ideological gap between maven/ivy).
|
||||
'!' + join(os.homedir(), '.sbt', '*.lock'),
|
||||
'!' + join(os.homedir(), '**', 'ivydata-*.properties')
|
||||
],
|
||||
pattern: ['**/*.sbt', '**/project/build.properties', '**/project/**.{scala,sbt}']
|
||||
}
|
||||
@ -87,9 +97,8 @@ export async function restore(id: string) {
|
||||
);
|
||||
}
|
||||
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey, [
|
||||
`${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}`
|
||||
]);
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||
core.setOutput('cache-hit', matchedKey === primaryKey);
|
||||
@ -108,7 +117,7 @@ export async function save(id: string) {
|
||||
const packageManager = findPackageManager(id);
|
||||
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
||||
|
||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||
|
||||
if (!primaryKey) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
export const MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||
export const INPUT_JAVA_VERSION = 'java-version';
|
||||
export const INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
export const INPUT_ARCHITECTURE = 'architecture';
|
||||
export const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
export const INPUT_DISTRIBUTION = 'distribution';
|
||||
@ -20,3 +21,11 @@ export const INPUT_CACHE = 'cache';
|
||||
export const INPUT_JOB_STATUS = 'job-status';
|
||||
|
||||
export const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
||||
|
||||
export const M2_DIR = '.m2';
|
||||
export const MVN_SETTINGS_FILE = 'settings.xml';
|
||||
export const MVN_TOOLCHAINS_FILE = 'toolchains.xml';
|
||||
export const INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
|
||||
export const INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
|
||||
|
||||
export const DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
|
||||
|
@ -88,12 +88,14 @@ export class AdoptDistribution extends JavaBase {
|
||||
|
||||
private async getAvailableVersions(): Promise<IAdoptAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const arch = this.distributionArchitecture();
|
||||
const imageType = this.packageType;
|
||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('adopt-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('adopt-retrieve-available-versions');
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
@ -7,6 +7,7 @@ import * as httpm from '@actions/http-client';
|
||||
import { getToolcachePath, isVersionSatisfies } from '../util';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models';
|
||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../constants';
|
||||
import os from 'os';
|
||||
|
||||
export abstract class JavaBase {
|
||||
protected http: httpm.HttpClient;
|
||||
@ -25,7 +26,7 @@ export abstract class JavaBase {
|
||||
({ version: this.version, stable: this.stable } = this.normalizeVersion(
|
||||
installerOptions.version
|
||||
));
|
||||
this.architecture = installerOptions.architecture;
|
||||
this.architecture = installerOptions.architecture || os.arch();
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
}
|
||||
@ -142,10 +143,32 @@ export abstract class JavaBase {
|
||||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
const majorVersion = version.split('.')[0];
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
core.exportVariable(`JAVA_HOME_${majorVersion}_${this.architecture.toUpperCase()}`, toolPath);
|
||||
}
|
||||
|
||||
protected distributionArchitecture(): string {
|
||||
// default mappings of config architectures to distribution architectures
|
||||
// override if a distribution uses any different names; see liberica for an example
|
||||
|
||||
// node's os.arch() - which this defaults to - can return any of:
|
||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64'
|
||||
// so we need to map these to java distribution architectures
|
||||
// 'amd64' is included here too b/c it's a common alias for 'x64' people might use explicitly
|
||||
switch (this.architecture) {
|
||||
case 'amd64':
|
||||
return 'x64';
|
||||
case 'ia32':
|
||||
return 'x86';
|
||||
case 'arm64':
|
||||
return 'aarch64';
|
||||
default:
|
||||
return this.architecture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import path from 'path';
|
||||
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import { ICorrettoAllAvailableVersions, ICorettoAvailableVersions } from './models';
|
||||
import { ICorrettoAllAvailableVersions, ICorrettoAvailableVersions } from './models';
|
||||
|
||||
export class CorrettoDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
@ -66,12 +66,14 @@ export class CorrettoDistribution extends JavaBase {
|
||||
return resolvedVersion;
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<ICorettoAvailableVersions[]> {
|
||||
private async getAvailableVersions(): Promise<ICorrettoAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const arch = this.distributionArchitecture();
|
||||
const imageType = this.packageType;
|
||||
|
||||
console.time('coretto-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('corretto-retrieve-available-versions');
|
||||
}
|
||||
|
||||
const availableVersionsUrl =
|
||||
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json';
|
||||
@ -83,8 +85,8 @@ export class CorrettoDistribution extends JavaBase {
|
||||
throw Error(`Could not fetch latest corretto versions from ${availableVersionsUrl}`);
|
||||
}
|
||||
|
||||
const eligbleVersions = fetchedCurrentVersions?.[platform]?.[arch]?.[imageType];
|
||||
const availableVersions = this.getAvailableVersionsForPlatform(eligbleVersions);
|
||||
const eligibleVersions = fetchedCurrentVersions?.[platform]?.[arch]?.[imageType];
|
||||
const availableVersions = this.getAvailableVersionsForPlatform(eligibleVersions);
|
||||
|
||||
if (core.isDebug()) {
|
||||
this.printAvailableVersions(availableVersions);
|
||||
@ -94,19 +96,19 @@ export class CorrettoDistribution extends JavaBase {
|
||||
}
|
||||
|
||||
private getAvailableVersionsForPlatform(
|
||||
eligbleVersions: ICorrettoAllAvailableVersions['os']['arch']['imageType'] | undefined
|
||||
): ICorettoAvailableVersions[] {
|
||||
const availableVersions: ICorettoAvailableVersions[] = [];
|
||||
eligibleVersions: ICorrettoAllAvailableVersions['os']['arch']['imageType'] | undefined
|
||||
): ICorrettoAvailableVersions[] {
|
||||
const availableVersions: ICorrettoAvailableVersions[] = [];
|
||||
|
||||
for (const version in eligbleVersions) {
|
||||
const availableVersion = eligbleVersions[version];
|
||||
for (const version in eligibleVersions) {
|
||||
const availableVersion = eligibleVersions[version];
|
||||
for (const fileType in availableVersion) {
|
||||
const skipNonExtractableBinaries = fileType != getDownloadArchiveExtension();
|
||||
if (skipNonExtractableBinaries) {
|
||||
continue;
|
||||
}
|
||||
const availableVersionDetails = availableVersion[fileType];
|
||||
const correttoVersion = this.getCorettoVersion(availableVersionDetails.resource);
|
||||
const correttoVersion = this.getCorrettoVersion(availableVersionDetails.resource);
|
||||
|
||||
availableVersions.push({
|
||||
checksum: availableVersionDetails.checksum,
|
||||
@ -122,9 +124,9 @@ export class CorrettoDistribution extends JavaBase {
|
||||
return availableVersions;
|
||||
}
|
||||
|
||||
private printAvailableVersions(availableVersions: ICorettoAvailableVersions[]) {
|
||||
private printAvailableVersions(availableVersions: ICorrettoAvailableVersions[]) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('coretto-retrieve-available-versions');
|
||||
console.timeEnd('corretto-retrieve-available-versions');
|
||||
console.log(`Available versions: [${availableVersions.length}]`);
|
||||
console.log(
|
||||
availableVersions.map(item => `${item.version}: ${item.correttoVersion}`).join(', ')
|
||||
@ -133,7 +135,7 @@ export class CorrettoDistribution extends JavaBase {
|
||||
}
|
||||
|
||||
private getPlatformOption(): string {
|
||||
// Coretto has its own platform names so we need to map them
|
||||
// Corretto has its own platform names so we need to map them
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
@ -144,7 +146,7 @@ export class CorrettoDistribution extends JavaBase {
|
||||
}
|
||||
}
|
||||
|
||||
private getCorettoVersion(resource: string): string {
|
||||
private getCorrettoVersion(resource: string): string {
|
||||
const regex = /(\d+.+)\//;
|
||||
const match = regex.exec(resource);
|
||||
if (match === null) {
|
||||
|
@ -14,7 +14,7 @@ export interface ICorrettoAllAvailableVersions {
|
||||
};
|
||||
}
|
||||
|
||||
export interface ICorettoAvailableVersions {
|
||||
export interface ICorrettoAvailableVersions {
|
||||
version: string;
|
||||
fileType: string;
|
||||
checksum: string;
|
||||
|
@ -10,7 +10,7 @@ import path from 'path';
|
||||
|
||||
const supportedPlatform = `'linux', 'linux-musl', 'macos', 'solaris', 'windows'`;
|
||||
|
||||
const supportedArchitecture = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`;
|
||||
const supportedArchitectures = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`;
|
||||
|
||||
export class LibericaDistributions extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
@ -66,7 +66,9 @@ export class LibericaDistributions extends JavaBase {
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<LibericaVersion[]> {
|
||||
console.time('liberica-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('liberica-retrieve-available-versions');
|
||||
}
|
||||
const url = this.prepareAvailableVersionsUrl();
|
||||
|
||||
if (core.isDebug()) {
|
||||
@ -110,7 +112,8 @@ export class LibericaDistributions extends JavaBase {
|
||||
}
|
||||
|
||||
private getArchitectureOptions(): ArchitectureOptions {
|
||||
switch (this.architecture) {
|
||||
const arch = this.distributionArchitecture();
|
||||
switch (arch) {
|
||||
case 'x86':
|
||||
return { bitness: '32', arch: 'x86' };
|
||||
case 'x64':
|
||||
@ -123,7 +126,7 @@ export class LibericaDistributions extends JavaBase {
|
||||
return { bitness: '64', arch: 'ppc' };
|
||||
default:
|
||||
throw new Error(
|
||||
`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`
|
||||
`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitectures}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -154,4 +157,14 @@ export class LibericaDistributions extends JavaBase {
|
||||
}
|
||||
return mainVersion;
|
||||
}
|
||||
|
||||
protected distributionArchitecture(): string {
|
||||
let arch = super.distributionArchitecture();
|
||||
switch (arch) {
|
||||
case 'arm':
|
||||
return 'armv7';
|
||||
default:
|
||||
return arch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import semver from 'semver';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||
import * as core from '@actions/core';
|
||||
import { MicrosoftVersion, PlatformOptions } from './models';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import { OutgoingHttpHeaders } from 'http';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { ITypedResponse } from '@actions/http-client/interfaces';
|
||||
|
||||
export class MicrosoftDistributions extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
@ -37,7 +37,8 @@ export class MicrosoftDistributions extends JavaBase {
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
|
||||
@ -49,76 +50,61 @@ export class MicrosoftDistributions extends JavaBase {
|
||||
throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type');
|
||||
}
|
||||
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const manifest = await this.getAvailableVersions();
|
||||
|
||||
const opts = this.getPlatformOption();
|
||||
const availableVersions = availableVersionsRaw.map(item => ({
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${
|
||||
this.architecture
|
||||
}.${opts.archive}`,
|
||||
version: this.convertVersionToSemver(item)
|
||||
}));
|
||||
if (!manifest) {
|
||||
throw new Error('Could not load manifest for Microsoft Build of OpenJDK');
|
||||
}
|
||||
|
||||
const satisfiedVersion = availableVersions
|
||||
.filter(item => isVersionSatisfies(range, item.version))
|
||||
.sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
|
||||
const foundRelease = await tc.findFromManifest(range, true, manifest, arch);
|
||||
|
||||
if (!satisfiedVersion) {
|
||||
const availableOptions = availableVersions.map(item => item.version).join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
if (!foundRelease) {
|
||||
throw new Error(
|
||||
`Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`
|
||||
`Could not find satisfied version for SemVer ${range}.\nAvailable versions: ${manifest
|
||||
.map(item => item.version)
|
||||
.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return satisfiedVersion;
|
||||
return { url: foundRelease.files[0].download_url, version: foundRelease.version };
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<MicrosoftVersion[]> {
|
||||
private async getAvailableVersions(): Promise<tc.IToolRelease[] | null> {
|
||||
// TODO get these dynamically!
|
||||
// We will need Microsoft to add an endpoint where we can query for versions.
|
||||
const jdkVersions = [
|
||||
{
|
||||
version: [17, 0, 1, 12, 1]
|
||||
},
|
||||
{
|
||||
version: [16, 0, 2, 7, 1]
|
||||
const token = core.getInput('token');
|
||||
const auth = !token ? undefined : `token ${token}`;
|
||||
const owner = 'actions';
|
||||
const repository = 'setup-java';
|
||||
const branch = 'main';
|
||||
const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json';
|
||||
|
||||
let releases: tc.IToolRelease[] | null = null;
|
||||
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
|
||||
|
||||
const headers: OutgoingHttpHeaders = {
|
||||
authorization: auth,
|
||||
accept: 'application/vnd.github.VERSION.raw'
|
||||
};
|
||||
|
||||
let response: ITypedResponse<tc.IToolRelease[]> | null = null;
|
||||
|
||||
try {
|
||||
response = await this.http.getJson<tc.IToolRelease[]>(fileUrl, headers);
|
||||
if (!response.result) {
|
||||
return null;
|
||||
}
|
||||
];
|
||||
|
||||
// M1 is only supported for Java 16 & 17
|
||||
if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
|
||||
jdkVersions.push({
|
||||
version: [11, 0, 13, 8, 1]
|
||||
});
|
||||
} catch (err) {
|
||||
core.debug(
|
||||
`Http request for microsoft-openjdk-versions.json failed with status code: ${response?.statusCode}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return jdkVersions;
|
||||
}
|
||||
|
||||
private getPlatformOption(
|
||||
platform: NodeJS.Platform = process.platform /* for testing */
|
||||
): PlatformOptions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return { archive: 'tar.gz', os: 'macos' };
|
||||
case 'win32':
|
||||
return { archive: 'zip', os: 'windows' };
|
||||
case 'linux':
|
||||
return { archive: 'tar.gz', os: 'linux' };
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`
|
||||
);
|
||||
if (response.result) {
|
||||
releases = response.result;
|
||||
}
|
||||
}
|
||||
|
||||
private convertVersionToSemver(version: MicrosoftVersion): string {
|
||||
const major = version.version[0];
|
||||
const minor = version.version[1];
|
||||
const patch = version.version[2];
|
||||
return `${major}.${minor}.${patch}`;
|
||||
return releases;
|
||||
}
|
||||
}
|
||||
|
181
src/distributions/microsoft/microsoft-openjdk-versions.json
Normal file
181
src/distributions/microsoft/microsoft-openjdk-versions.json
Normal file
@ -0,0 +1,181 @@
|
||||
[
|
||||
{
|
||||
"version": "17.0.3",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "17.0.1+12.1",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "16.0.2+7.1",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.15",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.13+8.1",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -1,12 +1,2 @@
|
||||
type OsVersions = 'linux' | 'macos' | 'windows';
|
||||
type ArchiveType = 'tar.gz' | 'zip';
|
||||
|
||||
export interface PlatformOptions {
|
||||
archive: ArchiveType;
|
||||
os: OsVersions;
|
||||
}
|
||||
|
||||
export interface MicrosoftVersion {
|
||||
downloadUrl?: string;
|
||||
version: Array<number>;
|
||||
}
|
||||
|
@ -86,12 +86,14 @@ export class TemurinDistribution extends JavaBase {
|
||||
|
||||
private async getAvailableVersions(): Promise<ITemurinAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const arch = this.distributionArchitecture();
|
||||
const imageType = this.packageType;
|
||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('temurin-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('temurin-retrieve-available-versions');
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
@ -90,7 +90,9 @@ export class ZuluDistribution extends JavaBase {
|
||||
const javafx = features?.includes('fx') ?? false;
|
||||
const releaseStatus = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('azul-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('azul-retrieve-available-versions');
|
||||
}
|
||||
const requestArguments = [
|
||||
`os=${platform}`,
|
||||
`ext=${extension}`,
|
||||
@ -129,12 +131,17 @@ export class ZuluDistribution extends JavaBase {
|
||||
hw_bitness: string;
|
||||
abi: string;
|
||||
} {
|
||||
if (this.architecture == 'x64') {
|
||||
return { arch: 'x86', hw_bitness: '64', abi: '' };
|
||||
} else if (this.architecture == 'x86') {
|
||||
return { arch: 'x86', hw_bitness: '32', abi: '' };
|
||||
} else {
|
||||
return { arch: this.architecture, hw_bitness: '', abi: '' };
|
||||
const arch = this.distributionArchitecture();
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
return { arch: 'x86', hw_bitness: '64', abi: '' };
|
||||
case 'x86':
|
||||
return { arch: 'x86', hw_bitness: '32', abi: '' };
|
||||
case 'aarch64':
|
||||
case 'arm64':
|
||||
return { arch: 'arm', hw_bitness: '64', abi: '' };
|
||||
default:
|
||||
return { arch: arch, hw_bitness: '', abi: '' };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as auth from './auth';
|
||||
import { getBooleanInput, isCacheFeatureAvailable } from './util';
|
||||
import { getBooleanInput, isCacheFeatureAvailable, getVersionFromFileContent } from './util';
|
||||
import * as toolchains from './toolchains';
|
||||
import * as constants from './constants';
|
||||
import { restore } from './cache';
|
||||
import * as path from 'path';
|
||||
@ -9,35 +11,56 @@ import { JavaInstallerOptions } from './distributions/base-models';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const version = core.getInput(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 = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version,
|
||||
checkLatest
|
||||
};
|
||||
core.startGroup('Installed distributions');
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
if (versions.length !== toolchainIds.length) {
|
||||
toolchainIds = [];
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
if (!versions.length && !versionFile) {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
if (!versions.length) {
|
||||
core.debug('java-version input is empty, looking for java-version-file input');
|
||||
const content = fs
|
||||
.readFileSync(versionFile)
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
const version = getVersionFromFileContent(content, distributionName);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
|
||||
if (!version) {
|
||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||
}
|
||||
|
||||
await installVersion(version, installerInputsOptions);
|
||||
}
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
await installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||
|
||||
@ -51,3 +74,50 @@ async function run() {
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
async function installVersion(version: string, options: installerInputsOptions, toolchainId = 0) {
|
||||
const {
|
||||
distributionName,
|
||||
jdkFile,
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
toolchainIds
|
||||
} = options;
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
version
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
await 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('');
|
||||
}
|
||||
|
||||
interface installerInputsOptions {
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
distributionName: string;
|
||||
jdkFile: string;
|
||||
toolchainIds: Array<string>;
|
||||
}
|
||||
|
158
src/toolchains.ts
Normal file
158
src/toolchains.ts
Normal file
@ -0,0 +1,158 @@
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as constants from './constants';
|
||||
|
||||
import { getBooleanInput } from './util';
|
||||
import { create as xmlCreate } from 'xmlbuilder2';
|
||||
|
||||
interface JdkInfo {
|
||||
version: string;
|
||||
vendor: string;
|
||||
id: string;
|
||||
jdkHome: string;
|
||||
}
|
||||
|
||||
export async function configureToolchains(
|
||||
version: string,
|
||||
distributionName: string,
|
||||
jdkHome: string,
|
||||
toolchainId?: string
|
||||
) {
|
||||
const vendor = core.getInput(constants.INPUT_MVN_TOOLCHAIN_VENDOR) || distributionName;
|
||||
const id = toolchainId || `${vendor}_${version}`;
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) || path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(constants.INPUT_OVERWRITE_SETTINGS, true);
|
||||
|
||||
await createToolchainsSettings({
|
||||
jdkInfo: {
|
||||
version,
|
||||
vendor,
|
||||
id,
|
||||
jdkHome
|
||||
},
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
});
|
||||
}
|
||||
|
||||
export async function createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
}: {
|
||||
jdkInfo: JdkInfo;
|
||||
settingsDirectory: string;
|
||||
overwriteSettings: boolean;
|
||||
}) {
|
||||
core.info(
|
||||
`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`
|
||||
);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
// otherwise use the home/.m2/ path
|
||||
await io.mkdirP(settingsDirectory);
|
||||
const originalToolchains = await readExistingToolchainsFile(settingsDirectory);
|
||||
const updatedToolchains = generateToolchainDefinition(
|
||||
originalToolchains,
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
);
|
||||
await writeToolchainsFileToDisk(settingsDirectory, updatedToolchains, overwriteSettings);
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
export function generateToolchainDefinition(
|
||||
original: string,
|
||||
version: string,
|
||||
vendor: string,
|
||||
id: string,
|
||||
jdkHome: string
|
||||
) {
|
||||
let xmlObj;
|
||||
if (original?.length) {
|
||||
xmlObj = xmlCreate(original)
|
||||
.root()
|
||||
.ele({
|
||||
toolchain: {
|
||||
type: 'jdk',
|
||||
provides: {
|
||||
version: `${version}`,
|
||||
vendor: `${vendor}`,
|
||||
id: `${id}`
|
||||
},
|
||||
configuration: {
|
||||
jdkHome: `${jdkHome}`
|
||||
}
|
||||
}
|
||||
});
|
||||
} else
|
||||
xmlObj = xmlCreate({
|
||||
toolchains: {
|
||||
'@xmlns': 'https://maven.apache.org/TOOLCHAINS/1.1.0',
|
||||
'@xmlns:xsi': 'https://www.w3.org/2001/XMLSchema-instance',
|
||||
'@xsi:schemaLocation':
|
||||
'https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
|
||||
toolchain: [
|
||||
{
|
||||
type: 'jdk',
|
||||
provides: {
|
||||
version: `${version}`,
|
||||
vendor: `${vendor}`,
|
||||
id: `${id}`
|
||||
},
|
||||
configuration: {
|
||||
jdkHome: `${jdkHome}`
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
return xmlObj.end({
|
||||
format: 'xml',
|
||||
wellFormed: false,
|
||||
headless: false,
|
||||
prettyPrint: true,
|
||||
width: 80
|
||||
});
|
||||
}
|
||||
|
||||
async function readExistingToolchainsFile(directory: string) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
if (fs.existsSync(location)) {
|
||||
return fs.readFileSync(location, {
|
||||
encoding: 'utf-8',
|
||||
flag: 'r'
|
||||
});
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async function writeToolchainsFileToDisk(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
} else if (!settingsExists) {
|
||||
core.info(`Writing to ${location}`);
|
||||
} else {
|
||||
core.info(
|
||||
`Skipping generation of ${location} because file already exists and overwriting is not enabled`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return fs.writeFileSync(location, settings, {
|
||||
encoding: 'utf-8',
|
||||
flag: 'w'
|
||||
});
|
||||
}
|
40
src/util.ts
40
src/util.ts
@ -6,7 +6,7 @@ import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import { INPUT_JOB_STATUS } from './constants';
|
||||
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
|
||||
|
||||
export function getTempDir() {
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
@ -99,3 +99,41 @@ export function isCacheFeatureAvailable(): boolean {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function getVersionFromFileContent(
|
||||
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)
|
||||
: '';
|
||||
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 (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
const coerceVersion = semver.coerce(version) ?? version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
|
||||
return version.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;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
"resolveJsonModule": true,
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
|
Reference in New Issue
Block a user