mirror of
https://github.com/actions/setup-java.git
synced 2026-11-24 21:33:04 +00:00
Compare commits
1 Commits
6937f5eb31
...
copilot/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7761ca7f37 |
209
.github/workflows/benchmark-cache-restore.yml
vendored
209
.github/workflows/benchmark-cache-restore.yml
vendored
@@ -1,209 +0,0 @@
|
|||||||
name: Benchmark cache restore
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
baseline-ref:
|
|
||||||
description: Git ref containing the sequential restore implementation
|
|
||||||
required: true
|
|
||||||
default: main
|
|
||||||
type: string
|
|
||||||
candidate-ref:
|
|
||||||
description: Git ref containing the concurrent restore implementation (defaults to the dispatched ref)
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
warm-caches:
|
|
||||||
name: Warm ${{ matrix.tool }} ${{ matrix.profile }} caches (${{ matrix.os }})
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [macos-15-intel, windows-latest, ubuntu-latest]
|
|
||||||
tool: [maven, gradle]
|
|
||||||
profile: [small, large]
|
|
||||||
steps:
|
|
||||||
- name: Checkout benchmark workflow
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Checkout baseline
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
path: baseline
|
|
||||||
persist-credentials: false
|
|
||||||
ref: ${{ inputs.baseline-ref }}
|
|
||||||
- name: Checkout candidate
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
path: candidate
|
|
||||||
persist-credentials: false
|
|
||||||
ref: ${{ inputs.candidate-ref || github.ref }}
|
|
||||||
- name: Prepare benchmark inputs
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh prepare "${{ matrix.tool }}" "${{ matrix.profile }}"
|
|
||||||
- name: Prepare cache save
|
|
||||||
uses: ./candidate
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
- name: Populate benchmark caches
|
|
||||||
run: |
|
|
||||||
bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
bash __tests__/benchmark-cache-restore.sh populate "${{ matrix.tool }}" "${{ matrix.profile }}"
|
|
||||||
|
|
||||||
benchmark:
|
|
||||||
name: Benchmark ${{ matrix.tool }} ${{ matrix.profile }} (${{ matrix.os }})
|
|
||||||
needs: warm-caches
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [macos-15-intel, windows-latest, ubuntu-latest]
|
|
||||||
tool: [maven, gradle]
|
|
||||||
profile: [small, large]
|
|
||||||
steps:
|
|
||||||
- name: Checkout benchmark workflow
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Checkout baseline
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
path: baseline
|
|
||||||
persist-credentials: false
|
|
||||||
ref: ${{ inputs.baseline-ref }}
|
|
||||||
- name: Checkout candidate
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
path: candidate
|
|
||||||
persist-credentials: false
|
|
||||||
ref: ${{ inputs.candidate-ref || github.ref }}
|
|
||||||
- name: Prepare benchmark inputs
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh prepare "${{ matrix.tool }}" "${{ matrix.profile }}"
|
|
||||||
|
|
||||||
- name: Reset caches for baseline iteration 1
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
- name: Start baseline iteration 1 timer
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh start "${{ matrix.tool }}"
|
|
||||||
- name: Restore with baseline iteration 1
|
|
||||||
id: baseline-1
|
|
||||||
uses: ./baseline
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Record baseline iteration 1
|
|
||||||
env:
|
|
||||||
CACHE_HIT: ${{ steps.baseline-1.outputs.cache-hit }}
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh record "${{ matrix.tool }}" "${{ matrix.os }}" "${{ matrix.profile }}" baseline 1 "$CACHE_HIT"
|
|
||||||
|
|
||||||
- name: Reset caches for candidate iteration 1
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
- name: Start candidate iteration 1 timer
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh start "${{ matrix.tool }}"
|
|
||||||
- name: Restore with candidate iteration 1
|
|
||||||
id: candidate-1
|
|
||||||
uses: ./candidate
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Record candidate iteration 1
|
|
||||||
env:
|
|
||||||
CACHE_HIT: ${{ steps.candidate-1.outputs.cache-hit }}
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh record "${{ matrix.tool }}" "${{ matrix.os }}" "${{ matrix.profile }}" candidate 1 "$CACHE_HIT"
|
|
||||||
|
|
||||||
- name: Reset caches for candidate iteration 2
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
- name: Start candidate iteration 2 timer
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh start "${{ matrix.tool }}"
|
|
||||||
- name: Restore with candidate iteration 2
|
|
||||||
id: candidate-2
|
|
||||||
uses: ./candidate
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Record candidate iteration 2
|
|
||||||
env:
|
|
||||||
CACHE_HIT: ${{ steps.candidate-2.outputs.cache-hit }}
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh record "${{ matrix.tool }}" "${{ matrix.os }}" "${{ matrix.profile }}" candidate 2 "$CACHE_HIT"
|
|
||||||
|
|
||||||
- name: Reset caches for baseline iteration 2
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
- name: Start baseline iteration 2 timer
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh start "${{ matrix.tool }}"
|
|
||||||
- name: Restore with baseline iteration 2
|
|
||||||
id: baseline-2
|
|
||||||
uses: ./baseline
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Record baseline iteration 2
|
|
||||||
env:
|
|
||||||
CACHE_HIT: ${{ steps.baseline-2.outputs.cache-hit }}
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh record "${{ matrix.tool }}" "${{ matrix.os }}" "${{ matrix.profile }}" baseline 2 "$CACHE_HIT"
|
|
||||||
|
|
||||||
- name: Reset caches for baseline iteration 3
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
- name: Start baseline iteration 3 timer
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh start "${{ matrix.tool }}"
|
|
||||||
- name: Restore with baseline iteration 3
|
|
||||||
id: baseline-3
|
|
||||||
uses: ./baseline
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Record baseline iteration 3
|
|
||||||
env:
|
|
||||||
CACHE_HIT: ${{ steps.baseline-3.outputs.cache-hit }}
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh record "${{ matrix.tool }}" "${{ matrix.os }}" "${{ matrix.profile }}" baseline 3 "$CACHE_HIT"
|
|
||||||
|
|
||||||
- name: Reset caches for candidate iteration 3
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh reset "${{ matrix.tool }}"
|
|
||||||
- name: Start candidate iteration 3 timer
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh start "${{ matrix.tool }}"
|
|
||||||
- name: Restore with candidate iteration 3
|
|
||||||
id: candidate-3
|
|
||||||
uses: ./candidate
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: '17'
|
|
||||||
cache: ${{ matrix.tool }}
|
|
||||||
cache-dependency-path: benchmark/${{ matrix.tool == 'maven' && 'pom.xml' || 'build.gradle' }}
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Record candidate iteration 3
|
|
||||||
env:
|
|
||||||
CACHE_HIT: ${{ steps.candidate-3.outputs.cache-hit }}
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh record "${{ matrix.tool }}" "${{ matrix.os }}" "${{ matrix.profile }}" candidate 3 "$CACHE_HIT"
|
|
||||||
|
|
||||||
- name: Summarize benchmark
|
|
||||||
run: bash __tests__/benchmark-cache-restore.sh summarize "${{ matrix.tool }}" "$GITHUB_STEP_SUMMARY"
|
|
||||||
- name: Upload raw timings
|
|
||||||
uses: actions/upload-artifact@v6
|
|
||||||
with:
|
|
||||||
name: cache-restore-${{ matrix.os }}-${{ matrix.tool }}-${{ matrix.profile }}
|
|
||||||
path: .benchmark-results/timings.csv
|
|
||||||
if-no-files-found: error
|
|
||||||
74
.github/workflows/e2e-cache.yml
vendored
74
.github/workflows/e2e-cache.yml
vendored
@@ -42,10 +42,7 @@ jobs:
|
|||||||
# https://github.com/actions/cache/issues/454#issuecomment-840493935
|
# https://github.com/actions/cache/issues/454#issuecomment-840493935
|
||||||
run: |
|
run: |
|
||||||
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle1
|
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle1
|
||||||
mkdir -p "$HOME/.gradle/wrapper/dists/setup-java-e2e"
|
|
||||||
echo "gradle wrapper cache" > "$HOME/.gradle/wrapper/dists/setup-java-e2e/payload"
|
|
||||||
bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
||||||
bash __tests__/check-dir.sh "$HOME/.gradle/wrapper/dists"
|
|
||||||
gradle-restore:
|
gradle-restore:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -65,11 +62,8 @@ jobs:
|
|||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
cache: gradle
|
cache: gradle
|
||||||
cache-read-only: true
|
|
||||||
- name: Confirm that ~/.gradle/caches directory has been made
|
- name: Confirm that ~/.gradle/caches directory has been made
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
run: bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
||||||
- name: Confirm that the Gradle Wrapper cache has been restored
|
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.gradle/wrapper/dists"
|
|
||||||
maven-save:
|
maven-save:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -91,10 +85,7 @@ jobs:
|
|||||||
- name: Create files to cache
|
- name: Create files to cache
|
||||||
run: |
|
run: |
|
||||||
mvn verify -f __tests__/cache/maven/pom.xml
|
mvn verify -f __tests__/cache/maven/pom.xml
|
||||||
mkdir -p "$HOME/.m2/wrapper/dists/setup-java-e2e"
|
|
||||||
echo "maven wrapper cache" > "$HOME/.m2/wrapper/dists/setup-java-e2e/payload"
|
|
||||||
bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
||||||
bash __tests__/check-dir.sh "$HOME/.m2/wrapper/dists"
|
|
||||||
maven-restore:
|
maven-restore:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -114,11 +105,8 @@ jobs:
|
|||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
cache: maven
|
cache: maven
|
||||||
cache-read-only: true
|
|
||||||
- name: Confirm that ~/.m2/repository directory has been made
|
- name: Confirm that ~/.m2/repository directory has been made
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
run: bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
||||||
- name: Confirm that the Maven Wrapper cache has been restored
|
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.m2/wrapper/dists"
|
|
||||||
sbt-save:
|
sbt-save:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
defaults:
|
defaults:
|
||||||
@@ -181,7 +169,6 @@ jobs:
|
|||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
cache: sbt
|
cache: sbt
|
||||||
cache-read-only: true
|
|
||||||
|
|
||||||
- name: Confirm that ~/Library/Caches/Coursier directory has been made
|
- name: Confirm that ~/Library/Caches/Coursier directory has been made
|
||||||
if: matrix.os == 'macos-15-intel'
|
if: matrix.os == 'macos-15-intel'
|
||||||
@@ -216,10 +203,7 @@ jobs:
|
|||||||
# https://github.com/actions/cache/issues/454#issuecomment-840493935
|
# https://github.com/actions/cache/issues/454#issuecomment-840493935
|
||||||
run: |
|
run: |
|
||||||
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle1
|
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle1
|
||||||
mkdir -p "$HOME/.gradle/wrapper/dists/setup-java-e2e-gradle1"
|
|
||||||
echo "gradle wrapper cache gradle1" > "$HOME/.gradle/wrapper/dists/setup-java-e2e-gradle1/payload"
|
|
||||||
bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
||||||
bash __tests__/check-dir.sh "$HOME/.gradle/wrapper/dists"
|
|
||||||
gradle1-restore:
|
gradle1-restore:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -242,8 +226,6 @@ jobs:
|
|||||||
cache-dependency-path: __tests__/cache/gradle1/*.gradle*
|
cache-dependency-path: __tests__/cache/gradle1/*.gradle*
|
||||||
- name: Confirm that ~/.gradle/caches directory has been made
|
- name: Confirm that ~/.gradle/caches directory has been made
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
run: bash __tests__/check-dir.sh "$HOME/.gradle/caches"
|
||||||
- name: Confirm that the Gradle Wrapper cache has been restored
|
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.gradle/wrapper/dists"
|
|
||||||
gradle2-restore:
|
gradle2-restore:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -288,10 +270,7 @@ jobs:
|
|||||||
- name: Create files to cache
|
- name: Create files to cache
|
||||||
run: |
|
run: |
|
||||||
mvn verify -f __tests__/cache/maven/pom.xml
|
mvn verify -f __tests__/cache/maven/pom.xml
|
||||||
mkdir -p "$HOME/.m2/wrapper/dists/setup-java-e2e-maven1"
|
|
||||||
echo "maven wrapper cache maven1" > "$HOME/.m2/wrapper/dists/setup-java-e2e-maven1/payload"
|
|
||||||
bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
||||||
bash __tests__/check-dir.sh "$HOME/.m2/wrapper/dists"
|
|
||||||
maven1-restore:
|
maven1-restore:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -314,8 +293,6 @@ jobs:
|
|||||||
cache-dependency-path: __tests__/cache/maven/pom.xml
|
cache-dependency-path: __tests__/cache/maven/pom.xml
|
||||||
- name: Confirm that ~/.m2/repository directory has been made
|
- name: Confirm that ~/.m2/repository directory has been made
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
run: bash __tests__/check-dir.sh "$HOME/.m2/repository"
|
||||||
- name: Confirm that the Maven Wrapper cache has been restored
|
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.m2/wrapper/dists"
|
|
||||||
maven2-restore:
|
maven2-restore:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -335,9 +312,7 @@ jobs:
|
|||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
cache: maven
|
cache: maven
|
||||||
cache-dependency-path: |
|
cache-dependency-path: __tests__/cache/maven2/pom.xml
|
||||||
__tests__/cache/maven2/pom.xml
|
|
||||||
README.md
|
|
||||||
- name: Confirm that ~/.m2/repository directory has not been made
|
- name: Confirm that ~/.m2/repository directory has not been made
|
||||||
run: bash __tests__/check-dir.sh "$HOME/.m2/repository" absent
|
run: bash __tests__/check-dir.sh "$HOME/.m2/repository" absent
|
||||||
sbt1-save:
|
sbt1-save:
|
||||||
@@ -448,50 +423,3 @@ jobs:
|
|||||||
- name: Confirm that ~/.cache/coursier directory has not been made
|
- name: Confirm that ~/.cache/coursier directory has not been made
|
||||||
if: matrix.os == 'ubuntu-22.04'
|
if: matrix.os == 'ubuntu-22.04'
|
||||||
run: bash "$GITHUB_WORKSPACE/__tests__/check-dir.sh" "$HOME/.cache/coursier" absent
|
run: bash "$GITHUB_WORKSPACE/__tests__/check-dir.sh" "$HOME/.cache/coursier" absent
|
||||||
custom-maven-path-save:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Run setup-java with a custom Maven cache path
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
distribution: 'adopt'
|
|
||||||
java-version: '11'
|
|
||||||
cache: maven
|
|
||||||
cache-dependency-path: |
|
|
||||||
__tests__/cache/maven2/pom.xml
|
|
||||||
.github/workflows/e2e-cache.yml
|
|
||||||
cache-path: |
|
|
||||||
${{ runner.temp }}/setup-java-custom-maven-repository
|
|
||||||
!${{ runner.temp }}/setup-java-custom-maven-repository/**/*.lastUpdated
|
|
||||||
- name: Populate the custom Maven repository
|
|
||||||
run: |
|
|
||||||
mvn -Dmaven.repo.local="$RUNNER_TEMP/setup-java-custom-maven-repository" verify -f __tests__/cache/maven2/pom.xml
|
|
||||||
touch "$RUNNER_TEMP/setup-java-custom-maven-repository/setup-java-cache-path-marker"
|
|
||||||
bash __tests__/check-dir.sh "$RUNNER_TEMP/setup-java-custom-maven-repository"
|
|
||||||
custom-maven-path-restore:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: custom-maven-path-save
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Run setup-java with a custom Maven cache path
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
distribution: 'adopt'
|
|
||||||
java-version: '11'
|
|
||||||
cache: maven
|
|
||||||
cache-dependency-path: |
|
|
||||||
__tests__/cache/maven2/pom.xml
|
|
||||||
.github/workflows/e2e-cache.yml
|
|
||||||
cache-path: |
|
|
||||||
${{ runner.temp }}/setup-java-custom-maven-repository
|
|
||||||
!${{ runner.temp }}/setup-java-custom-maven-repository/**/*.lastUpdated
|
|
||||||
cache-read-only: true
|
|
||||||
- name: Confirm that the custom Maven repository has been restored
|
|
||||||
run: test -f "$RUNNER_TEMP/setup-java-custom-maven-repository/setup-java-cache-path-marker"
|
|
||||||
|
|||||||
87
.github/workflows/e2e-smoke.yml
vendored
87
.github/workflows/e2e-smoke.yml
vendored
@@ -1,87 +0,0 @@
|
|||||||
name: Validate Java e2e smoke
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
setup-java:
|
|
||||||
name: ${{ matrix.distribution }} ${{ matrix.version }} (${{ matrix.java-package }}) - ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- os: macos-latest
|
|
||||||
distribution: temurin
|
|
||||||
version: '11'
|
|
||||||
java-package: jdk
|
|
||||||
- os: windows-latest
|
|
||||||
distribution: temurin
|
|
||||||
version: '17'
|
|
||||||
java-package: jdk
|
|
||||||
- os: ubuntu-latest
|
|
||||||
distribution: temurin
|
|
||||||
version: '21'
|
|
||||||
java-package: jdk
|
|
||||||
- os: macos-latest
|
|
||||||
distribution: temurin
|
|
||||||
version: '25'
|
|
||||||
java-package: jdk
|
|
||||||
- os: windows-latest
|
|
||||||
distribution: temurin
|
|
||||||
version: '25'
|
|
||||||
java-package: jdk
|
|
||||||
- os: ubuntu-latest
|
|
||||||
distribution: temurin
|
|
||||||
version: '25'
|
|
||||||
java-package: jdk
|
|
||||||
- os: macos-latest
|
|
||||||
distribution: microsoft
|
|
||||||
version: '25'
|
|
||||||
java-package: jdk
|
|
||||||
- os: windows-latest
|
|
||||||
distribution: microsoft
|
|
||||||
version: '25'
|
|
||||||
java-package: jdk
|
|
||||||
- os: ubuntu-latest
|
|
||||||
distribution: microsoft
|
|
||||||
version: '25'
|
|
||||||
java-package: jdk
|
|
||||||
- os: ubuntu-latest
|
|
||||||
distribution: zulu
|
|
||||||
version: '17'
|
|
||||||
java-package: jre
|
|
||||||
- os: ubuntu-latest
|
|
||||||
distribution: liberica
|
|
||||||
version: '21'
|
|
||||||
java-package: jdk+fx
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v7
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: setup-java
|
|
||||||
uses: ./
|
|
||||||
id: setup-java
|
|
||||||
with:
|
|
||||||
java-version: ${{ matrix.version }}
|
|
||||||
java-package: ${{ matrix.java-package }}
|
|
||||||
distribution: ${{ matrix.distribution }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- name: Verify Java
|
|
||||||
env:
|
|
||||||
JAVA_VERSION: ${{ matrix.version }}
|
|
||||||
JAVA_PATH: ${{ steps.setup-java.outputs.path }}
|
|
||||||
run: bash __tests__/verify-java.sh "$JAVA_VERSION" "$JAVA_PATH"
|
|
||||||
shell: bash
|
|
||||||
51
.github/workflows/e2e-versions.yml
vendored
51
.github/workflows/e2e-versions.yml
vendored
@@ -3,9 +3,13 @@ name: Validate Java e2e
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
- main
|
||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 */12 * * *'
|
- cron: '0 */12 * * *'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -79,15 +83,6 @@ jobs:
|
|||||||
- distribution: oracle
|
- distribution: oracle
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
version: 21
|
version: 21
|
||||||
- distribution: oracle-openjdk
|
|
||||||
os: macos-15-intel
|
|
||||||
version: 21
|
|
||||||
- distribution: oracle-openjdk
|
|
||||||
os: windows-latest
|
|
||||||
version: 21
|
|
||||||
- distribution: oracle-openjdk
|
|
||||||
os: ubuntu-latest
|
|
||||||
version: 21
|
|
||||||
- distribution: graalvm
|
- distribution: graalvm
|
||||||
os: macos-latest
|
os: macos-latest
|
||||||
version: 17.0.12
|
version: 17.0.12
|
||||||
@@ -121,25 +116,6 @@ jobs:
|
|||||||
run: bash __tests__/verify-java.sh "$JAVA_VERSION" "$JAVA_PATH"
|
run: bash __tests__/verify-java.sh "$JAVA_VERSION" "$JAVA_PATH"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-java-checksum-verification:
|
|
||||||
name: Corretto checksum verification - ubuntu-latest
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- *checkout_step
|
|
||||||
- name: setup-java with forced download
|
|
||||||
uses: ./
|
|
||||||
id: setup-java
|
|
||||||
with:
|
|
||||||
java-version: '21'
|
|
||||||
distribution: corretto
|
|
||||||
force-download: true
|
|
||||||
- name: Verify Java
|
|
||||||
env:
|
|
||||||
JAVA_VERSION: '21'
|
|
||||||
JAVA_PATH: ${{ steps.setup-java.outputs.path }}
|
|
||||||
run: bash __tests__/verify-java.sh "$JAVA_VERSION" "$JAVA_PATH"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
setup-java-alpine-linux:
|
setup-java-alpine-linux:
|
||||||
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-${{ contains(matrix.os, 'macos') && !contains(matrix.os, 'intel') && 'arm64' || 'x64' }}) - alpine-linux - ${{ matrix.os }}
|
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-${{ contains(matrix.os, 'macos') && !contains(matrix.os, 'intel') && 'arm64' || 'x64' }}) - alpine-linux - ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -495,25 +471,6 @@ jobs:
|
|||||||
run: bash __tests__/verify-java.sh "$JAVA_VERSION" "$JAVA_PATH"
|
run: bash __tests__/verify-java.sh "$JAVA_VERSION" "$JAVA_PATH"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-java-unsupported-platform:
|
|
||||||
name: Reject unsupported Oracle x86 on Linux
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- *checkout_step
|
|
||||||
- name: Attempt unsupported setup
|
|
||||||
id: unsupported-setup
|
|
||||||
continue-on-error: true
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
distribution: oracle
|
|
||||||
java-version: '21'
|
|
||||||
architecture: x86
|
|
||||||
- name: Verify setup was rejected
|
|
||||||
if: always()
|
|
||||||
env:
|
|
||||||
SETUP_OUTCOME: ${{ steps.unsupported-setup.outcome }}
|
|
||||||
run: test "$SETUP_OUTCOME" = failure
|
|
||||||
|
|
||||||
setup-java-version-both-version-inputs-presents:
|
setup-java-version-both-version-inputs-presents:
|
||||||
name: ${{ matrix.distribution }} version (should be from input) - ${{ matrix.os }}
|
name: ${{ matrix.distribution }} version (should be from input) - ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|||||||
96
README.md
96
README.md
@@ -48,9 +48,9 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).
|
- `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).
|
||||||
|
|
||||||
- `java-package`: The packaging variant of the chosen distribution. Possible values across all distributions are `jdk`, `jre`, `jdk+fx`, `jre+fx`, `jdk+crac`, `jre+crac`, `jdk+jmods`, `jdk+jcef`, `jre+jcef`, `jdk+ft`, and `jre+ft`. Supported values vary by distribution; see the [package compatibility table](docs/advanced-usage.md#package-compatibility). Default value: `jdk`.
|
- `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. For Azul Zulu, `jdk+crac` and `jre+crac` are also supported. For Eclipse Temurin 24 and later, `jdk+jmods` includes the separately packaged JMOD files. Default value: `jdk`.
|
||||||
|
|
||||||
- `architecture`: The target architecture of the package. Canonical values are `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`, `ppc64`, and `s390x`; the aliases `ia32`, `amd64`, `arm`, and `arm64` normalize to `x86`, `x64`, `armv7`, and `aarch64`. Supported values vary by distribution and operating system. Default value: Derived from the runner machine.
|
- `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: Derived from the runner machine.
|
||||||
|
|
||||||
- `jdk-file`: 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. Note: `distribution` must be set to 'jdkfile' (case-sensitive; all lowercase) when using this option. (The camelCase `jdkFile` input is still accepted as a deprecated alias and may be removed in a future release.)
|
- `jdk-file`: 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. Note: `distribution` must be set to 'jdkfile' (case-sensitive; all lowercase) when using this option. (The camelCase `jdkFile` input is still accepted as a deprecated alias and may be removed in a future release.)
|
||||||
|
|
||||||
@@ -72,10 +72,6 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `cache-dependency-path`: The path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.
|
- `cache-dependency-path`: The path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.
|
||||||
|
|
||||||
- `cache-path`: The dependency cache path to use instead of the default path for the package manager selected by `cache`. This option supports a list of paths and exclusion patterns. The build tool must be configured to use the same location.
|
|
||||||
|
|
||||||
- `cache-read-only`: Restore dependency caches without saving changes in the post action. Defaults to `false`. Use this for pull requests, merge queues, short-lived branches, and fan-out jobs that should consume caches populated by a default-branch or seed job.
|
|
||||||
|
|
||||||
#### Maven options
|
#### 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.
|
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.
|
||||||
|
|
||||||
@@ -93,20 +89,12 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `gpg-passphrase-env-var`: Environment variable name for the GPG private key passphrase. Default is GPG\_PASSPHRASE.
|
- `gpg-passphrase-env-var`: 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. When supplied, the number of IDs must match the number of Java versions.
|
- `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.
|
- `mvn-toolchain-vendor`: Name of Maven Toolchain Vendor if the default name of `${distribution}` is not wanted.
|
||||||
|
|
||||||
- `show-download-progress`: Set to `true` to keep Maven artifact download and transfer progress in build logs. Default value: `false`. By default, the action adds `-ntp` (`--no-transfer-progress`) to `MAVEN_ARGS`. This input has no effect on non-Maven builds. See [Maven transfer progress](docs/advanced-usage.md#maven-transfer-progress-download-logs) for more details.
|
- `show-download-progress`: Set to `true` to keep Maven artifact download and transfer progress in build logs. Default value: `false`. By default, the action adds `-ntp` (`--no-transfer-progress`) to `MAVEN_ARGS`. This input has no effect on non-Maven builds. See [Maven transfer progress](docs/advanced-usage.md#maven-transfer-progress-download-logs) for more details.
|
||||||
|
|
||||||
### Download integrity verification
|
|
||||||
|
|
||||||
When a selected distribution publishes an authoritative checksum for an archive, `setup-java` automatically verifies each downloaded JDK, JRE, or JMOD archive before extraction and caching. No input is required. Automatic checksum verification is currently available for `temurin`, `semeru`, `adopt`, `corretto`, `dragonwell`, `kona`, `sapmachine`, `graalvm`, `graalvm-community`, `zulu`, `oracle`, `oracle-openjdk`, `microsoft`, and `jetbrains`.
|
|
||||||
|
|
||||||
Distributions or individual releases without an authoritative checksum continue to install normally, with the omission reported only in debug logs. Archives resolved directly from the runner tool cache are not downloaded again and therefore are not reverified.
|
|
||||||
|
|
||||||
Checksums detect corrupted or unexpectedly modified downloads before they are persisted in the runner tool cache.
|
|
||||||
|
|
||||||
### Basic Configuration
|
### Basic Configuration
|
||||||
|
|
||||||
#### Eclipse Temurin
|
#### Eclipse Temurin
|
||||||
@@ -190,88 +178,12 @@ The action has a built-in functionality for caching and restoring dependencies.
|
|||||||
|
|
||||||
When the option `cache-dependency-path` is specified, the hash is based on the matching file. This option supports wildcards and a list of file names, and is especially useful for monorepos.
|
When the option `cache-dependency-path` is specified, the hash is based on the matching file. This option supports wildcards and a list of file names, and is especially useful for monorepos.
|
||||||
|
|
||||||
Use `cache-path` to replace the selected package manager's default dependency
|
|
||||||
cache paths. Each non-empty line is passed to `actions/cache`, including
|
|
||||||
supported exclusion patterns. `setup-java` does not configure the build tool,
|
|
||||||
so the build must use the same paths:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: actions/setup-java@v6
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '25'
|
|
||||||
cache: 'maven'
|
|
||||||
cache-path: |
|
|
||||||
/custom/maven/repository
|
|
||||||
!/custom/maven/repository/**/*.lastUpdated
|
|
||||||
- run: mvn -Dmaven.repo.local=/custom/maven/repository verify
|
|
||||||
```
|
|
||||||
|
|
||||||
`cache-path` does not change the cache key. The key continues to use the runner
|
|
||||||
OS, architecture, selected package manager, and dependency-file hash described
|
|
||||||
above. Jobs intended to share a cache key must therefore use the same
|
|
||||||
`cache-path` values so that they restore and save the same filesystem
|
|
||||||
locations.
|
|
||||||
|
|
||||||
The Maven and Gradle wrapper caches remain at their documented default paths
|
|
||||||
and are managed independently of `cache-path`. For advanced keying, fallback
|
|
||||||
keys, or cache topologies that do not map to one package manager's dependency
|
|
||||||
paths, use [`actions/cache`](https://github.com/actions/cache) directly.
|
|
||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
The workflow output `cache-primary-key` exposes the primary cache key computed by the action for the configured build tool. It is useful for composing with [`actions/cache`](https://github.com/actions/cache) or [`actions/cache/restore`](https://github.com/actions/cache/tree/main/restore) in later steps or dependent jobs that need to reuse the exact same key. It is empty when caching is not enabled or when caching is skipped (for example, when the cache service is unavailable).
|
The workflow output `cache-primary-key` exposes the primary cache key computed by the action for the configured build tool. It is useful for composing with [`actions/cache`](https://github.com/actions/cache) or [`actions/cache/restore`](https://github.com/actions/cache/tree/main/restore) in later steps or dependent jobs that need to reuse the exact same key. It is empty when caching is not enabled or when caching is skipped (for example, when the cache service is unavailable).
|
||||||
|
|
||||||
The cache input is optional, and caching is turned off by default.
|
The cache input is optional, and caching is turned off by default.
|
||||||
|
|
||||||
Set `cache-read-only: true` to restore the main dependency cache and any Maven
|
|
||||||
or Gradle wrapper cache without archiving or uploading changes after the job.
|
|
||||||
For example, a workflow can allow only the default branch to write caches while
|
|
||||||
pull requests, merge queues, and short-lived branches remain read-only:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: actions/setup-java@v6
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '25'
|
|
||||||
cache: 'maven'
|
|
||||||
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
|
|
||||||
```
|
|
||||||
|
|
||||||
For a fan-out matrix, use one seed job to populate a complete cache and make
|
|
||||||
every matrix job a read-only consumer. The seed and consumers must use the same
|
|
||||||
runner OS and cache dependency inputs so they compute the same key:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
seed-cache:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v7
|
|
||||||
- uses: actions/setup-java@v6
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '25'
|
|
||||||
cache: 'maven'
|
|
||||||
- run: mvn dependency:go-offline dependency:resolve-plugins
|
|
||||||
|
|
||||||
build:
|
|
||||||
needs: seed-cache
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
goal: [test, verify, package]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v7
|
|
||||||
- uses: actions/setup-java@v6
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '25'
|
|
||||||
cache: 'maven'
|
|
||||||
cache-read-only: true
|
|
||||||
- run: mvn ${{ matrix.goal }}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Maven Wrapper:** when `cache: 'maven'` is enabled, the action also caches and restores the Maven Wrapper distribution downloaded to `~/.m2/wrapper/dists` (in addition to the local repository), so wrapper-based (`./mvnw`) builds don't re-download the Maven distribution. The wrapper distribution is stored in a **separate** cache entry keyed only on `**/.mvn/wrapper/maven-wrapper.properties`, so it stays cached across the frequent `pom.xml` changes that rotate the main dependency cache key.
|
**Maven Wrapper:** when `cache: 'maven'` is enabled, the action also caches and restores the Maven Wrapper distribution downloaded to `~/.m2/wrapper/dists` (in addition to the local repository), so wrapper-based (`./mvnw`) builds don't re-download the Maven distribution. The wrapper distribution is stored in a **separate** cache entry keyed only on `**/.mvn/wrapper/maven-wrapper.properties`, so it stays cached across the frequent `pom.xml` changes that rotate the main dependency cache key.
|
||||||
|
|
||||||
#### Caching gradle dependencies
|
#### Caching gradle dependencies
|
||||||
@@ -355,8 +267,6 @@ In the basic examples above, the `check-latest` flag defaults to `false`. When s
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
[GitHub-hosted runners](https://github.com/actions/runner-images) include Eclipse Temurin JDKs in their tool cache. Selecting Eclipse Temurin (`distribution: 'temurin'`) can save setup time by using a pre-installed JDK instead of downloading one. See the installed Java versions for [Ubuntu](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md#java), [Windows](https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md#java), and [macOS](https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md#java).
|
|
||||||
|
|
||||||
For Java distributions that are not cached on Hosted images, `check-latest` always behaves as `true` and downloads Java on the fly. Check out [Hosted Tool Cache](docs/advanced-usage.md#Hosted-Tool-Cache) for more details about pre-cached Java versions.
|
For Java distributions that are not cached on Hosted images, `check-latest` always behaves as `true` and downloads Java on the fly. Check out [Hosted Tool Cache](docs/advanced-usage.md#Hosted-Tool-Cache) for more details about pre-cached Java versions.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
command=${1:?command is required}
|
|
||||||
tool=${2:?tool is required}
|
|
||||||
|
|
||||||
case "$tool" in
|
|
||||||
maven)
|
|
||||||
dependency_cache="$HOME/.m2/repository"
|
|
||||||
wrapper_cache="$HOME/.m2/wrapper/dists"
|
|
||||||
dependency_file="benchmark/pom.xml"
|
|
||||||
wrapper_file="benchmark/.mvn/wrapper/maven-wrapper.properties"
|
|
||||||
;;
|
|
||||||
gradle)
|
|
||||||
dependency_cache="$HOME/.gradle/caches"
|
|
||||||
wrapper_cache="$HOME/.gradle/wrapper"
|
|
||||||
dependency_file="benchmark/build.gradle"
|
|
||||||
wrapper_file="benchmark/gradle/wrapper/gradle-wrapper.properties"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unsupported tool: $tool" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case "$command" in
|
|
||||||
prepare)
|
|
||||||
profile=${3:?profile is required}
|
|
||||||
mkdir -p "$(dirname "$dependency_file")" "$(dirname "$wrapper_file")"
|
|
||||||
printf '// setup-java cache benchmark v1: %s\n' "$profile" > "$dependency_file"
|
|
||||||
printf '# setup-java cache benchmark v1: %s\n' "$profile" > "$wrapper_file"
|
|
||||||
;;
|
|
||||||
reset)
|
|
||||||
rm -rf "$dependency_cache" "$wrapper_cache"
|
|
||||||
;;
|
|
||||||
populate)
|
|
||||||
profile=${3:?profile is required}
|
|
||||||
case "$profile" in
|
|
||||||
small)
|
|
||||||
dependency_megabytes=8
|
|
||||||
wrapper_megabytes=2
|
|
||||||
;;
|
|
||||||
large)
|
|
||||||
dependency_megabytes=128
|
|
||||||
wrapper_megabytes=32
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unsupported profile: $profile" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
mkdir -p "$dependency_cache/setup-java-benchmark"
|
|
||||||
mkdir -p "$wrapper_cache/setup-java-benchmark"
|
|
||||||
dd if=/dev/urandom \
|
|
||||||
of="$dependency_cache/setup-java-benchmark/payload" \
|
|
||||||
bs=1048576 count="$dependency_megabytes" 2>/dev/null
|
|
||||||
dd if=/dev/urandom \
|
|
||||||
of="$wrapper_cache/setup-java-benchmark/payload" \
|
|
||||||
bs=1048576 count="$wrapper_megabytes" 2>/dev/null
|
|
||||||
;;
|
|
||||||
start)
|
|
||||||
node -e "require('fs').writeFileSync('.benchmark-start', String(Date.now()))"
|
|
||||||
;;
|
|
||||||
record)
|
|
||||||
os=${3:?os is required}
|
|
||||||
profile=${4:?profile is required}
|
|
||||||
implementation=${5:?implementation is required}
|
|
||||||
iteration=${6:?iteration is required}
|
|
||||||
cache_hit=${7:?cache-hit output is required}
|
|
||||||
if [ "$cache_hit" != "true" ]; then
|
|
||||||
echo "Expected an exact dependency-cache hit for $implementation" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
test -f "$dependency_cache/setup-java-benchmark/payload"
|
|
||||||
started=$(cat .benchmark-start)
|
|
||||||
finished=$(node -e "process.stdout.write(String(Date.now()))")
|
|
||||||
elapsed=$((finished - started))
|
|
||||||
mkdir -p .benchmark-results
|
|
||||||
printf '%s,%s,%s,%s,%s,%s\n' \
|
|
||||||
"$os" "$tool" "$profile" "$implementation" "$iteration" "$elapsed" \
|
|
||||||
>> .benchmark-results/timings.csv
|
|
||||||
;;
|
|
||||||
summarize)
|
|
||||||
summary_file=${3:?summary file is required}
|
|
||||||
results_file=".benchmark-results/timings.csv"
|
|
||||||
node --input-type=module - "$results_file" "$summary_file" <<'NODE'
|
|
||||||
import fs from 'node:fs';
|
|
||||||
|
|
||||||
const [, , resultsFile, summaryFile] = process.argv;
|
|
||||||
const rows = fs
|
|
||||||
.readFileSync(resultsFile, 'utf8')
|
|
||||||
.trim()
|
|
||||||
.split('\n')
|
|
||||||
.map(line => {
|
|
||||||
const [os, tool, profile, implementation, iteration, elapsed] =
|
|
||||||
line.split(',');
|
|
||||||
return {os, tool, profile, implementation, iteration, elapsed: +elapsed};
|
|
||||||
});
|
|
||||||
const average = implementation => {
|
|
||||||
const values = rows
|
|
||||||
.filter(row => row.implementation === implementation)
|
|
||||||
.map(row => row.elapsed);
|
|
||||||
if (values.length === 0) {
|
|
||||||
throw new Error(`No ${implementation} benchmark results were recorded`);
|
|
||||||
}
|
|
||||||
return Math.round(values.reduce((sum, value) => sum + value, 0) / values.length);
|
|
||||||
};
|
|
||||||
const baseline = average('baseline');
|
|
||||||
const candidate = average('candidate');
|
|
||||||
const change = (((candidate - baseline) / baseline) * 100).toFixed(1);
|
|
||||||
const {os, tool, profile} = rows[0];
|
|
||||||
const lines = [
|
|
||||||
`### ${tool} ${profile} cache restore on ${os}`,
|
|
||||||
'',
|
|
||||||
'| Implementation | Iteration | Wall time (ms) |',
|
|
||||||
'| --- | ---: | ---: |',
|
|
||||||
...rows.map(
|
|
||||||
row =>
|
|
||||||
`| ${row.implementation} | ${row.iteration} | ${row.elapsed} |`
|
|
||||||
),
|
|
||||||
`| **baseline average** | | **${baseline}** |`,
|
|
||||||
`| **candidate average** | | **${candidate}** |`,
|
|
||||||
'',
|
|
||||||
`Candidate change from baseline: **${change}%**`,
|
|
||||||
''
|
|
||||||
];
|
|
||||||
fs.appendFileSync(summaryFile, `${lines.join('\n')}\n`);
|
|
||||||
NODE
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unsupported command: $command" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
@@ -224,10 +224,10 @@ describe('dependency cache', () => {
|
|||||||
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
|
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
|
||||||
);
|
);
|
||||||
|
|
||||||
await restore('maven', '', ['/custom/maven/repository']);
|
await restore('maven', '');
|
||||||
// Main dependency cache no longer carries the wrapper dists path.
|
// Main dependency cache no longer carries the wrapper dists path.
|
||||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||||
['/custom/maven/repository'],
|
[join(os.homedir(), '.m2', 'repository')],
|
||||||
expect.any(String)
|
expect.any(String)
|
||||||
);
|
);
|
||||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||||
@@ -237,83 +237,6 @@ describe('dependency cache', () => {
|
|||||||
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
expect(spyGlobHashFiles).toHaveBeenCalledWith(
|
||||||
'**/.mvn/wrapper/maven-wrapper.properties'
|
'**/.mvn/wrapper/maven-wrapper.properties'
|
||||||
);
|
);
|
||||||
expect(spyInfo).toHaveBeenCalledWith(
|
|
||||||
'maven-wrapper cache is not found'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('starts maven dependency and wrapper restores before either completes', async () => {
|
|
||||||
createDirectory(join(workspace, '.mvn'));
|
|
||||||
createDirectory(join(workspace, '.mvn', 'wrapper'));
|
|
||||||
createFile(
|
|
||||||
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
|
|
||||||
);
|
|
||||||
const dependencyRestore = deferred<string | undefined>();
|
|
||||||
const wrapperRestore = deferred<string | undefined>();
|
|
||||||
const bothRestoresStarted = deferred<void>();
|
|
||||||
let restoreCount = 0;
|
|
||||||
spyCacheRestore.mockImplementation((paths: string[]) => {
|
|
||||||
restoreCount++;
|
|
||||||
if (restoreCount === 2) {
|
|
||||||
bothRestoresStarted.resolve();
|
|
||||||
}
|
|
||||||
return paths.includes(join(os.homedir(), '.m2', 'repository'))
|
|
||||||
? dependencyRestore.promise
|
|
||||||
: wrapperRestore.promise;
|
|
||||||
});
|
|
||||||
|
|
||||||
const restorePromise = restore('maven', '');
|
|
||||||
await bothRestoresStarted.promise;
|
|
||||||
|
|
||||||
expect(spyCacheRestore).toHaveBeenCalledTimes(2);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-primary-key',
|
|
||||||
expect.any(String)
|
|
||||||
);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-primary-key-maven-wrapper',
|
|
||||||
expect.any(String)
|
|
||||||
);
|
|
||||||
|
|
||||||
wrapperRestore.resolve('maven-wrapper-hit');
|
|
||||||
dependencyRestore.resolve('maven-dependency-hit');
|
|
||||||
await restorePromise;
|
|
||||||
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-matched-key-maven-wrapper',
|
|
||||||
'maven-wrapper-hit'
|
|
||||||
);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-matched-key',
|
|
||||||
'maven-dependency-hit'
|
|
||||||
);
|
|
||||||
expect(spySetOutput).toHaveBeenCalledWith('cache-hit', false);
|
|
||||||
});
|
|
||||||
it('propagates a wrapper restore failure after starting both restores', async () => {
|
|
||||||
createDirectory(join(workspace, '.mvn'));
|
|
||||||
createDirectory(join(workspace, '.mvn', 'wrapper'));
|
|
||||||
createFile(
|
|
||||||
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
|
|
||||||
);
|
|
||||||
const dependencyRestore = deferred<string | undefined>();
|
|
||||||
const wrapperRestore = deferred<string | undefined>();
|
|
||||||
const bothRestoresStarted = deferred<void>();
|
|
||||||
let restoreCount = 0;
|
|
||||||
spyCacheRestore.mockImplementation((paths: string[]) => {
|
|
||||||
restoreCount++;
|
|
||||||
if (restoreCount === 2) {
|
|
||||||
bothRestoresStarted.resolve();
|
|
||||||
}
|
|
||||||
return paths.includes(join(os.homedir(), '.m2', 'repository'))
|
|
||||||
? dependencyRestore.promise
|
|
||||||
: wrapperRestore.promise;
|
|
||||||
});
|
|
||||||
|
|
||||||
const restorePromise = restore('maven', '');
|
|
||||||
await bothRestoresStarted.promise;
|
|
||||||
wrapperRestore.reject(new Error('wrapper restore failed'));
|
|
||||||
dependencyRestore.resolve(undefined);
|
|
||||||
|
|
||||||
await expect(restorePromise).rejects.toThrow('wrapper restore failed');
|
|
||||||
});
|
});
|
||||||
it('skips the maven wrapper cache when no wrapper properties exist', async () => {
|
it('skips the maven wrapper cache when no wrapper properties exist', async () => {
|
||||||
createFile(join(workspace, 'pom.xml'));
|
createFile(join(workspace, 'pom.xml'));
|
||||||
@@ -394,10 +317,10 @@ describe('dependency cache', () => {
|
|||||||
it('restores the gradle wrapper distribution cache independently of the main cache', async () => {
|
it('restores the gradle wrapper distribution cache independently of the main cache', async () => {
|
||||||
createFile(join(workspace, 'build.gradle'));
|
createFile(join(workspace, 'build.gradle'));
|
||||||
|
|
||||||
await restore('gradle', '', ['/custom/gradle/caches']);
|
await restore('gradle', '');
|
||||||
// Main dependency cache no longer carries the wrapper path.
|
// Main dependency cache no longer carries the wrapper path.
|
||||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
expect(spyCacheRestore).toHaveBeenCalledWith(
|
||||||
['/custom/gradle/caches'],
|
[join(os.homedir(), '.gradle', 'caches')],
|
||||||
expect.any(String)
|
expect.any(String)
|
||||||
);
|
);
|
||||||
// Wrapper distribution is restored on its own, keyed only on the
|
// Wrapper distribution is restored on its own, keyed only on the
|
||||||
@@ -410,50 +333,6 @@ describe('dependency cache', () => {
|
|||||||
'**/gradle-wrapper.properties'
|
'**/gradle-wrapper.properties'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('starts gradle dependency and wrapper restores before either completes', async () => {
|
|
||||||
createFile(join(workspace, 'build.gradle'));
|
|
||||||
createFile(join(workspace, 'gradle-wrapper.properties'));
|
|
||||||
const dependencyRestore = deferred<string | undefined>();
|
|
||||||
const wrapperRestore = deferred<string | undefined>();
|
|
||||||
const bothRestoresStarted = deferred<void>();
|
|
||||||
let restoreCount = 0;
|
|
||||||
spyCacheRestore.mockImplementation((paths: string[]) => {
|
|
||||||
restoreCount++;
|
|
||||||
if (restoreCount === 2) {
|
|
||||||
bothRestoresStarted.resolve();
|
|
||||||
}
|
|
||||||
return paths.includes(join(os.homedir(), '.gradle', 'caches'))
|
|
||||||
? dependencyRestore.promise
|
|
||||||
: wrapperRestore.promise;
|
|
||||||
});
|
|
||||||
|
|
||||||
const restorePromise = restore('gradle', '');
|
|
||||||
await bothRestoresStarted.promise;
|
|
||||||
|
|
||||||
expect(spyCacheRestore).toHaveBeenCalledTimes(2);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-primary-key',
|
|
||||||
expect.any(String)
|
|
||||||
);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-primary-key-gradle-wrapper',
|
|
||||||
expect.any(String)
|
|
||||||
);
|
|
||||||
|
|
||||||
dependencyRestore.resolve('gradle-dependency-hit');
|
|
||||||
wrapperRestore.resolve('gradle-wrapper-hit');
|
|
||||||
await restorePromise;
|
|
||||||
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-matched-key',
|
|
||||||
'gradle-dependency-hit'
|
|
||||||
);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-matched-key-gradle-wrapper',
|
|
||||||
'gradle-wrapper-hit'
|
|
||||||
);
|
|
||||||
expect(spySetOutput).toHaveBeenCalledWith('cache-hit', false);
|
|
||||||
});
|
|
||||||
it('skips the gradle wrapper cache when no wrapper properties exist', async () => {
|
it('skips the gradle wrapper cache when no wrapper properties exist', async () => {
|
||||||
createFile(join(workspace, 'build.gradle'));
|
createFile(join(workspace, 'build.gradle'));
|
||||||
spyGlobHashFiles.mockImplementation((pattern: string) =>
|
spyGlobHashFiles.mockImplementation((pattern: string) =>
|
||||||
@@ -576,34 +455,6 @@ describe('dependency cache', () => {
|
|||||||
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found');
|
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('cache-path', () => {
|
|
||||||
it.each([
|
|
||||||
['maven', ['/custom/maven/repository']],
|
|
||||||
['gradle', ['/custom/gradle/caches']],
|
|
||||||
[
|
|
||||||
'sbt',
|
|
||||||
[
|
|
||||||
'/custom/ivy/cache',
|
|
||||||
'/custom/coursier/cache',
|
|
||||||
'!/custom/ivy/cache/*.lock'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
])(
|
|
||||||
'restores and persists custom paths for %s',
|
|
||||||
async (packageManager, cachePaths) => {
|
|
||||||
await restore(packageManager, '', cachePaths);
|
|
||||||
|
|
||||||
expect(spyCacheRestore).toHaveBeenCalledWith(
|
|
||||||
cachePaths,
|
|
||||||
expect.any(String)
|
|
||||||
);
|
|
||||||
expect(spySaveState).toHaveBeenCalledWith(
|
|
||||||
'cache-paths',
|
|
||||||
JSON.stringify(cachePaths)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('save', () => {
|
describe('save', () => {
|
||||||
let spyCacheSave: any;
|
let spyCacheSave: any;
|
||||||
@@ -653,42 +504,6 @@ describe('dependency cache', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
|
||||||
['maven', ['/custom/maven/repository']],
|
|
||||||
['gradle', ['/custom/gradle/caches']],
|
|
||||||
[
|
|
||||||
'sbt',
|
|
||||||
[
|
|
||||||
'/custom/ivy/cache',
|
|
||||||
'/custom/coursier/cache',
|
|
||||||
'!/custom/ivy/cache/*.lock'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
])(
|
|
||||||
'saves the persisted custom paths for %s',
|
|
||||||
async (packageManager, cachePaths) => {
|
|
||||||
(core.getState as jest.Mock<any>).mockImplementation((name: any) => {
|
|
||||||
switch (name) {
|
|
||||||
case 'cache-primary-key':
|
|
||||||
return 'setup-java-cache-primary-key';
|
|
||||||
case 'cache-matched-key':
|
|
||||||
return 'setup-java-cache-matched-key';
|
|
||||||
case 'cache-paths':
|
|
||||||
return JSON.stringify(cachePaths);
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await save(packageManager);
|
|
||||||
|
|
||||||
expect(spyCacheSave).toHaveBeenCalledWith(
|
|
||||||
cachePaths,
|
|
||||||
'setup-java-cache-primary-key'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
describe('for maven', () => {
|
describe('for maven', () => {
|
||||||
it('uploads cache even if no pom.xml found', async () => {
|
it('uploads cache even if no pom.xml found', async () => {
|
||||||
createStateForMissingBuildFile();
|
createStateForMissingBuildFile();
|
||||||
@@ -794,36 +609,6 @@ describe('dependency cache', () => {
|
|||||||
);
|
);
|
||||||
expect(spyWarning).not.toHaveBeenCalled();
|
expect(spyWarning).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('continues with primary cache save when additional cache save fails unexpectedly', async () => {
|
|
||||||
createFile(join(workspace, 'pom.xml'));
|
|
||||||
(core.getState as jest.Mock<any>).mockImplementation((name: any) => {
|
|
||||||
switch (name) {
|
|
||||||
case 'cache-primary-key':
|
|
||||||
return 'setup-java-cache-primary-key';
|
|
||||||
case 'cache-matched-key':
|
|
||||||
return 'setup-java-cache-matched-key';
|
|
||||||
case 'cache-primary-key-maven-wrapper':
|
|
||||||
return 'setup-java-maven-wrapper-key';
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
spyCacheSave.mockImplementation((paths: string[], key: string) => {
|
|
||||||
if (paths[0] === 'wrapper-path') {
|
|
||||||
return Promise.reject(new Error('wrapper save exploded'));
|
|
||||||
}
|
|
||||||
return Promise.resolve(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(save('maven')).resolves.toBeUndefined();
|
|
||||||
expect(spyWarning).toHaveBeenCalledWith(
|
|
||||||
'Failed to save maven-wrapper cache: wrapper save exploded. Continuing with primary cache save.'
|
|
||||||
);
|
|
||||||
expect(spyCacheSave).toHaveBeenCalledWith(
|
|
||||||
[join(os.homedir(), '.m2', 'repository')],
|
|
||||||
'setup-java-cache-primary-key'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('for gradle', () => {
|
describe('for gradle', () => {
|
||||||
it('uploads cache even if no build.gradle found', async () => {
|
it('uploads cache even if no build.gradle found', async () => {
|
||||||
@@ -1032,16 +817,6 @@ function createFile(path: string) {
|
|||||||
fs.writeFileSync(path, '');
|
fs.writeFileSync(path, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function deferred<T>() {
|
|
||||||
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
||||||
let reject!: (reason?: unknown) => void;
|
|
||||||
const promise = new Promise<T>((promiseResolve, promiseReject) => {
|
|
||||||
resolve = promiseResolve;
|
|
||||||
reject = promiseReject;
|
|
||||||
});
|
|
||||||
return {promise, resolve, reject};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createDirectory(path: string) {
|
function createDirectory(path: string) {
|
||||||
core.info(`created a directory at ${path}`);
|
core.info(`created a directory at ${path}`);
|
||||||
fs.mkdirSync(path);
|
fs.mkdirSync(path);
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
import {afterEach, describe, expect, it, jest} from '@jest/globals';
|
|
||||||
import {createHash} from 'crypto';
|
|
||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
import {calculateChecksum, verifyChecksum} from '../src/checksum.js';
|
|
||||||
import type {ChecksumMetadata} from '../src/distributions/base-models.js';
|
|
||||||
|
|
||||||
const temporaryPaths: string[] = [];
|
|
||||||
|
|
||||||
async function temporaryFile(contents: string): Promise<string> {
|
|
||||||
const directory = await fs.promises.mkdtemp(
|
|
||||||
path.join(os.tmpdir(), 'setup-java-checksum-')
|
|
||||||
);
|
|
||||||
const file = path.join(directory, 'archive');
|
|
||||||
await fs.promises.writeFile(file, contents);
|
|
||||||
temporaryPaths.push(directory);
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await Promise.all(
|
|
||||||
temporaryPaths
|
|
||||||
.splice(0)
|
|
||||||
.map(item => fs.promises.rm(item, {recursive: true, force: true}))
|
|
||||||
);
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('verifyChecksum', () => {
|
|
||||||
it.each(['sha256', 'sha512'] as const)(
|
|
||||||
'verifies a matching %s digest',
|
|
||||||
async algorithm => {
|
|
||||||
const contents = `jdk archive for ${algorithm}`;
|
|
||||||
const file = await temporaryFile(contents);
|
|
||||||
const value = createHash(algorithm).update(contents).digest('hex');
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
verifyChecksum(
|
|
||||||
file,
|
|
||||||
{algorithm, value: value.toUpperCase()},
|
|
||||||
{distribution: 'Test', version: '21.0.1'}
|
|
||||||
)
|
|
||||||
).resolves.toBeUndefined();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('reports mismatch context and both digests', async () => {
|
|
||||||
const file = await temporaryFile('corrupt archive');
|
|
||||||
const expected = 'a'.repeat(64);
|
|
||||||
const actual = await calculateChecksum(file, 'sha256');
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
verifyChecksum(
|
|
||||||
file,
|
|
||||||
{algorithm: 'sha256', value: expected},
|
|
||||||
{distribution: 'Corretto', version: '21.0.8'}
|
|
||||||
)
|
|
||||||
).rejects.toThrow(
|
|
||||||
`Checksum verification failed for Corretto version 21.0.8: sha256 expected ${expected}, actual ${actual}.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects malformed digest metadata before reading the file', async () => {
|
|
||||||
await expect(
|
|
||||||
verifyChecksum(
|
|
||||||
'/missing/archive',
|
|
||||||
{algorithm: 'sha512', value: 'not-a-digest'},
|
|
||||||
{distribution: 'Test', version: '17'}
|
|
||||||
)
|
|
||||||
).rejects.toThrow(
|
|
||||||
'Malformed sha512 checksum metadata: expected a 128-character hexadecimal digest.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([undefined, null, 123])(
|
|
||||||
'reports a malformed digest when the value is %p',
|
|
||||||
async value => {
|
|
||||||
const checksum = {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value
|
|
||||||
} as unknown as ChecksumMetadata;
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
verifyChecksum('/missing/archive', checksum, {
|
|
||||||
distribution: 'Test',
|
|
||||||
version: '17'
|
|
||||||
})
|
|
||||||
).rejects.toThrow(
|
|
||||||
'Malformed sha256 checksum metadata: expected a 64-character hexadecimal digest.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('rejects unsupported algorithms without leaking source query parameters', async () => {
|
|
||||||
const checksum = {
|
|
||||||
algorithm: 'md5',
|
|
||||||
value: 'a'.repeat(32),
|
|
||||||
source: 'https://vendor.example/checksum.txt?token=secret-value#private'
|
|
||||||
} as unknown as ChecksumMetadata;
|
|
||||||
|
|
||||||
let message = '';
|
|
||||||
try {
|
|
||||||
await verifyChecksum('/missing/archive', checksum, {
|
|
||||||
distribution: 'Test',
|
|
||||||
version: '17'
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
message = (error as Error).message;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(message).toContain(
|
|
||||||
"Unsupported checksum algorithm 'md5' from https://vendor.example/checksum.txt"
|
|
||||||
);
|
|
||||||
expect(message).not.toContain('secret-value');
|
|
||||||
expect(message).not.toContain('token=');
|
|
||||||
expect(message).not.toContain('#private');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('surfaces file read errors', async () => {
|
|
||||||
await expect(
|
|
||||||
verifyChecksum(
|
|
||||||
'/missing/archive',
|
|
||||||
{algorithm: 'sha256', value: 'a'.repeat(64)},
|
|
||||||
{distribution: 'Test', version: '17'}
|
|
||||||
)
|
|
||||||
).rejects.toMatchObject({code: 'ENOENT'});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -120,49 +120,6 @@ describe('cleanup', () => {
|
|||||||
await cleanup();
|
await cleanup();
|
||||||
expect(spyCacheSave).toHaveBeenCalled();
|
expect(spyCacheSave).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['maven', 'gradle', 'sbt'])(
|
|
||||||
'does not save the %s cache in read-only mode',
|
|
||||||
async packageManager => {
|
|
||||||
createStateForSuccessfulRestoreWithWrapper(packageManager);
|
|
||||||
(core.getInput as jest.Mock<any>).mockImplementation((name: string) => {
|
|
||||||
switch (name) {
|
|
||||||
case 'cache':
|
|
||||||
return packageManager;
|
|
||||||
case 'cache-read-only':
|
|
||||||
return 'true';
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await cleanup();
|
|
||||||
|
|
||||||
expect(spyCacheSave).not.toHaveBeenCalled();
|
|
||||||
expect(core.getState).not.toHaveBeenCalled();
|
|
||||||
expect(spyInfo).toHaveBeenCalledWith(
|
|
||||||
'Cache saving is skipped because cache-read-only is enabled.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('saves the cache when read-only mode is explicitly disabled', async () => {
|
|
||||||
spyCacheSave.mockResolvedValue(0);
|
|
||||||
(core.getInput as jest.Mock<any>).mockImplementation((name: string) => {
|
|
||||||
switch (name) {
|
|
||||||
case 'cache':
|
|
||||||
return 'maven';
|
|
||||||
case 'cache-read-only':
|
|
||||||
return 'false';
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await cleanup();
|
|
||||||
|
|
||||||
expect(spyCacheSave).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function resetState() {
|
function resetState() {
|
||||||
@@ -184,18 +141,3 @@ function createStateForSuccessfulRestore() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStateForSuccessfulRestoreWithWrapper(packageManager: string) {
|
|
||||||
(core.getState as jest.Mock<any>).mockImplementation((name: any) => {
|
|
||||||
switch (name) {
|
|
||||||
case 'cache-primary-key':
|
|
||||||
return 'setup-java-cache-primary-key';
|
|
||||||
case 'cache-matched-key':
|
|
||||||
return 'setup-java-cache-matched-key';
|
|
||||||
case `cache-primary-key-${packageManager}-wrapper`:
|
|
||||||
return `setup-java-${packageManager}-wrapper-primary-key`;
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -260,7 +260,6 @@ describe('getAvailableVersions', () => {
|
|||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['amd64', 'x64'],
|
['amd64', 'x64'],
|
||||||
['arm', 'arm'],
|
|
||||||
['arm64', 'aarch64']
|
['arm64', 'aarch64']
|
||||||
])(
|
])(
|
||||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||||
@@ -358,14 +357,6 @@ describe('findPackageForDownload', () => {
|
|||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||||
expect(resolvedVersion.version).toBe(expected);
|
expect(resolvedVersion.version).toBe(expected);
|
||||||
const vendorPackage = (manifestData as any[]).find(
|
|
||||||
item => item.version_data.semver === expected
|
|
||||||
).binaries[0].package;
|
|
||||||
expect(resolvedVersion.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: vendorPackage.checksum,
|
|
||||||
source: vendorPackage.checksum_link
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('version is found but binaries list is empty', async () => {
|
it('version is found but binaries list is empty', async () => {
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ import type {
|
|||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import fs from 'fs';
|
|
||||||
import {createHash} from 'crypto';
|
|
||||||
import {HttpClient} from '@actions/http-client';
|
|
||||||
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
@@ -120,17 +117,6 @@ class EmptyJavaBase extends JavaBase {
|
|||||||
url: `some/random_url/java/${availableVersion}`
|
url: `some/random_url/java/${availableVersion}`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public downloadRelease(javaRelease: JavaDownloadRelease): Promise<string> {
|
|
||||||
return this.downloadAndVerify(javaRelease);
|
|
||||||
}
|
|
||||||
|
|
||||||
public fetchChecksumForTest(
|
|
||||||
checksumUrl: string,
|
|
||||||
algorithm: 'sha256' | 'sha512' | ('sha256' | 'sha512')[]
|
|
||||||
) {
|
|
||||||
return this.fetchChecksum(checksumUrl, algorithm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('findInToolcache', () => {
|
describe('findInToolcache', () => {
|
||||||
@@ -619,31 +605,6 @@ describe('setupJava', () => {
|
|||||||
expect(spyCoreSetOutput).not.toHaveBeenCalled();
|
expect(spyCoreSetOutput).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not repeat version resolution when downloadTool fails', async () => {
|
|
||||||
mockJavaBase = new EmptyJavaBase({
|
|
||||||
version: '11',
|
|
||||||
architecture: 'x86',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false,
|
|
||||||
forceDownload: true
|
|
||||||
});
|
|
||||||
const findPackageForDownload = jest.fn(async () => ({
|
|
||||||
version: '11.0.9',
|
|
||||||
url: 'https://example.com/jdk.tar.gz'
|
|
||||||
}));
|
|
||||||
const downloadError = new Error('download failed');
|
|
||||||
const downloadTool = jest.fn(async () => {
|
|
||||||
throw downloadError;
|
|
||||||
});
|
|
||||||
mockJavaBase['findPackageForDownload'] = findPackageForDownload;
|
|
||||||
mockJavaBase['downloadTool'] = downloadTool;
|
|
||||||
|
|
||||||
await expect(mockJavaBase.setupJava()).rejects.toBe(downloadError);
|
|
||||||
|
|
||||||
expect(findPackageForDownload).toHaveBeenCalledTimes(1);
|
|
||||||
expect(downloadTool).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -831,306 +792,6 @@ describe('setupJava', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('downloadAndVerify', () => {
|
|
||||||
const options: JavaInstallerOptions = {
|
|
||||||
version: '21',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
};
|
|
||||||
let temporaryDirectory: string;
|
|
||||||
let archivePath: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
temporaryDirectory = await fs.promises.mkdtemp(
|
|
||||||
path.join(os.tmpdir(), 'setup-java-base-')
|
|
||||||
);
|
|
||||||
archivePath = path.join(temporaryDirectory, 'archive');
|
|
||||||
await fs.promises.writeFile(archivePath, 'downloaded archive');
|
|
||||||
(tc.downloadTool as jest.Mock<any>).mockResolvedValue(archivePath);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await fs.promises.rm(temporaryDirectory, {recursive: true, force: true});
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns a download after successful verification', async () => {
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
const result = await distribution.downloadRelease({
|
|
||||||
version: '21.0.8',
|
|
||||||
url: 'https://vendor.example/jdk.tar.gz',
|
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: createHash('sha256').update('downloaded archive').digest('hex')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBe(archivePath);
|
|
||||||
expect(fs.existsSync(archivePath)).toBe(true);
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
'Verified sha256 checksum for Empty version 21.0.8.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes the download after verification failure', async () => {
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.downloadRelease({
|
|
||||||
version: '21.0.8',
|
|
||||||
url: 'https://vendor.example/jdk.tar.gz?token=secret',
|
|
||||||
checksum: {algorithm: 'sha256', value: 'a'.repeat(64)}
|
|
||||||
})
|
|
||||||
).rejects.toThrow('Checksum verification failed for Empty version 21.0.8');
|
|
||||||
|
|
||||||
expect(fs.existsSync(archivePath)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('preserves the verification error when removing the download fails', async () => {
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
const cleanupError = new Error('cleanup failed');
|
|
||||||
jest.spyOn(fs.promises, 'rm').mockRejectedValueOnce(cleanupError);
|
|
||||||
|
|
||||||
const result = distribution.downloadRelease({
|
|
||||||
version: '21.0.8',
|
|
||||||
url: 'https://vendor.example/jdk.tar.gz',
|
|
||||||
checksum: {algorithm: 'sha256', value: 'a'.repeat(64)}
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(result).rejects.toMatchObject({
|
|
||||||
message: expect.stringContaining(
|
|
||||||
'Failed to remove the downloaded archive after verification failure: cleanup failed'
|
|
||||||
),
|
|
||||||
cause: expect.objectContaining({
|
|
||||||
message: expect.stringContaining(
|
|
||||||
'Checksum verification failed for Empty version 21.0.8'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('logs when authoritative checksum metadata is unavailable', async () => {
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.downloadRelease({
|
|
||||||
version: '21.0.8',
|
|
||||||
url: 'https://vendor.example/jdk.tar.gz'
|
|
||||||
})
|
|
||||||
).resolves.toBe(archivePath);
|
|
||||||
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
'No authoritative checksum is available for Empty version 21.0.8; skipping checksum verification.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([undefined, '', ' '])(
|
|
||||||
'skips verification when the vendor digest is %p',
|
|
||||||
async value => {
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.downloadRelease({
|
|
||||||
version: '21.0.8',
|
|
||||||
url: 'https://vendor.example/jdk.tar.gz',
|
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value
|
|
||||||
} as JavaDownloadRelease['checksum']
|
|
||||||
})
|
|
||||||
).resolves.toBe(archivePath);
|
|
||||||
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
'No authoritative checksum is available for Empty version 21.0.8; skipping checksum verification.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('fetchChecksum', () => {
|
|
||||||
const options: JavaInstallerOptions = {
|
|
||||||
version: '21',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
};
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
function mockGet(statusCode: number, body: string) {
|
|
||||||
return jest.spyOn(HttpClient.prototype, 'get').mockResolvedValue({
|
|
||||||
message: {statusCode},
|
|
||||||
readBody: async () => body
|
|
||||||
} as any);
|
|
||||||
}
|
|
||||||
|
|
||||||
it('parses a bare hex digest', async () => {
|
|
||||||
const digest = 'a'.repeat(64);
|
|
||||||
const spy = mockGet(200, digest);
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
const checksum = await distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jdk.tar.gz.sha256',
|
|
||||||
'sha256'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(spy).toHaveBeenCalledWith(
|
|
||||||
'https://vendor.example/jdk.tar.gz.sha256'
|
|
||||||
);
|
|
||||||
expect(checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: digest,
|
|
||||||
source: 'https://vendor.example/jdk.tar.gz.sha256'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parses only the first token of a GNU-style checksum file', async () => {
|
|
||||||
const digest = 'b'.repeat(128);
|
|
||||||
mockGet(200, `${digest} jbrsdk-21.0.3-linux-x64-b465.3.tar.gz\n`);
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
const checksum = await distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jdk.tar.gz.checksum',
|
|
||||||
'sha512'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(checksum).toEqual({
|
|
||||||
algorithm: 'sha512',
|
|
||||||
value: digest,
|
|
||||||
source: 'https://vendor.example/jdk.tar.gz.checksum'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('trims surrounding whitespace and newlines', async () => {
|
|
||||||
const digest = 'c'.repeat(64);
|
|
||||||
mockGet(200, `\n ${digest} \n`);
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
const checksum = await distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jdk.tar.gz.sha256',
|
|
||||||
'sha256'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(checksum.value).toBe(digest);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('skips verification when the sibling checksum is not published', async () => {
|
|
||||||
mockGet(404, 'Not Found');
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jdk.tar.gz.sha256',
|
|
||||||
'sha256'
|
|
||||||
)
|
|
||||||
).resolves.toBeUndefined();
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
'No authoritative sha256 checksum is available for Empty from https://vendor.example/jdk.tar.gz.sha256; skipping checksum verification.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('surfaces unexpected HTTP failures without query parameters', async () => {
|
|
||||||
mockGet(500, 'Server Error');
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jdk.tar.gz.sha256?token=secret',
|
|
||||||
'sha256'
|
|
||||||
)
|
|
||||||
).rejects.toThrow(
|
|
||||||
'Failed to fetch the authoritative sha256 checksum for Empty from https://vendor.example/jdk.tar.gz.sha256 (HTTP 500).'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects an empty successful checksum response', async () => {
|
|
||||||
mockGet(200, ' \n');
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jdk.tar.gz.sha256',
|
|
||||||
'sha256'
|
|
||||||
)
|
|
||||||
).rejects.toThrow(
|
|
||||||
'Received an empty authoritative sha256 checksum for Empty from https://vendor.example/jdk.tar.gz.sha256.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('with a list of candidate algorithms', () => {
|
|
||||||
it('infers sha512 when the digest is 128 hex characters', async () => {
|
|
||||||
const digest = 'd'.repeat(128);
|
|
||||||
mockGet(200, `${digest} jbrsdk.tar.gz\n`);
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
const checksum = await distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jbrsdk.tar.gz.checksum',
|
|
||||||
['sha512', 'sha256']
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(checksum).toEqual({
|
|
||||||
algorithm: 'sha512',
|
|
||||||
value: digest,
|
|
||||||
source: 'https://vendor.example/jbrsdk.tar.gz.checksum'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('infers sha256 when the digest is 64 hex characters, even though sha512 was preferred', async () => {
|
|
||||||
// Reproduces older JetBrains JBR builds (e.g. JBR 11), which publish a
|
|
||||||
// SHA-256 digest at the generic `.checksum` sibling instead of SHA-512.
|
|
||||||
const digest = 'e'.repeat(64);
|
|
||||||
mockGet(200, `${digest} jbrsdk_nomod-11_0_16-osx-x64-b2043.64.tar.gz\n`);
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
const checksum = await distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jbrsdk_nomod-11_0_16-osx-x64-b2043.64.tar.gz.checksum',
|
|
||||||
['sha512', 'sha256']
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: digest,
|
|
||||||
source:
|
|
||||||
'https://vendor.example/jbrsdk_nomod-11_0_16-osx-x64-b2043.64.tar.gz.checksum'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('falls back to the first candidate algorithm when the digest length matches none of them', async () => {
|
|
||||||
const digest = 'f'.repeat(40); // e.g. sha1, not supported
|
|
||||||
mockGet(200, `${digest} jbrsdk.tar.gz\n`);
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
const checksum = await distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jbrsdk.tar.gz.checksum',
|
|
||||||
['sha512', 'sha256']
|
|
||||||
);
|
|
||||||
|
|
||||||
// No candidate algorithm matches, so the first-listed one is kept;
|
|
||||||
// downstream verification will reject it as malformed.
|
|
||||||
expect(checksum.algorithm).toBe('sha512');
|
|
||||||
expect(checksum.value).toBe(digest);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reports the checksum as unavailable using a combined algorithm label on 404', async () => {
|
|
||||||
mockGet(404, 'Not Found');
|
|
||||||
const distribution = new EmptyJavaBase(options);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
distribution.fetchChecksumForTest(
|
|
||||||
'https://vendor.example/jbrsdk.tar.gz.checksum',
|
|
||||||
['sha512', 'sha256']
|
|
||||||
)
|
|
||||||
).resolves.toBeUndefined();
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
'No authoritative sha512 or sha256 checksum is available for Empty from https://vendor.example/jbrsdk.tar.gz.checksum; skipping checksum verification.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('normalizeVersion', () => {
|
describe('normalizeVersion', () => {
|
||||||
const DummyJavaBase = JavaBase as any;
|
const DummyJavaBase = JavaBase as any;
|
||||||
|
|
||||||
|
|||||||
@@ -202,12 +202,6 @@ describe('getAvailableVersions', () => {
|
|||||||
await distribution['findPackageForDownload'](version);
|
await distribution['findPackageForDownload'](version);
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
expect(availableVersion.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: expect.stringMatching(/^[a-f0-9]{64}$/),
|
|
||||||
source:
|
|
||||||
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with latest resolves to the newest available major version', async () => {
|
it('with latest resolves to the newest available major version', async () => {
|
||||||
@@ -299,19 +293,6 @@ describe('getAvailableVersions', () => {
|
|||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
it('keeps the canonical ARM runner value separate from the vendor value', () => {
|
|
||||||
jest.spyOn(os, 'arch').mockReturnValue('arm');
|
|
||||||
const distribution = new CorrettoDistribution({
|
|
||||||
version: '11',
|
|
||||||
architecture: '',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(distribution['architecture']).toBe('armv7');
|
|
||||||
expect(distribution['distributionArchitecture']()).toBe('arm');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockPlatform = (
|
const mockPlatform = (
|
||||||
|
|||||||
@@ -1,148 +1,16 @@
|
|||||||
import {getJavaDistribution} from '../../src/distributions/distribution-factory.js';
|
import {getJavaDistribution} from '../../src/distributions/distribution-factory.js';
|
||||||
import {RetryingHttpClient} from '../../src/retrying-http-client.js';
|
|
||||||
import {
|
|
||||||
JAVA_PACKAGE_CAPABILITIES,
|
|
||||||
JavaDistribution
|
|
||||||
} from '../../src/distributions/package-types.js';
|
|
||||||
import os from 'os';
|
|
||||||
import {validateJavaPlatform} from '../../src/distributions/platform-types.js';
|
|
||||||
import {normalizeArchitecture} from '../../src/distributions/platform-types.js';
|
|
||||||
|
|
||||||
const supportedDistributionsOnCurrentPlatform = Object.values(
|
|
||||||
JavaDistribution
|
|
||||||
).filter(distributionName => {
|
|
||||||
try {
|
|
||||||
validateJavaPlatform(distributionName, process.platform, 'x64', '25');
|
|
||||||
return distributionName !== JavaDistribution.JdkFile;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const installerOptions = (packageType: string, version = '25') => ({
|
|
||||||
version,
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType,
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getJavaDistribution', () => {
|
describe('getJavaDistribution', () => {
|
||||||
it.each(supportedDistributionsOnCurrentPlatform)(
|
|
||||||
'uses the shared retrying HTTP client for %s',
|
|
||||||
distributionName => {
|
|
||||||
const distribution = getJavaDistribution(distributionName, {
|
|
||||||
version: '25',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(distribution).not.toBeNull();
|
|
||||||
expect(distribution!['http']).toBeInstanceOf(RetryingHttpClient);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it.each(
|
|
||||||
Object.entries(JAVA_PACKAGE_CAPABILITIES).flatMap(
|
|
||||||
([distributionName, packageTypes]) =>
|
|
||||||
supportedDistributionsOnCurrentPlatform.includes(
|
|
||||||
distributionName as JavaDistribution
|
|
||||||
) || distributionName === JavaDistribution.JdkFile
|
|
||||||
? packageTypes.map(packageType => [distributionName, packageType])
|
|
||||||
: []
|
|
||||||
)
|
|
||||||
)('accepts %s with java-package %s', (distributionName, packageType) => {
|
|
||||||
expect(
|
|
||||||
getJavaDistribution(
|
|
||||||
distributionName,
|
|
||||||
installerOptions(packageType as string)
|
|
||||||
)
|
|
||||||
).not.toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each(Object.entries(JAVA_PACKAGE_CAPABILITIES))(
|
|
||||||
'rejects unsupported java-package values for %s',
|
|
||||||
(distributionName, packageTypes) => {
|
|
||||||
expect(() =>
|
|
||||||
getJavaDistribution(distributionName, installerOptions('jdk+typo'))
|
|
||||||
).toThrow(
|
|
||||||
`Java package 'jdk+typo' is not supported for distribution '${distributionName}'. Supported package types: ${packageTypes.join(', ')}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it("rejects java-package 'jdk+jmods' for non-Temurin distributions", () => {
|
it("rejects java-package 'jdk+jmods' for non-Temurin distributions", () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
getJavaDistribution('zulu', installerOptions('jdk+jmods'))
|
getJavaDistribution('zulu', {
|
||||||
|
version: '25',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk+jmods',
|
||||||
|
checkLatest: false
|
||||||
|
})
|
||||||
).toThrow(
|
).toThrow(
|
||||||
"Java package 'jdk+jmods' is not supported for distribution 'zulu'. Supported package types: jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac."
|
"java-package 'jdk+jmods' is only supported for distribution 'temurin'."
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['8', '23.x', '23.0.1.1', '<24'])(
|
|
||||||
"rejects Temurin java-package 'jdk+jmods' for version %s",
|
|
||||||
version => {
|
|
||||||
expect(() =>
|
|
||||||
getJavaDistribution(
|
|
||||||
JavaDistribution.Temurin,
|
|
||||||
installerOptions('jdk+jmods', version)
|
|
||||||
)
|
|
||||||
).toThrow(
|
|
||||||
`Java package 'jdk+jmods' is not supported for distribution 'temurin'. Supported package types: jdk, jre, jdk+jmods. Package 'jdk+jmods' requires Java 24 or later; requested version '${version}'.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it.each(['24', '24.0.1.1', '25-ea', '>=21', 'latest'])(
|
|
||||||
"accepts Temurin java-package 'jdk+jmods' for version %s",
|
|
||||||
version => {
|
|
||||||
expect(
|
|
||||||
getJavaDistribution(
|
|
||||||
JavaDistribution.Temurin,
|
|
||||||
installerOptions('jdk+jmods', version)
|
|
||||||
)
|
|
||||||
).not.toBeNull();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('preserves unsupported distribution handling', () => {
|
|
||||||
expect(
|
|
||||||
getJavaDistribution(
|
|
||||||
'not-a-distribution',
|
|
||||||
installerOptions('not-a-package')
|
|
||||||
)
|
|
||||||
).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
['amd64', 'x64'],
|
|
||||||
['ia32', 'x86'],
|
|
||||||
['arm64', 'aarch64']
|
|
||||||
])('passes normalized architecture %s as %s', (input, expected) => {
|
|
||||||
const normalized = getJavaDistribution(JavaDistribution.JdkFile, {
|
|
||||||
...installerOptions('jdk'),
|
|
||||||
architecture: input
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(normalized!['architecture']).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses the runner architecture when the input is empty', () => {
|
|
||||||
const distribution = getJavaDistribution(JavaDistribution.Temurin, {
|
|
||||||
...installerOptions('jdk'),
|
|
||||||
architecture: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
const expected = normalizeArchitecture(os.arch());
|
|
||||||
expect(distribution!['architecture']).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects an unsupported combination before creating an HTTP client', () => {
|
|
||||||
expect(() =>
|
|
||||||
getJavaDistribution(JavaDistribution.Oracle, {
|
|
||||||
...installerOptions('jdk'),
|
|
||||||
architecture: 'x86'
|
|
||||||
})
|
|
||||||
).toThrow(/does not support operating system/);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -259,10 +259,6 @@ describe('getAvailableVersions', () => {
|
|||||||
await distribution['findPackageForDownload'](jdkVersion);
|
await distribution['findPackageForDownload'](jdkVersion);
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
expect(availableVersion.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: expect.stringMatching(/^[a-f0-9]{64}$/)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -129,14 +129,6 @@ describe('GraalVMDistribution', () => {
|
|||||||
(distribution as any).http = mockHttpClient;
|
(distribution as any).http = mockHttpClient;
|
||||||
(communityDistribution as any).http = mockHttpClient;
|
(communityDistribution as any).http = mockHttpClient;
|
||||||
|
|
||||||
// Default checksum sibling response for `${url}.sha256` requests made by
|
|
||||||
// GraalVM (Oracle) and GraalVM EA. Individual tests override this when
|
|
||||||
// they need to assert the exact URL/digest contract.
|
|
||||||
mockHttpClient.get.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: jest.fn().mockResolvedValue('a'.repeat(64))
|
|
||||||
});
|
|
||||||
|
|
||||||
(util.getDownloadArchiveExtension as jest.Mock<any>).mockReturnValue(
|
(util.getDownloadArchiveExtension as jest.Mock<any>).mockReturnValue(
|
||||||
'tar.gz'
|
'tar.gz'
|
||||||
);
|
);
|
||||||
@@ -415,16 +407,9 @@ describe('GraalVMDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
url: 'https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.5_linux-x64_bin.tar.gz',
|
url: 'https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.5_linux-x64_bin.tar.gz',
|
||||||
version: '17.0.5',
|
version: '17.0.5'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: 'a'.repeat(64),
|
|
||||||
source:
|
|
||||||
'https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.5_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
expect(mockHttpClient.head).toHaveBeenCalledWith(result.url);
|
expect(mockHttpClient.head).toHaveBeenCalledWith(result.url);
|
||||||
expect(mockHttpClient.get).toHaveBeenCalledWith(`${result.url}.sha256`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should construct correct URL for major version (latest)', async () => {
|
it('should construct correct URL for major version (latest)', async () => {
|
||||||
@@ -437,13 +422,7 @@ describe('GraalVMDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
url: 'https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz',
|
url: 'https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz',
|
||||||
version: '21',
|
version: '21'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: 'a'.repeat(64),
|
|
||||||
source:
|
|
||||||
'https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -486,13 +465,7 @@ describe('GraalVMDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
url: 'https://download.oracle.com/graalvm/25/latest/graalvm-jdk-25_linux-x64_bin.tar.gz',
|
url: 'https://download.oracle.com/graalvm/25/latest/graalvm-jdk-25_linux-x64_bin.tar.gz',
|
||||||
version: '25',
|
version: '25'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: 'a'.repeat(64),
|
|
||||||
source:
|
|
||||||
'https://download.oracle.com/graalvm/25/latest/graalvm-jdk-25_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -664,20 +637,13 @@ describe('GraalVMDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
url: 'https://example.com/download/graalvm-jdk-23_linux-x64_bin.tar.gz',
|
url: 'https://example.com/download/graalvm-jdk-23_linux-x64_bin.tar.gz',
|
||||||
version: '23-ea-20240716',
|
version: '23-ea-20240716'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: 'a'.repeat(64),
|
|
||||||
source:
|
|
||||||
'https://example.com/download/graalvm-jdk-23_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockHttpClient.getJson).toHaveBeenCalledWith(
|
expect(mockHttpClient.getJson).toHaveBeenCalledWith(
|
||||||
'https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/23-ea.json?ref=main',
|
'https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/23-ea.json?ref=main',
|
||||||
{Accept: 'application/json'}
|
{Accept: 'application/json'}
|
||||||
);
|
);
|
||||||
expect(mockHttpClient.get).toHaveBeenCalledWith(`${result.url}.sha256`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw error when no latest EA version found', async () => {
|
it('should throw error when no latest EA version found', async () => {
|
||||||
@@ -910,15 +876,8 @@ describe('GraalVMDistribution', () => {
|
|||||||
expect(fetchEASpy).toHaveBeenCalledWith('23-ea');
|
expect(fetchEASpy).toHaveBeenCalledWith('23-ea');
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
url: 'https://example.com/download/graalvm-jdk-23_linux-x64_bin.tar.gz',
|
url: 'https://example.com/download/graalvm-jdk-23_linux-x64_bin.tar.gz',
|
||||||
version: '23-ea-20240716',
|
version: '23-ea-20240716'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: 'a'.repeat(64),
|
|
||||||
source:
|
|
||||||
'https://example.com/download/graalvm-jdk-23_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
expect(mockHttpClient.get).toHaveBeenCalledWith(`${result.url}.sha256`);
|
|
||||||
|
|
||||||
// Verify debug logging
|
// Verify debug logging
|
||||||
expect(core.debug).toHaveBeenCalledWith('Searching for EA build: 23-ea');
|
expect(core.debug).toHaveBeenCalledWith('Searching for EA build: 23-ea');
|
||||||
@@ -1017,13 +976,7 @@ describe('GraalVMDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
url: 'https://example.com/download/graalvm-jdk-23_linux-aarch64_bin.tar.gz',
|
url: 'https://example.com/download/graalvm-jdk-23_linux-aarch64_bin.tar.gz',
|
||||||
version: '23-ea-20240716',
|
version: '23-ea-20240716'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: 'a'.repeat(64),
|
|
||||||
source:
|
|
||||||
'https://example.com/download/graalvm-jdk-23_linux-aarch64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1198,80 +1151,6 @@ describe('GraalVMDistribution', () => {
|
|||||||
url: 'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
url: 'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
||||||
version: '21.0.2'
|
version: '21.0.2'
|
||||||
});
|
});
|
||||||
// The asset had no `digest` field, so no checksum should be attached,
|
|
||||||
// and the checksum sibling-URL fetch path (used by Oracle GraalVM)
|
|
||||||
// must not be consulted for GraalVM Community.
|
|
||||||
expect(result.checksum).toBeUndefined();
|
|
||||||
expect(mockHttpClient.get).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('strips the `sha256:` prefix from a GitHub release asset digest', async () => {
|
|
||||||
const digest = 'd'.repeat(64);
|
|
||||||
mockHttpClient.getJson.mockResolvedValue({
|
|
||||||
result: [
|
|
||||||
{
|
|
||||||
draft: false,
|
|
||||||
prerelease: false,
|
|
||||||
assets: [
|
|
||||||
{
|
|
||||||
name: 'graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
|
||||||
browser_download_url:
|
|
||||||
'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
|
||||||
digest: `sha256:${digest}`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await (
|
|
||||||
communityDistribution as any
|
|
||||||
).findPackageForDownload('21.0.2');
|
|
||||||
|
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: digest,
|
|
||||||
source:
|
|
||||||
'https://api.github.com/repos/graalvm/graalvm-ce-builds/releases?per_page=100'
|
|
||||||
});
|
|
||||||
// The digest came from the release listing itself, so no additional
|
|
||||||
// HTTP request should be made to resolve the checksum.
|
|
||||||
expect(mockHttpClient.get).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('safely skips a missing or malformed release asset digest', async () => {
|
|
||||||
mockHttpClient.getJson.mockResolvedValue({
|
|
||||||
result: [
|
|
||||||
{
|
|
||||||
draft: false,
|
|
||||||
prerelease: false,
|
|
||||||
assets: [
|
|
||||||
{
|
|
||||||
name: 'graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
|
||||||
browser_download_url:
|
|
||||||
'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
|
||||||
digest: 'md5:not-a-sha256-digest'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await (
|
|
||||||
communityDistribution as any
|
|
||||||
).findPackageForDownload('21.0.2');
|
|
||||||
|
|
||||||
expect(result.checksum).toBeUndefined();
|
|
||||||
expect(mockHttpClient.get).not.toHaveBeenCalled();
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining(
|
|
||||||
'No authoritative sha256 digest is available for graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve the latest GraalVM Community release for a major version', async () => {
|
it('should resolve the latest GraalVM Community release for a major version', async () => {
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ import {
|
|||||||
afterAll
|
afterAll
|
||||||
} from '@jest/globals';
|
} from '@jest/globals';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import {HttpClient, HttpClientResponse} from '@actions/http-client';
|
import {HttpClient} from '@actions/http-client';
|
||||||
import type {IncomingMessage} from 'http';
|
|
||||||
import {Readable} from 'stream';
|
|
||||||
|
|
||||||
import manifestData from '../data/jetbrains.json' with {type: 'json'};
|
import manifestData from '../data/jetbrains.json' with {type: 'json'};
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
@@ -46,18 +44,6 @@ jest.unstable_mockModule('@actions/core', () => ({
|
|||||||
const core = await import('@actions/core');
|
const core = await import('@actions/core');
|
||||||
const {JetBrainsDistribution} =
|
const {JetBrainsDistribution} =
|
||||||
await import('../../src/distributions/jetbrains/installer.js');
|
await import('../../src/distributions/jetbrains/installer.js');
|
||||||
const {RetryingHttpClient} = await import('../../src/retrying-http-client.js');
|
|
||||||
|
|
||||||
function response(
|
|
||||||
statusCode: number,
|
|
||||||
body = '',
|
|
||||||
headers: IncomingMessage['headers'] = {}
|
|
||||||
): HttpClientResponse {
|
|
||||||
const message = Readable.from([Buffer.from(body)]) as IncomingMessage;
|
|
||||||
message.statusCode = statusCode;
|
|
||||||
message.headers = headers;
|
|
||||||
return new HttpClientResponse(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: any;
|
let spyHttpClient: any;
|
||||||
@@ -109,66 +95,9 @@ describe('getAvailableVersions', () => {
|
|||||||
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
|
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
|
||||||
expect(availableVersions.length).toBe(length);
|
expect(availableVersions.length).toBe(length);
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
|
|
||||||
it('retries a GitHub rate limit using Retry-After', async () => {
|
|
||||||
spyHttpClient.mockRestore();
|
|
||||||
const sleep = jest.fn(async () => undefined);
|
|
||||||
const requestRaw = jest
|
|
||||||
.spyOn(HttpClient.prototype, 'requestRaw')
|
|
||||||
.mockResolvedValueOnce(response(429, '', {'retry-after': '2'}))
|
|
||||||
.mockResolvedValueOnce(response(200, '[]'))
|
|
||||||
.mockResolvedValueOnce(response(200))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const distribution = new JetBrainsDistribution({
|
|
||||||
version: '17',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['http'] = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
const availableVersions = await distribution['getAvailableVersions']();
|
|
||||||
|
|
||||||
expect(availableVersions).toHaveLength(2);
|
|
||||||
expect(requestRaw).toHaveBeenCalledTimes(4);
|
|
||||||
expect(requestRaw.mock.calls[0][0].options.path).toBe(
|
|
||||||
requestRaw.mock.calls[1][0].options.path
|
|
||||||
);
|
|
||||||
expect(requestRaw.mock.calls[0][0].options.path).toContain(
|
|
||||||
'/repos/JetBrains/JetBrainsRuntime/releases'
|
|
||||||
);
|
|
||||||
expect(sleep).toHaveBeenCalledWith(2000);
|
|
||||||
expect(core.info).toHaveBeenCalledWith(
|
|
||||||
'Request attempt 1 of 4 failed (HTTP 429); retrying in 2000 ms'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
let spyHttpClientGet: any;
|
|
||||||
|
|
||||||
const JETBRAINS_CHECKSUM = 'c'.repeat(128);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// Every resolved release fetches `${url}.checksum` (sha512, GNU
|
|
||||||
// `<hex> <filename>` format); stub it so tests never reach the real
|
|
||||||
// network, except the dedicated 'version %s can be downloaded' test
|
|
||||||
// below which intentionally exercises real HTTPS HEAD requests.
|
|
||||||
spyHttpClientGet = jest
|
|
||||||
.spyOn(HttpClient.prototype, 'get')
|
|
||||||
.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => `${JETBRAINS_CHECKSUM} jbrsdk.tar.gz\n`
|
|
||||||
} as any);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['17', '17.0.11+1207.24'],
|
['17', '17.0.11+1207.24'],
|
||||||
['11.0', '11.0.16+2043.64'],
|
['11.0', '11.0.16+2043.64'],
|
||||||
@@ -252,72 +181,4 @@ describe('findPackageForDownload', () => {
|
|||||||
/No matching version found for SemVer */
|
/No matching version found for SemVer */
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fetches the authoritative sha512 checksum only for the resolved version', async () => {
|
|
||||||
const distribution = new JetBrainsDistribution({
|
|
||||||
version: '21',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload']('21');
|
|
||||||
|
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha512',
|
|
||||||
value: JETBRAINS_CHECKSUM,
|
|
||||||
source: `${result.url}.checksum`
|
|
||||||
});
|
|
||||||
// Only the single resolved/winning version's checksum is requested,
|
|
||||||
// not one per candidate considered during version resolution.
|
|
||||||
expect(spyHttpClientGet).toHaveBeenCalledWith(`${result.url}.checksum`);
|
|
||||||
expect(spyHttpClientGet).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parses only the first whitespace-delimited token from the GNU checksum payload', async () => {
|
|
||||||
spyHttpClientGet.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => `${JETBRAINS_CHECKSUM} jbrsdk-21.tar.gz\n`
|
|
||||||
} as any);
|
|
||||||
|
|
||||||
const distribution = new JetBrainsDistribution({
|
|
||||||
version: '21',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload']('21');
|
|
||||||
|
|
||||||
expect(result.checksum?.value).toBe(JETBRAINS_CHECKSUM);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('falls back to a sha256 checksum for older JBR builds that only publish one', async () => {
|
|
||||||
// Older JBR 11 builds (e.g. jbrsdk_nomod-11_0_16-*-b2043.64.tar.gz) publish
|
|
||||||
// a SHA-256 digest at the generic `.checksum` sibling instead of SHA-512.
|
|
||||||
const sha256Checksum = 'a'.repeat(64);
|
|
||||||
spyHttpClientGet.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () =>
|
|
||||||
`${sha256Checksum} jbrsdk_nomod-11_0_16-osx-x64-b2043.64.tar.gz\n`
|
|
||||||
} as any);
|
|
||||||
|
|
||||||
const distribution = new JetBrainsDistribution({
|
|
||||||
version: '21',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload']('21');
|
|
||||||
|
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: sha256Checksum,
|
|
||||||
source: `${result.url}.checksum`
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -216,15 +216,6 @@ describe('Check findPackageForDownload', () => {
|
|||||||
await distribution['findPackageForDownload'](version);
|
await distribution['findPackageForDownload'](version);
|
||||||
expect(availableRelease).not.toBeNull();
|
expect(availableRelease).not.toBeNull();
|
||||||
expect(availableRelease.url).toBe(expectedUrl);
|
expect(availableRelease.url).toBe(expectedUrl);
|
||||||
if (availableRelease.checksum) {
|
|
||||||
expect(availableRelease.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: expect.stringMatching(/^[a-f0-9]{64}$/),
|
|
||||||
source: 'https://tencent.github.io/konajdk/releases/kona-v1.json'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
expect(version).toBe('8.0.20');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -103,12 +103,9 @@ const util = await import('../../src/util.js');
|
|||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
let distribution: InstanceType<typeof MicrosoftDistributions>;
|
let distribution: InstanceType<typeof MicrosoftDistributions>;
|
||||||
let spyGetManifestFromRepo: any;
|
let spyGetManifestFromRepo: any;
|
||||||
let spyHttpClientGet: any;
|
|
||||||
let spyDebug: any;
|
let spyDebug: any;
|
||||||
let spyCoreError: any;
|
let spyCoreError: any;
|
||||||
|
|
||||||
const MICROSOFT_CHECKSUM = 'b'.repeat(64);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockOsArch.mockReturnValue('x64');
|
mockOsArch.mockReturnValue('x64');
|
||||||
mockOsPlatform.mockReturnValue(process.platform);
|
mockOsPlatform.mockReturnValue(process.platform);
|
||||||
@@ -127,15 +124,6 @@ describe('findPackageForDownload', () => {
|
|||||||
headers: {}
|
headers: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Every resolved release fetches `${download_url}.sha256sum.txt`; stub
|
|
||||||
// it with a GNU-style `<hex> <filename>` payload so tests never reach
|
|
||||||
// the real network.
|
|
||||||
spyHttpClientGet = jest.spyOn(HttpClient.prototype, 'get');
|
|
||||||
spyHttpClientGet.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => `${MICROSOFT_CHECKSUM} microsoft-jdk.tar.gz\n`
|
|
||||||
});
|
|
||||||
|
|
||||||
spyDebug = core.debug as jest.Mock;
|
spyDebug = core.debug as jest.Mock;
|
||||||
spyDebug.mockImplementation(() => {});
|
spyDebug.mockImplementation(() => {});
|
||||||
|
|
||||||
@@ -323,34 +311,6 @@ describe('findPackageForDownload', () => {
|
|||||||
'https://example.test/jdk.tar.gz.custom.sig'
|
'https://example.test/jdk.tar.gz.custom.sig'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fetches the authoritative sha256 checksum from the GNU-style sibling file', async () => {
|
|
||||||
mockOsPlatform.mockReturnValue(process.platform);
|
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload']('17.0.7');
|
|
||||||
|
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: MICROSOFT_CHECKSUM,
|
|
||||||
source: `${result.url}.sha256sum.txt`
|
|
||||||
});
|
|
||||||
expect(spyHttpClientGet).toHaveBeenCalledWith(
|
|
||||||
`${result.url}.sha256sum.txt`
|
|
||||||
);
|
|
||||||
expect(spyHttpClientGet).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parses only the first whitespace-delimited token from the GNU checksum payload', async () => {
|
|
||||||
spyHttpClientGet.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () =>
|
|
||||||
`${MICROSOFT_CHECKSUM} microsoft-jdk-17.0.7-linux-x64.tar.gz\n`
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload']('17.0.7');
|
|
||||||
|
|
||||||
expect(result.checksum?.value).toBe(MICROSOFT_CHECKSUM);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('downloadTool', () => {
|
describe('downloadTool', () => {
|
||||||
|
|||||||
@@ -50,14 +50,6 @@ const archivePage = `
|
|||||||
<th>9.0.4 (build 9.0.4+11)</th>
|
<th>9.0.4 (build 9.0.4+11)</th>
|
||||||
<a href="https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz">tar.gz</a>
|
<a href="https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
`;
|
`;
|
||||||
const GA_CHECKSUM = 'c'.repeat(64);
|
|
||||||
const EA_CHECKSUM = 'd'.repeat(64);
|
|
||||||
const checksumPages: Record<string, string> = {
|
|
||||||
'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz.sha256':
|
|
||||||
GA_CHECKSUM,
|
|
||||||
'https://download.java.net/java/early_access/jdk27/32/GPL/openjdk-27-ea+32_linux-x64_bin.tar.gz.sha256':
|
|
||||||
EA_CHECKSUM
|
|
||||||
};
|
|
||||||
|
|
||||||
function createDistribution(
|
function createDistribution(
|
||||||
version = '26',
|
version = '26',
|
||||||
@@ -90,16 +82,8 @@ describe('OpenJdkDistribution', () => {
|
|||||||
'https://jdk.java.net/27/': earlyAccessPage,
|
'https://jdk.java.net/27/': earlyAccessPage,
|
||||||
'https://jdk.java.net/archive/': archivePage
|
'https://jdk.java.net/archive/': archivePage
|
||||||
};
|
};
|
||||||
if (url in pages) {
|
|
||||||
return {
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => pages[url]
|
|
||||||
} as Awaited<ReturnType<HttpClient['get']>>;
|
|
||||||
}
|
|
||||||
// Any other GET is a `${archiveUrl}.sha256` checksum sibling request.
|
|
||||||
return {
|
return {
|
||||||
message: {statusCode: 200},
|
readBody: async () => pages[url] ?? ''
|
||||||
readBody: async () => checksumPages[url] ?? 'e'.repeat(64)
|
|
||||||
} as Awaited<ReturnType<HttpClient['get']>>;
|
} as Awaited<ReturnType<HttpClient['get']>>;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -113,15 +97,8 @@ describe('OpenJdkDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
version: '26.0.2+10',
|
version: '26.0.2+10',
|
||||||
url: 'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz',
|
url: 'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: GA_CHECKSUM,
|
|
||||||
source:
|
|
||||||
'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
expect(getSpy).toHaveBeenCalledWith(`${result.url}.sha256`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves an archived GA release', async () => {
|
it('resolves an archived GA release', async () => {
|
||||||
@@ -167,16 +144,9 @@ describe('OpenJdkDistribution', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
version: '27.0.0+32',
|
version: '27.0.0+32',
|
||||||
url: 'https://download.java.net/java/early_access/jdk27/32/GPL/openjdk-27-ea+32_linux-x64_bin.tar.gz',
|
url: 'https://download.java.net/java/early_access/jdk27/32/GPL/openjdk-27-ea+32_linux-x64_bin.tar.gz'
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: EA_CHECKSUM,
|
|
||||||
source:
|
|
||||||
'https://download.java.net/java/early_access/jdk27/32/GPL/openjdk-27-ea+32_linux-x64_bin.tar.gz.sha256'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
expect(getSpy).not.toHaveBeenCalledWith('https://jdk.java.net/archive/');
|
expect(getSpy).not.toHaveBeenCalledWith('https://jdk.java.net/archive/');
|
||||||
expect(getSpy).toHaveBeenCalledWith(`${result.url}.sha256`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports available versions when no release matches', async () => {
|
it('reports available versions when no release matches', async () => {
|
||||||
|
|||||||
@@ -47,11 +47,8 @@ describe('findPackageForDownload', () => {
|
|||||||
let distribution: InstanceType<typeof OracleDistribution>;
|
let distribution: InstanceType<typeof OracleDistribution>;
|
||||||
let spyDebug: any;
|
let spyDebug: any;
|
||||||
let spyHttpClient: any;
|
let spyHttpClient: any;
|
||||||
let spyHttpClientGet: any;
|
|
||||||
let spyCoreError: any;
|
let spyCoreError: any;
|
||||||
|
|
||||||
const ORACLE_CHECKSUM = 'f'.repeat(64);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
distribution = new OracleDistribution({
|
distribution = new OracleDistribution({
|
||||||
version: '',
|
version: '',
|
||||||
@@ -66,14 +63,6 @@ describe('findPackageForDownload', () => {
|
|||||||
// Mock core.error to suppress error logs
|
// Mock core.error to suppress error logs
|
||||||
spyCoreError = core.error as jest.Mock;
|
spyCoreError = core.error as jest.Mock;
|
||||||
spyCoreError.mockImplementation(() => {});
|
spyCoreError.mockImplementation(() => {});
|
||||||
|
|
||||||
// Every resolved release fetches its `${url}.sha256` sibling checksum;
|
|
||||||
// stub it so tests never reach the real network.
|
|
||||||
spyHttpClientGet = jest.spyOn(HttpClient.prototype, 'get');
|
|
||||||
spyHttpClientGet.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => ORACLE_CHECKSUM
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
@@ -144,23 +133,6 @@ describe('findPackageForDownload', () => {
|
|||||||
expect(result.url).toBe(url);
|
expect(result.url).toBe(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fetches the authoritative sha256 checksum for the resolved archive', async () => {
|
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
|
|
||||||
spyHttpClient.mockResolvedValue({message: {statusCode: 200}});
|
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload']('21');
|
|
||||||
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
|
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: ORACLE_CHECKSUM,
|
|
||||||
source: `${result.url}.sha256`
|
|
||||||
});
|
|
||||||
expect(spyHttpClientGet).toHaveBeenCalledWith(`${result.url}.sha256`);
|
|
||||||
expect(spyHttpClientGet).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['amd64', 'x64'],
|
['amd64', 'x64'],
|
||||||
['arm64', 'aarch64']
|
['arm64', 'aarch64']
|
||||||
@@ -224,10 +196,6 @@ describe('findPackageForDownload with latest', () => {
|
|||||||
it('resolves the newest major version from the Adoptium API', async () => {
|
it('resolves the newest major version from the Adoptium API', async () => {
|
||||||
spyHttpClientHead = jest.spyOn(HttpClient.prototype, 'head');
|
spyHttpClientHead = jest.spyOn(HttpClient.prototype, 'head');
|
||||||
spyHttpClientHead.mockResolvedValue({message: {statusCode: 200}});
|
spyHttpClientHead.mockResolvedValue({message: {statusCode: 200}});
|
||||||
jest.spyOn(HttpClient.prototype, 'get').mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => 'f'.repeat(64)
|
|
||||||
} as any);
|
|
||||||
|
|
||||||
const distribution = new OracleDistribution({
|
const distribution = new OracleDistribution({
|
||||||
version: 'latest',
|
version: 'latest',
|
||||||
|
|||||||
@@ -52,10 +52,8 @@ const utils = await import('../../src/util.js');
|
|||||||
|
|
||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: any;
|
let spyHttpClient: any;
|
||||||
let spyHttpGet: any;
|
|
||||||
let spyUtilGetDownloadArchiveExtension: any;
|
let spyUtilGetDownloadArchiveExtension: any;
|
||||||
let spyCoreError: any;
|
let spyCoreError: any;
|
||||||
const archiveChecksum = 'f'.repeat(64);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||||
@@ -64,11 +62,6 @@ describe('getAvailableVersions', () => {
|
|||||||
headers: {},
|
headers: {},
|
||||||
result: manifestData
|
result: manifestData
|
||||||
});
|
});
|
||||||
spyHttpGet = jest.spyOn(HttpClient.prototype, 'get');
|
|
||||||
spyHttpGet.mockResolvedValue({
|
|
||||||
message: {statusCode: 200},
|
|
||||||
readBody: async () => `${archiveChecksum} archive`
|
|
||||||
});
|
|
||||||
|
|
||||||
spyUtilGetDownloadArchiveExtension =
|
spyUtilGetDownloadArchiveExtension =
|
||||||
utils.getDownloadArchiveExtension as jest.Mock<any>;
|
utils.getDownloadArchiveExtension as jest.Mock<any>;
|
||||||
@@ -289,31 +282,9 @@ describe('getAvailableVersions', () => {
|
|||||||
await distribution['findPackageForDownload'](normalizedVersion);
|
await distribution['findPackageForDownload'](normalizedVersion);
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
expect(availableVersion.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: archiveChecksum,
|
|
||||||
source: expectedLink.replace(/\.(?:tar\.gz|zip)$/, '.sha256.txt')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
it('uses the checksum published beside the selected EA archive', async () => {
|
|
||||||
const distribution = new SapMachineDistribution({
|
|
||||||
version: '21-ea',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
mockPlatform(distribution, 'linux');
|
|
||||||
|
|
||||||
const release = await distribution['findPackageForDownload']('21');
|
|
||||||
|
|
||||||
expect(spyHttpGet).toHaveBeenCalledWith(
|
|
||||||
release.url.replace(/\.(?:tar\.gz|zip)$/, '.sha256.txt')
|
|
||||||
);
|
|
||||||
expect(release.checksum?.value).toBe(archiveChecksum);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['8', 'linux', 'x64'],
|
['8', 'linux', 'x64'],
|
||||||
['8', 'macos', 'aarch64'],
|
['8', 'macos', 'aarch64'],
|
||||||
|
|||||||
@@ -208,14 +208,6 @@ describe('findPackageForDownload', () => {
|
|||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||||
expect(resolvedVersion.version).toBe(expected);
|
expect(resolvedVersion.version).toBe(expected);
|
||||||
const vendorPackage = (manifestData as any[]).find(
|
|
||||||
item => item.version_data.semver === expected
|
|
||||||
).binaries[0].package;
|
|
||||||
expect(resolvedVersion.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: vendorPackage.checksum,
|
|
||||||
source: vendorPackage.checksum_link
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('version is found but binaries list is empty', async () => {
|
it('version is found but binaries list is empty', async () => {
|
||||||
|
|||||||
@@ -291,7 +291,6 @@ describe('getAvailableVersions', () => {
|
|||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['amd64', 'x64'],
|
['amd64', 'x64'],
|
||||||
['arm', 'arm'],
|
|
||||||
['arm64', 'aarch64']
|
['arm64', 'aarch64']
|
||||||
])(
|
])(
|
||||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||||
@@ -348,14 +347,6 @@ describe('findPackageForDownload', () => {
|
|||||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||||
expect(resolvedVersion.version).toBe(expected);
|
expect(resolvedVersion.version).toBe(expected);
|
||||||
expect(resolvedVersion.signatureUrl).toBeDefined();
|
expect(resolvedVersion.signatureUrl).toBeDefined();
|
||||||
const vendorPackage = (manifestData as any[]).find(
|
|
||||||
item => item.version_data.semver === expected
|
|
||||||
).binaries[0].package;
|
|
||||||
expect(resolvedVersion.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: vendorPackage.checksum,
|
|
||||||
source: vendorPackage.checksum_link
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('version "latest" is normalized to the newest available version', async () => {
|
it('version "latest" is normalized to the newest available version', async () => {
|
||||||
|
|||||||
@@ -241,26 +241,6 @@ describe('getArchitectureOptions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
let spyPackageDetails: any;
|
|
||||||
|
|
||||||
const ZULU_CHECKSUM = 'a'.repeat(64);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// The resolved winning package fetches sha256_hash from the Azul
|
|
||||||
// package-details endpoint; stub it so tests never reach the real
|
|
||||||
// network.
|
|
||||||
spyPackageDetails = jest.spyOn(HttpClient.prototype, 'getJson');
|
|
||||||
spyPackageDetails.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: {sha256_hash: ZULU_CHECKSUM}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['8', '8.0.282+8'],
|
['8', '8.0.282+8'],
|
||||||
['11.x', '11.0.10+9'],
|
['11.x', '11.0.10+9'],
|
||||||
@@ -299,38 +279,6 @@ describe('findPackageForDownload', () => {
|
|||||||
expect(result.url).toBe(
|
expect(result.url).toBe(
|
||||||
'https://cdn.azul.com/zulu/bin/zulu11.35.15-ca-jdk11.0.5-macosx_x64.tar.gz'
|
'https://cdn.azul.com/zulu/bin/zulu11.35.15-ca-jdk11.0.5-macosx_x64.tar.gz'
|
||||||
);
|
);
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: ZULU_CHECKSUM,
|
|
||||||
source: 'https://api.azul.com/metadata/v1/zulu/packages/test-uuid-10933'
|
|
||||||
});
|
|
||||||
// Only the winning package's UUID triggers a details request.
|
|
||||||
expect(spyPackageDetails).toHaveBeenCalledWith(
|
|
||||||
'https://api.azul.com/metadata/v1/zulu/packages/test-uuid-10933'
|
|
||||||
);
|
|
||||||
expect(spyPackageDetails).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('skips checksum verification when sha256_hash is missing or malformed', async () => {
|
|
||||||
spyPackageDetails.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: {sha256_hash: 'not-a-valid-digest'}
|
|
||||||
});
|
|
||||||
|
|
||||||
const distribution = new ZuluDistribution({
|
|
||||||
version: '',
|
|
||||||
architecture: 'x86',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['getAvailableVersions'] = async () => manifestData;
|
|
||||||
const result = await distribution['findPackageForDownload']('11.0.5');
|
|
||||||
|
|
||||||
expect(result.checksum).toBeUndefined();
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining('No authoritative sha256 checksum')
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error', async () => {
|
it('should throw an error', async () => {
|
||||||
|
|||||||
@@ -245,26 +245,6 @@ describe('getArchitectureOptions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
let spyPackageDetails: any;
|
|
||||||
|
|
||||||
const ZULU_CHECKSUM = 'a'.repeat(64);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// The resolved winning package fetches sha256_hash from the Azul
|
|
||||||
// package-details endpoint; stub it so tests never reach the real
|
|
||||||
// network.
|
|
||||||
spyPackageDetails = jest.spyOn(HttpClient.prototype, 'getJson');
|
|
||||||
spyPackageDetails.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: {sha256_hash: ZULU_CHECKSUM}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['8', '8.0.282+8'],
|
['8', '8.0.282+8'],
|
||||||
['11.x', '11.0.10+9'],
|
['11.x', '11.0.10+9'],
|
||||||
@@ -303,38 +283,6 @@ describe('findPackageForDownload', () => {
|
|||||||
expect(result.url).toBe(
|
expect(result.url).toBe(
|
||||||
'https://cdn.azul.com/zulu/bin/zulu21.32.17-ca-jdk21.0.2-linux_aarch64.tar.gz'
|
'https://cdn.azul.com/zulu/bin/zulu21.32.17-ca-jdk21.0.2-linux_aarch64.tar.gz'
|
||||||
);
|
);
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: ZULU_CHECKSUM,
|
|
||||||
source: 'https://api.azul.com/metadata/v1/zulu/packages/test-uuid-12447'
|
|
||||||
});
|
|
||||||
// Only the winning package's UUID triggers a details request.
|
|
||||||
expect(spyPackageDetails).toHaveBeenCalledWith(
|
|
||||||
'https://api.azul.com/metadata/v1/zulu/packages/test-uuid-12447'
|
|
||||||
);
|
|
||||||
expect(spyPackageDetails).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('skips checksum verification when sha256_hash is missing or malformed', async () => {
|
|
||||||
spyPackageDetails.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
const distribution = new ZuluDistribution({
|
|
||||||
version: '',
|
|
||||||
architecture: 'arm64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['getAvailableVersions'] = async () => manifestData;
|
|
||||||
const result = await distribution['findPackageForDownload']('21.0.2');
|
|
||||||
|
|
||||||
expect(result.checksum).toBeUndefined();
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining('No authoritative sha256 checksum')
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error', async () => {
|
it('should throw an error', async () => {
|
||||||
|
|||||||
@@ -242,26 +242,6 @@ describe('getArchitectureOptions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
let spyPackageDetails: any;
|
|
||||||
|
|
||||||
const ZULU_CHECKSUM = 'a'.repeat(64);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// The resolved winning package fetches sha256_hash from the Azul
|
|
||||||
// package-details endpoint; stub it so tests never reach the real
|
|
||||||
// network.
|
|
||||||
spyPackageDetails = jest.spyOn(HttpClient.prototype, 'getJson');
|
|
||||||
spyPackageDetails.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: {sha256_hash: ZULU_CHECKSUM}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['8', '8.0.282+8'],
|
['8', '8.0.282+8'],
|
||||||
['11.x', '11.0.10+9'],
|
['11.x', '11.0.10+9'],
|
||||||
@@ -300,38 +280,6 @@ describe('findPackageForDownload', () => {
|
|||||||
expect(result.url).toBe(
|
expect(result.url).toBe(
|
||||||
'https://cdn.azul.com/zulu/bin/zulu17.48.15-ca-jdk17.0.10-windows_aarch64.zip'
|
'https://cdn.azul.com/zulu/bin/zulu17.48.15-ca-jdk17.0.10-windows_aarch64.zip'
|
||||||
);
|
);
|
||||||
expect(result.checksum).toEqual({
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: ZULU_CHECKSUM,
|
|
||||||
source: 'https://api.azul.com/metadata/v1/zulu/packages/test-uuid-12446'
|
|
||||||
});
|
|
||||||
// Only the winning package's UUID triggers a details request.
|
|
||||||
expect(spyPackageDetails).toHaveBeenCalledWith(
|
|
||||||
'https://api.azul.com/metadata/v1/zulu/packages/test-uuid-12446'
|
|
||||||
);
|
|
||||||
expect(spyPackageDetails).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('skips checksum verification when sha256_hash is missing or malformed', async () => {
|
|
||||||
spyPackageDetails.mockResolvedValue({
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {},
|
|
||||||
result: {sha256_hash: '123'}
|
|
||||||
});
|
|
||||||
|
|
||||||
const distribution = new ZuluDistribution({
|
|
||||||
version: '',
|
|
||||||
architecture: 'arm64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
distribution['getAvailableVersions'] = async () => manifestData;
|
|
||||||
const result = await distribution['findPackageForDownload']('17.0.10');
|
|
||||||
|
|
||||||
expect(result.checksum).toBeUndefined();
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining('No authoritative sha256 checksum')
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error', async () => {
|
it('should throw an error', async () => {
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import {
|
|
||||||
JAVA_PACKAGE_CAPABILITIES,
|
|
||||||
JavaDistribution
|
|
||||||
} from '../src/distributions/package-types.js';
|
|
||||||
|
|
||||||
const repositoryRoot = process.cwd();
|
|
||||||
const readRepositoryFile = (filePath: string) =>
|
|
||||||
fs.readFileSync(path.join(repositoryRoot, filePath), 'utf8');
|
|
||||||
const allPackageTypes = [
|
|
||||||
...new Set(Object.values(JAVA_PACKAGE_CAPABILITIES).flat())
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('java-package published contract', () => {
|
|
||||||
it.each(['action.yml', 'README.md'])(
|
|
||||||
'documents every supported package type in %s',
|
|
||||||
filePath => {
|
|
||||||
const content = readRepositoryFile(filePath);
|
|
||||||
const contractLine =
|
|
||||||
filePath === 'action.yml'
|
|
||||||
? content.match(/ {2}java-package:\n(?: {4}.+\n)+/)?.[0]
|
|
||||||
: content
|
|
||||||
.split('\n')
|
|
||||||
.find(line => line.includes('- `java-package`:'));
|
|
||||||
|
|
||||||
expect(contractLine).toBeDefined();
|
|
||||||
for (const packageType of allPackageTypes) {
|
|
||||||
expect(contractLine).toContain(`\`${packageType}\``);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it.each(Object.entries(JAVA_PACKAGE_CAPABILITIES))(
|
|
||||||
'keeps the advanced compatibility table aligned for %s',
|
|
||||||
(distributionName, packageTypes) => {
|
|
||||||
const advancedUsage = readRepositoryFile('docs/advanced-usage.md');
|
|
||||||
const compatibilityTable = advancedUsage.slice(
|
|
||||||
advancedUsage.indexOf('### Package compatibility')
|
|
||||||
);
|
|
||||||
const compatibilityRow = compatibilityTable
|
|
||||||
.split('\n')
|
|
||||||
.find(
|
|
||||||
line =>
|
|
||||||
line.startsWith('|') && line.includes(`\`${distributionName}\``)
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(compatibilityRow).toBeDefined();
|
|
||||||
for (const packageType of packageTypes) {
|
|
||||||
expect(compatibilityRow).toContain(`\`${packageType}\``);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('only exercises supported distribution/package combinations in E2E', () => {
|
|
||||||
const workflow = readRepositoryFile('.github/workflows/e2e-versions.yml');
|
|
||||||
const defaultMatrix = workflow.match(
|
|
||||||
/distribution:\s*\n\s*\[([^\]]+)\]\s*\n\s*java-package:\s*\['([^']+)'\]/
|
|
||||||
);
|
|
||||||
expect(defaultMatrix).not.toBeNull();
|
|
||||||
|
|
||||||
const defaultDistributions = [
|
|
||||||
...defaultMatrix![1].matchAll(/'([^']+)'/g)
|
|
||||||
].map(match => match[1]);
|
|
||||||
const defaultPackage = defaultMatrix![2];
|
|
||||||
for (const distributionName of defaultDistributions) {
|
|
||||||
expect(supportedPackagesFor(distributionName)).toContain(defaultPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
const includedPackages = workflow.matchAll(
|
|
||||||
/- distribution: '([^']+)'\s*\n\s*java-package: ([^\s]+)/g
|
|
||||||
);
|
|
||||||
for (const match of includedPackages) {
|
|
||||||
const [, distributionName, packageType] = match;
|
|
||||||
expect(supportedPackagesFor(distributionName)).toContain(packageType);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function supportedPackagesFor(distributionName: string): readonly string[] {
|
|
||||||
return JAVA_PACKAGE_CAPABILITIES[distributionName as JavaDistribution] ?? [];
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import {
|
|
||||||
JAVA_PLATFORM_CAPABILITIES,
|
|
||||||
normalizeArchitecture,
|
|
||||||
validateJavaPlatform
|
|
||||||
} from '../src/distributions/platform-types.js';
|
|
||||||
import {JavaDistribution} from '../src/distributions/package-types.js';
|
|
||||||
|
|
||||||
describe('Java platform capabilities', () => {
|
|
||||||
it('declares a capability for every distribution', () => {
|
|
||||||
expect(Object.keys(JAVA_PLATFORM_CAPABILITIES).sort()).toEqual(
|
|
||||||
Object.values(JavaDistribution).sort()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
['x64', 'x64'],
|
|
||||||
['amd64', 'x64'],
|
|
||||||
['x86', 'x86'],
|
|
||||||
['ia32', 'x86'],
|
|
||||||
['arm', 'armv7'],
|
|
||||||
['aarch64', 'aarch64'],
|
|
||||||
['arm64', 'aarch64'],
|
|
||||||
['ppc64le', 'ppc64le'],
|
|
||||||
['s390x', 's390x']
|
|
||||||
])('normalizes architecture %s to %s', (input, expected) => {
|
|
||||||
expect(normalizeArchitecture(input)).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses the normalized architecture for validation', () => {
|
|
||||||
expect(validateJavaPlatform('microsoft', 'linux', 'arm64', '25')).toBe(
|
|
||||||
'aarch64'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects OS-specific restrictions with a consistent diagnostic', () => {
|
|
||||||
expect(() =>
|
|
||||||
validateJavaPlatform('oracle', 'win32', 'arm64', '21')
|
|
||||||
).toThrow(
|
|
||||||
"Distribution 'oracle' does not support operating system 'windows' with architecture 'aarch64' for Java version '21'. Supported combinations: linux (x64, aarch64); macos (x64, aarch64); windows (x64)."
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects version-dependent architecture restrictions', () => {
|
|
||||||
expect(() =>
|
|
||||||
validateJavaPlatform('corretto', 'linux', 'x86', '17')
|
|
||||||
).toThrow(/x86 \(<12\)/);
|
|
||||||
expect(() =>
|
|
||||||
validateJavaPlatform('corretto', 'linux', 'x86', '17.0.2.8.1')
|
|
||||||
).toThrow(/x86 \(<12\)/);
|
|
||||||
expect(validateJavaPlatform('corretto', 'linux', 'x86', '11')).toBe('x86');
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each(['corretto', 'kona'])(
|
|
||||||
'rejects Windows aarch64 for %s',
|
|
||||||
distributionName => {
|
|
||||||
expect(() =>
|
|
||||||
validateJavaPlatform(distributionName, 'win32', 'arm64', '21')
|
|
||||||
).toThrow(/does not support operating system 'windows'/);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('keeps Adopt HotSpot aliases aligned with the Temurin-first resolver', () => {
|
|
||||||
expect(validateJavaPlatform('adopt', 'darwin', 'arm64', '21')).toBe(
|
|
||||||
'aarch64'
|
|
||||||
);
|
|
||||||
expect(validateJavaPlatform('adopt-hotspot', 'win32', 'arm64', '21')).toBe(
|
|
||||||
'aarch64'
|
|
||||||
);
|
|
||||||
expect(() =>
|
|
||||||
validateJavaPlatform('adopt-openj9', 'darwin', 'arm64', '16')
|
|
||||||
).toThrow(/does not support operating system 'macos'/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('allows local archives on any platform and architecture', () => {
|
|
||||||
expect(validateJavaPlatform('jdkfile', 'aix', 'mips64', '21')).toBe(
|
|
||||||
'mips64'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('keeps the documented architecture contract aligned', () => {
|
|
||||||
const repositoryRoot = process.cwd();
|
|
||||||
const readRepositoryFile = (filePath: string) =>
|
|
||||||
fs.readFileSync(path.join(repositoryRoot, filePath), 'utf8');
|
|
||||||
|
|
||||||
for (const filePath of ['action.yml', 'README.md']) {
|
|
||||||
const content = readRepositoryFile(filePath);
|
|
||||||
for (const architecture of [
|
|
||||||
'x86',
|
|
||||||
'x64',
|
|
||||||
'armv7',
|
|
||||||
'aarch64',
|
|
||||||
'ppc64le',
|
|
||||||
'ppc64',
|
|
||||||
's390x'
|
|
||||||
]) {
|
|
||||||
expect(content).toContain(architecture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each(Object.entries(JAVA_PLATFORM_CAPABILITIES))(
|
|
||||||
'keeps the advanced compatibility table aligned for %s',
|
|
||||||
(distributionName, capability) => {
|
|
||||||
const advancedUsage = fs.readFileSync(
|
|
||||||
path.join(process.cwd(), 'docs/advanced-usage.md'),
|
|
||||||
'utf8'
|
|
||||||
);
|
|
||||||
const compatibilityTable = advancedUsage.slice(
|
|
||||||
advancedUsage.indexOf('## Platform and architecture compatibility')
|
|
||||||
);
|
|
||||||
const compatibilityRow = compatibilityTable
|
|
||||||
.split('\n')
|
|
||||||
.find(
|
|
||||||
line =>
|
|
||||||
line.startsWith('|') && line.includes(`\`${distributionName}\``)
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(compatibilityRow).toBeDefined();
|
|
||||||
if (!('platforms' in capability)) {
|
|
||||||
expect(compatibilityRow).toContain('Any');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const architectures = new Set(
|
|
||||||
Object.values(capability.platforms)
|
|
||||||
.flat()
|
|
||||||
.map(item => (typeof item === 'string' ? item : item.architecture))
|
|
||||||
);
|
|
||||||
for (const architecture of architectures) {
|
|
||||||
expect(compatibilityRow).toContain(`\`${architecture}\``);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -1,251 +0,0 @@
|
|||||||
import {jest, describe, it, expect, beforeEach, afterEach} from '@jest/globals';
|
|
||||||
import type {IncomingMessage} from 'http';
|
|
||||||
|
|
||||||
jest.unstable_mockModule('@actions/core', () => ({
|
|
||||||
info: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
const core = await import('@actions/core');
|
|
||||||
const httpm = await import('@actions/http-client');
|
|
||||||
const {RetryingHttpClient, isRetryableNetworkError, parseRetryAfter} =
|
|
||||||
await import('../src/retrying-http-client.js');
|
|
||||||
|
|
||||||
function response(
|
|
||||||
statusCode: number,
|
|
||||||
retryAfter?: string
|
|
||||||
): httpm.HttpClientResponse {
|
|
||||||
return {
|
|
||||||
message: {
|
|
||||||
statusCode,
|
|
||||||
headers: retryAfter ? {'retry-after': retryAfter} : {}
|
|
||||||
} as IncomingMessage,
|
|
||||||
readBody: jest.fn(async () => '')
|
|
||||||
} as unknown as httpm.HttpClientResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('RetryingHttpClient', () => {
|
|
||||||
let request: ReturnType<typeof jest.spyOn>;
|
|
||||||
let sleep: jest.Mock<(delayMs: number) => Promise<void>>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
request = jest.spyOn(httpm.HttpClient.prototype, 'request');
|
|
||||||
sleep = jest.fn(async () => undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses exponential backoff with jitter for retryable responses', async () => {
|
|
||||||
request
|
|
||||||
.mockResolvedValueOnce(response(503))
|
|
||||||
.mockResolvedValueOnce(response(502))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0,
|
|
||||||
baseDelayMs: 1000,
|
|
||||||
maxDelayMs: 10000
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(client.get('https://example.com')).resolves.toBeDefined();
|
|
||||||
|
|
||||||
expect(request).toHaveBeenCalledTimes(3);
|
|
||||||
expect(sleep).toHaveBeenNthCalledWith(1, 500);
|
|
||||||
expect(sleep).toHaveBeenNthCalledWith(2, 1000);
|
|
||||||
expect(core.info).toHaveBeenNthCalledWith(
|
|
||||||
1,
|
|
||||||
'Request attempt 1 of 4 failed (HTTP 503); retrying in 500 ms'
|
|
||||||
);
|
|
||||||
expect(core.info).toHaveBeenNthCalledWith(
|
|
||||||
2,
|
|
||||||
'Request attempt 2 of 4 failed (HTTP 502); retrying in 1000 ms'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('honors Retry-After delta-seconds over the client delay', async () => {
|
|
||||||
request
|
|
||||||
.mockResolvedValueOnce(response(429, '3'))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(sleep).toHaveBeenCalledWith(3000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('honors Retry-After HTTP dates over the client delay', async () => {
|
|
||||||
const now = Date.parse('2026-07-29T00:00:00Z');
|
|
||||||
request
|
|
||||||
.mockResolvedValueOnce(response(503, new Date(now + 5000).toUTCString()))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0,
|
|
||||||
now: () => now
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(sleep).toHaveBeenCalledWith(5000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('caps Retry-After at the configured maximum delay', async () => {
|
|
||||||
request
|
|
||||||
.mockResolvedValueOnce(response(429, '60'))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0,
|
|
||||||
maxDelayMs: 10000
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(sleep).toHaveBeenCalledWith(10000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([429, 502, 503, 504, 522])(
|
|
||||||
'retries HTTP %s responses',
|
|
||||||
async statusCode => {
|
|
||||||
request
|
|
||||||
.mockResolvedValueOnce(response(statusCode))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(request).toHaveBeenCalledTimes(2);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it.each(['ETIMEDOUT', 'ECONNRESET', 'ENOTFOUND', 'ECONNREFUSED'])(
|
|
||||||
'retries network errors with code %s',
|
|
||||||
async code => {
|
|
||||||
request
|
|
||||||
.mockRejectedValueOnce(Object.assign(new Error(code), {code}))
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(request).toHaveBeenCalledTimes(2);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('retries retryable aggregate network errors', async () => {
|
|
||||||
const aggregateError = Object.assign(new Error('connection failed'), {
|
|
||||||
errors: [Object.assign(new Error('timed out'), {code: 'ETIMEDOUT'})]
|
|
||||||
});
|
|
||||||
request
|
|
||||||
.mockRejectedValueOnce(aggregateError)
|
|
||||||
.mockResolvedValueOnce(response(200));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(request).toHaveBeenCalledTimes(2);
|
|
||||||
expect(sleep).toHaveBeenCalledWith(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not retry non-retryable responses or network errors', async () => {
|
|
||||||
request.mockResolvedValueOnce(response(500));
|
|
||||||
const client = new RetryingHttpClient('test', {sleep});
|
|
||||||
|
|
||||||
await expect(client.get('https://example.com')).resolves.toBeDefined();
|
|
||||||
expect(request).toHaveBeenCalledTimes(1);
|
|
||||||
expect(sleep).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
request.mockRejectedValueOnce(
|
|
||||||
Object.assign(new Error('certificate failed'), {code: 'CERT_HAS_EXPIRED'})
|
|
||||||
);
|
|
||||||
await expect(client.get('https://example.com')).rejects.toThrow(
|
|
||||||
'certificate failed'
|
|
||||||
);
|
|
||||||
expect(request).toHaveBeenCalledTimes(2);
|
|
||||||
expect(sleep).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('stops after the configured total attempt count', async () => {
|
|
||||||
request
|
|
||||||
.mockResolvedValueOnce(response(503))
|
|
||||||
.mockResolvedValueOnce(response(503));
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
maxAttempts: 2,
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
const finalResponse = await client.get('https://example.com');
|
|
||||||
|
|
||||||
expect(finalResponse.message.statusCode).toBe(503);
|
|
||||||
expect(request).toHaveBeenCalledTimes(2);
|
|
||||||
expect(sleep).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('propagates the final network error after exhausting attempts', async () => {
|
|
||||||
const finalError = Object.assign(new Error('still unavailable'), {
|
|
||||||
code: 'ECONNREFUSED'
|
|
||||||
});
|
|
||||||
request
|
|
||||||
.mockRejectedValueOnce(
|
|
||||||
Object.assign(new Error('unavailable'), {code: 'ECONNREFUSED'})
|
|
||||||
)
|
|
||||||
.mockRejectedValueOnce(finalError);
|
|
||||||
const client = new RetryingHttpClient('test', {
|
|
||||||
maxAttempts: 2,
|
|
||||||
sleep,
|
|
||||||
random: () => 0
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(client.get('https://example.com')).rejects.toBe(finalError);
|
|
||||||
|
|
||||||
expect(request).toHaveBeenCalledTimes(2);
|
|
||||||
expect(sleep).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not retry write requests', async () => {
|
|
||||||
request.mockResolvedValueOnce(response(503));
|
|
||||||
const client = new RetryingHttpClient('test', {sleep});
|
|
||||||
|
|
||||||
await client.post('https://example.com', '{}');
|
|
||||||
|
|
||||||
expect(request).toHaveBeenCalledTimes(1);
|
|
||||||
expect(sleep).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('retry classification', () => {
|
|
||||||
it('parses valid Retry-After values and ignores invalid or past values', () => {
|
|
||||||
const now = Date.parse('2026-07-29T00:00:00Z');
|
|
||||||
|
|
||||||
expect(parseRetryAfter('7', now)).toBe(7000);
|
|
||||||
expect(parseRetryAfter(new Date(now + 3000).toUTCString(), now)).toBe(3000);
|
|
||||||
expect(parseRetryAfter(new Date(now - 3000).toUTCString(), now)).toBe(
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
expect(parseRetryAfter('not-a-date', now)).toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('recognizes direct and nested retryable network error codes', () => {
|
|
||||||
expect(isRetryableNetworkError({code: 'ECONNRESET'})).toBe(true);
|
|
||||||
expect(
|
|
||||||
isRetryableNetworkError({errors: [{code: 'ENOTFOUND'}, {code: 'OTHER'}]})
|
|
||||||
).toBe(true);
|
|
||||||
expect(isRetryableNetworkError({code: 'CERT_HAS_EXPIRED'})).toBe(false);
|
|
||||||
expect(isRetryableNetworkError(new Error('unknown'))).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,416 +0,0 @@
|
|||||||
import {jest, describe, it, expect, beforeEach} from '@jest/globals';
|
|
||||||
|
|
||||||
jest.unstable_mockModule('@actions/core', () => ({
|
|
||||||
info: jest.fn(),
|
|
||||||
warning: jest.fn(),
|
|
||||||
debug: jest.fn(),
|
|
||||||
error: jest.fn(),
|
|
||||||
notice: jest.fn(),
|
|
||||||
setFailed: jest.fn(),
|
|
||||||
setOutput: jest.fn(),
|
|
||||||
getInput: jest.fn(),
|
|
||||||
getBooleanInput: jest.fn(),
|
|
||||||
getMultilineInput: jest.fn(),
|
|
||||||
addPath: jest.fn(),
|
|
||||||
exportVariable: jest.fn(),
|
|
||||||
saveState: jest.fn(),
|
|
||||||
getState: jest.fn(),
|
|
||||||
setSecret: jest.fn(),
|
|
||||||
isDebug: jest.fn(() => false),
|
|
||||||
startGroup: jest.fn(),
|
|
||||||
endGroup: jest.fn(),
|
|
||||||
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
|
|
||||||
toPlatformPath: jest.fn((value: string) => value),
|
|
||||||
toWin32Path: jest.fn((value: string) => value),
|
|
||||||
toPosixPath: jest.fn((value: string) => value)
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule('fs', () => ({
|
|
||||||
default: {
|
|
||||||
readFileSync: jest.fn()
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule('../src/util.js', () => ({
|
|
||||||
getBooleanInput: jest.fn(),
|
|
||||||
isCacheFeatureAvailable: jest.fn(),
|
|
||||||
getVersionFromFileContent: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule('../src/toolchains.js', () => ({
|
|
||||||
validateToolchainIds: jest.fn(),
|
|
||||||
configureToolchains: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule('../src/cache.js', () => ({
|
|
||||||
restore: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule(
|
|
||||||
'../src/distributions/distribution-factory.js',
|
|
||||||
() => ({
|
|
||||||
getJavaDistribution: jest.fn()
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
jest.unstable_mockModule('../src/auth.js', () => ({
|
|
||||||
configureAuthentication: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule('../src/maven-args.js', () => ({
|
|
||||||
configureMavenArgs: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.unstable_mockModule('../src/problem-matcher.js', () => ({
|
|
||||||
configureProblemMatcher: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
const core = await import('@actions/core');
|
|
||||||
const fs = (await import('fs')).default;
|
|
||||||
const util = await import('../src/util.js');
|
|
||||||
const toolchains = await import('../src/toolchains.js');
|
|
||||||
const cache = await import('../src/cache.js');
|
|
||||||
const factory = await import('../src/distributions/distribution-factory.js');
|
|
||||||
const auth = await import('../src/auth.js');
|
|
||||||
const mavenArgs = await import('../src/maven-args.js');
|
|
||||||
const problemMatcher = await import('../src/problem-matcher.js');
|
|
||||||
const {run} = await import('../src/setup-java.js');
|
|
||||||
|
|
||||||
const inputCallsOnImport = (core.getInput as jest.Mock).mock.calls.length;
|
|
||||||
const multilineInputCallsOnImport = (core.getMultilineInput as jest.Mock).mock
|
|
||||||
.calls.length;
|
|
||||||
|
|
||||||
describe('setup action orchestration', () => {
|
|
||||||
const inputs = new Map<string, string>();
|
|
||||||
const multilineInputs = new Map<string, string[]>();
|
|
||||||
const booleanInputs = new Map<string, boolean>();
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
inputs.clear();
|
|
||||||
multilineInputs.clear();
|
|
||||||
booleanInputs.clear();
|
|
||||||
|
|
||||||
(core.getInput as jest.Mock).mockImplementation((name: unknown) => {
|
|
||||||
return inputs.get(name as string) ?? '';
|
|
||||||
});
|
|
||||||
(core.getMultilineInput as jest.Mock).mockImplementation(
|
|
||||||
(name: unknown) => {
|
|
||||||
return multilineInputs.get(name as string) ?? [];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
(util.getBooleanInput as jest.Mock).mockImplementation(
|
|
||||||
(name: unknown, defaultValue: unknown) => {
|
|
||||||
return booleanInputs.get(name as string) ?? defaultValue;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
(util.isCacheFeatureAvailable as jest.Mock).mockReturnValue(true);
|
|
||||||
(toolchains.configureToolchains as jest.Mock).mockResolvedValue(undefined);
|
|
||||||
(auth.configureAuthentication as jest.Mock).mockResolvedValue(undefined);
|
|
||||||
(cache.restore as jest.Mock).mockResolvedValue(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not execute the action when imported', () => {
|
|
||||||
expect(inputCallsOnImport).toBe(0);
|
|
||||||
expect(multilineInputCallsOnImport).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires java-version or java-version-file', async () => {
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
|
||||||
'java-version or java-version-file input expected'
|
|
||||||
);
|
|
||||||
expect(factory.getJavaDistribution).not.toHaveBeenCalled();
|
|
||||||
expect(problemMatcher.configureProblemMatcher).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires distribution when java-version is provided', async () => {
|
|
||||||
multilineInputs.set('java-version', ['21']);
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
|
||||||
'distribution input is required'
|
|
||||||
);
|
|
||||||
expect(factory.getJavaDistribution).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires distribution when it cannot be inferred from the version file', async () => {
|
|
||||||
inputs.set('java-version-file', '.java-version');
|
|
||||||
(fs.readFileSync as jest.Mock).mockReturnValue(Buffer.from('21'));
|
|
||||||
(util.getVersionFromFileContent as jest.Mock).mockReturnValue({
|
|
||||||
version: '21'
|
|
||||||
});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
|
||||||
'distribution input is required when not specified in the version file'
|
|
||||||
);
|
|
||||||
expect(factory.getJavaDistribution).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails when the version file has no supported version', async () => {
|
|
||||||
inputs.set('java-version-file', '.java-version');
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
(fs.readFileSync as jest.Mock).mockReturnValue(Buffer.from('invalid'));
|
|
||||||
(util.getVersionFromFileContent as jest.Mock).mockReturnValue(undefined);
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
|
||||||
'No supported version was found in file .java-version'
|
|
||||||
);
|
|
||||||
expect(factory.getJavaDistribution).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses the distribution inferred from a version file', async () => {
|
|
||||||
inputs.set('java-version-file', '.sdkmanrc');
|
|
||||||
inputs.set('architecture', 'x64');
|
|
||||||
inputs.set('java-package', 'jdk');
|
|
||||||
inputs.set('distribution', 'zulu');
|
|
||||||
inputs.set('jdk-file', '/tmp/java.tar.gz');
|
|
||||||
multilineInputs.set('mvn-toolchain-id', ['file-jdk']);
|
|
||||||
booleanInputs.set('check-latest', true);
|
|
||||||
booleanInputs.set('force-download', true);
|
|
||||||
booleanInputs.set('set-default', false);
|
|
||||||
booleanInputs.set('verify-signature', true);
|
|
||||||
inputs.set('verify-signature-public-key', 'public-key');
|
|
||||||
(fs.readFileSync as jest.Mock).mockReturnValue(
|
|
||||||
Buffer.from('java=21.0.5-tem')
|
|
||||||
);
|
|
||||||
(util.getVersionFromFileContent as jest.Mock).mockReturnValue({
|
|
||||||
version: '21.0.5',
|
|
||||||
distribution: 'temurin'
|
|
||||||
});
|
|
||||||
const setupJava = jest.fn(async () => ({
|
|
||||||
version: '21.0.5+11',
|
|
||||||
path: '/opt/java/21'
|
|
||||||
}));
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue({setupJava});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(util.getVersionFromFileContent).toHaveBeenCalledWith(
|
|
||||||
'java=21.0.5-tem',
|
|
||||||
'zulu',
|
|
||||||
'.sdkmanrc'
|
|
||||||
);
|
|
||||||
expect(factory.getJavaDistribution).toHaveBeenCalledWith(
|
|
||||||
'temurin',
|
|
||||||
{
|
|
||||||
version: '21.0.5',
|
|
||||||
architecture: 'x64',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: true,
|
|
||||||
forceDownload: true,
|
|
||||||
setDefault: false,
|
|
||||||
verifySignature: true,
|
|
||||||
verifySignaturePublicKey: 'public-key'
|
|
||||||
},
|
|
||||||
'/tmp/java.tar.gz'
|
|
||||||
);
|
|
||||||
expect(toolchains.validateToolchainIds).toHaveBeenCalledWith(
|
|
||||||
[],
|
|
||||||
'.sdkmanrc',
|
|
||||||
['file-jdk']
|
|
||||||
);
|
|
||||||
expect(toolchains.configureToolchains).toHaveBeenCalledWith(
|
|
||||||
'21.0.5',
|
|
||||||
'temurin',
|
|
||||||
'/opt/java/21',
|
|
||||||
'file-jdk'
|
|
||||||
);
|
|
||||||
expect(core.setFailed).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('installs multiple JDKs in order with matching toolchain IDs', async () => {
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
inputs.set('architecture', 'x64');
|
|
||||||
inputs.set('java-package', 'jdk');
|
|
||||||
multilineInputs.set('java-version', ['17', '21']);
|
|
||||||
multilineInputs.set('mvn-toolchain-id', ['java-17', 'java-21']);
|
|
||||||
|
|
||||||
const setupJava17 = jest.fn(async () => ({
|
|
||||||
version: '17.0.12+7',
|
|
||||||
path: '/opt/java/17'
|
|
||||||
}));
|
|
||||||
const setupJava21 = jest.fn(async () => ({
|
|
||||||
version: '21.0.4+7',
|
|
||||||
path: '/opt/java/21'
|
|
||||||
}));
|
|
||||||
(factory.getJavaDistribution as jest.Mock)
|
|
||||||
.mockReturnValueOnce({setupJava: setupJava17})
|
|
||||||
.mockReturnValueOnce({setupJava: setupJava21});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(factory.getJavaDistribution).toHaveBeenNthCalledWith(
|
|
||||||
1,
|
|
||||||
'temurin',
|
|
||||||
expect.objectContaining({version: '17'}),
|
|
||||||
''
|
|
||||||
);
|
|
||||||
expect(factory.getJavaDistribution).toHaveBeenNthCalledWith(
|
|
||||||
2,
|
|
||||||
'temurin',
|
|
||||||
expect.objectContaining({version: '21'}),
|
|
||||||
''
|
|
||||||
);
|
|
||||||
expect(toolchains.configureToolchains).toHaveBeenNthCalledWith(
|
|
||||||
1,
|
|
||||||
'17',
|
|
||||||
'temurin',
|
|
||||||
'/opt/java/17',
|
|
||||||
'java-17'
|
|
||||||
);
|
|
||||||
expect(toolchains.configureToolchains).toHaveBeenNthCalledWith(
|
|
||||||
2,
|
|
||||||
'21',
|
|
||||||
'temurin',
|
|
||||||
'/opt/java/21',
|
|
||||||
'java-21'
|
|
||||||
);
|
|
||||||
expect(setupJava17.mock.invocationCallOrder[0]).toBeLessThan(
|
|
||||||
setupJava21.mock.invocationCallOrder[0]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses the resolved version for the latest Maven toolchain', async () => {
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
multilineInputs.set('java-version', ['latest']);
|
|
||||||
const setupJava = jest.fn(async () => ({
|
|
||||||
version: '24.0.2+12',
|
|
||||||
path: '/opt/java/24'
|
|
||||||
}));
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue({setupJava});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(toolchains.configureToolchains).toHaveBeenCalledWith(
|
|
||||||
'24.0.2+12',
|
|
||||||
'temurin',
|
|
||||||
'/opt/java/24',
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('configures post-install collaborators in order and restores the cache last', async () => {
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
inputs.set('cache', 'maven');
|
|
||||||
inputs.set('cache-dependency-path', '**/pom.xml');
|
|
||||||
multilineInputs.set('java-version', ['21']);
|
|
||||||
multilineInputs.set('cache-path', [
|
|
||||||
'/custom/maven/repository',
|
|
||||||
'!/custom/maven/repository/excluded'
|
|
||||||
]);
|
|
||||||
const setupJava = jest.fn(async () => ({
|
|
||||||
version: '21.0.4+7',
|
|
||||||
path: '/opt/java/21'
|
|
||||||
}));
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue({setupJava});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(problemMatcher.configureProblemMatcher).toHaveBeenCalledWith(
|
|
||||||
expect.stringMatching(/\.github[/\\]java\.json$/)
|
|
||||||
);
|
|
||||||
expect(cache.restore).toHaveBeenCalledWith('maven', '**/pom.xml', [
|
|
||||||
'/custom/maven/repository',
|
|
||||||
'!/custom/maven/repository/excluded'
|
|
||||||
]);
|
|
||||||
expect(
|
|
||||||
(toolchains.configureToolchains as jest.Mock).mock.invocationCallOrder[0]
|
|
||||||
).toBeLessThan(
|
|
||||||
(problemMatcher.configureProblemMatcher as jest.Mock).mock
|
|
||||||
.invocationCallOrder[0]
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
(problemMatcher.configureProblemMatcher as jest.Mock).mock
|
|
||||||
.invocationCallOrder[0]
|
|
||||||
).toBeLessThan(
|
|
||||||
(auth.configureAuthentication as jest.Mock).mock.invocationCallOrder[0]
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
(auth.configureAuthentication as jest.Mock).mock.invocationCallOrder[0]
|
|
||||||
).toBeLessThan(
|
|
||||||
(mavenArgs.configureMavenArgs as jest.Mock).mock.invocationCallOrder[0]
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
(mavenArgs.configureMavenArgs as jest.Mock).mock.invocationCallOrder[0]
|
|
||||||
).toBeLessThan((cache.restore as jest.Mock).mock.invocationCallOrder[0]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('skips cache restoration when the cache feature is unavailable', async () => {
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
inputs.set('cache', 'maven');
|
|
||||||
multilineInputs.set('java-version', ['21']);
|
|
||||||
(util.isCacheFeatureAvailable as jest.Mock).mockReturnValue(false);
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue({
|
|
||||||
setupJava: jest.fn(async () => ({
|
|
||||||
version: '21.0.4+7',
|
|
||||||
path: '/opt/java/21'
|
|
||||||
}))
|
|
||||||
});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(cache.restore).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reports unsupported distributions through core.setFailed', async () => {
|
|
||||||
inputs.set('distribution', 'unsupported');
|
|
||||||
multilineInputs.set('java-version', ['21']);
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue(null);
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
|
||||||
'No supported distribution was found for input unsupported'
|
|
||||||
);
|
|
||||||
expect(toolchains.configureToolchains).not.toHaveBeenCalled();
|
|
||||||
expect(problemMatcher.configureProblemMatcher).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reports collaborator failures and stops post-install configuration', async () => {
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
multilineInputs.set('java-version', ['21']);
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue({
|
|
||||||
setupJava: jest.fn(async () => {
|
|
||||||
throw new Error('download failed');
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith('download failed');
|
|
||||||
expect(toolchains.configureToolchains).not.toHaveBeenCalled();
|
|
||||||
expect(problemMatcher.configureProblemMatcher).not.toHaveBeenCalled();
|
|
||||||
expect(auth.configureAuthentication).not.toHaveBeenCalled();
|
|
||||||
expect(mavenArgs.configureMavenArgs).not.toHaveBeenCalled();
|
|
||||||
expect(cache.restore).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reports post-install failures and skips later collaborators', async () => {
|
|
||||||
inputs.set('distribution', 'temurin');
|
|
||||||
inputs.set('cache', 'maven');
|
|
||||||
multilineInputs.set('java-version', ['21']);
|
|
||||||
(factory.getJavaDistribution as jest.Mock).mockReturnValue({
|
|
||||||
setupJava: jest.fn(async () => ({
|
|
||||||
version: '21.0.4+7',
|
|
||||||
path: '/opt/java/21'
|
|
||||||
}))
|
|
||||||
});
|
|
||||||
(auth.configureAuthentication as jest.Mock).mockRejectedValue(
|
|
||||||
new Error('authentication failed')
|
|
||||||
);
|
|
||||||
|
|
||||||
await run();
|
|
||||||
|
|
||||||
expect(problemMatcher.configureProblemMatcher).toHaveBeenCalled();
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith('authentication failed');
|
|
||||||
expect(mavenArgs.configureMavenArgs).not.toHaveBeenCalled();
|
|
||||||
expect(cache.restore).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1007,67 +1007,3 @@ describe('toolchains tests', () => {
|
|||||||
expect((contents.match(/<toolchain>/g) || []).length).toBe(runs.length);
|
expect((contents.match(/<toolchain>/g) || []).length).toBe(runs.length);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateToolchainIds', () => {
|
|
||||||
it.each([
|
|
||||||
{
|
|
||||||
name: 'uses generated IDs when no custom IDs are supplied',
|
|
||||||
versions: ['17', '21'],
|
|
||||||
versionFile: '',
|
|
||||||
toolchainIds: []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'accepts one custom ID for a single Java version',
|
|
||||||
versions: ['21'],
|
|
||||||
versionFile: '',
|
|
||||||
toolchainIds: ['custom-21']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'accepts one custom ID per Java version',
|
|
||||||
versions: ['17', '21'],
|
|
||||||
versionFile: '',
|
|
||||||
toolchainIds: ['custom-17', 'custom-21']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'accepts one custom ID with java-version-file',
|
|
||||||
versions: [],
|
|
||||||
versionFile: '.java-version',
|
|
||||||
toolchainIds: ['custom-file-version']
|
|
||||||
}
|
|
||||||
])('$name', ({versions, versionFile, toolchainIds}) => {
|
|
||||||
expect(() =>
|
|
||||||
toolchains.validateToolchainIds(versions, versionFile, toolchainIds)
|
|
||||||
).not.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
{
|
|
||||||
name: 'rejects fewer IDs than Java versions',
|
|
||||||
versions: ['17', '21'],
|
|
||||||
versionFile: '',
|
|
||||||
toolchainIds: ['custom-17'],
|
|
||||||
expectedMessage:
|
|
||||||
'The number of Maven toolchain IDs (1) must match the number of Java versions (2)'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'rejects extra IDs for a single Java version',
|
|
||||||
versions: ['21'],
|
|
||||||
versionFile: '',
|
|
||||||
toolchainIds: ['custom-21', 'custom-extra'],
|
|
||||||
expectedMessage:
|
|
||||||
'The number of Maven toolchain IDs (2) must match the number of Java versions (1)'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'rejects extra IDs with java-version-file',
|
|
||||||
versions: [],
|
|
||||||
versionFile: '.java-version',
|
|
||||||
toolchainIds: ['custom-file-version', 'custom-extra'],
|
|
||||||
expectedMessage:
|
|
||||||
'The number of Maven toolchain IDs (2) must match the number of Java versions (1)'
|
|
||||||
}
|
|
||||||
])('$name', ({versions, versionFile, toolchainIds, expectedMessage}) => {
|
|
||||||
expect(() =>
|
|
||||||
toolchains.validateToolchainIds(versions, versionFile, toolchainIds)
|
|
||||||
).toThrow(expectedMessage);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -57,73 +57,9 @@ const {
|
|||||||
isCacheFeatureAvailable,
|
isCacheFeatureAvailable,
|
||||||
isGhes,
|
isGhes,
|
||||||
validatePaginationUrl,
|
validatePaginationUrl,
|
||||||
getLatestMajorVersion,
|
getLatestMajorVersion
|
||||||
getBooleanInput
|
|
||||||
} = await import('../src/util.js');
|
} = await import('../src/util.js');
|
||||||
|
|
||||||
describe('getBooleanInput', () => {
|
|
||||||
let inputs: Record<string, string>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
inputs = {};
|
|
||||||
(core.getInput as jest.Mock).mockImplementation(
|
|
||||||
(name: string) => inputs[name] ?? ''
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
['true', true],
|
|
||||||
['TRUE', true],
|
|
||||||
['TrUe', true],
|
|
||||||
[' true ', true],
|
|
||||||
['false', false],
|
|
||||||
['FALSE', false],
|
|
||||||
['FaLsE', false],
|
|
||||||
[' false ', false]
|
|
||||||
])('parses %j as %s', (value: string, expected: boolean) => {
|
|
||||||
inputs['boolean-input'] = value;
|
|
||||||
|
|
||||||
expect(getBooleanInput('boolean-input')).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
[undefined, false],
|
|
||||||
[false, false],
|
|
||||||
[true, true]
|
|
||||||
])(
|
|
||||||
'uses the configured default %s when the input is omitted',
|
|
||||||
(defaultValue: boolean | undefined, expected: boolean) => {
|
|
||||||
expect(getBooleanInput('boolean-input', defaultValue)).toBe(expected);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('uses the configured default for a whitespace-only input', () => {
|
|
||||||
inputs['boolean-input'] = ' ';
|
|
||||||
|
|
||||||
expect(getBooleanInput('boolean-input', true)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
'check-latest',
|
|
||||||
'force-download',
|
|
||||||
'set-default',
|
|
||||||
'verify-signature',
|
|
||||||
'overwrite-settings',
|
|
||||||
'show-download-progress',
|
|
||||||
'problem-matcher'
|
|
||||||
])('rejects an invalid value for %s', inputName => {
|
|
||||||
inputs[inputName] = 'ture';
|
|
||||||
|
|
||||||
expect(() => getBooleanInput(inputName)).toThrow(
|
|
||||||
`Invalid value 'ture' for boolean input '${inputName}'. Expected 'true' or 'false'.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isVersionSatisfies', () => {
|
describe('isVersionSatisfies', () => {
|
||||||
it.each([
|
it.each([
|
||||||
['x', '11.0.0', true],
|
['x', '11.0.0', true],
|
||||||
|
|||||||
13
action.yml
13
action.yml
@@ -13,11 +13,11 @@ inputs:
|
|||||||
description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
|
description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
|
||||||
required: false
|
required: false
|
||||||
java-package:
|
java-package:
|
||||||
description: 'The package type (`jdk`, `jre`, `jdk+fx`, `jre+fx`, `jdk+crac`, `jre+crac`, `jdk+jmods`, `jdk+jcef`, `jre+jcef`, `jdk+ft`, or `jre+ft`). Supported values vary by distribution.'
|
description: 'The package type (jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac, jdk+jmods)'
|
||||||
required: false
|
required: false
|
||||||
default: 'jdk'
|
default: 'jdk'
|
||||||
architecture:
|
architecture:
|
||||||
description: "The architecture of the package (`x86`, `x64`, `armv7`, `aarch64`, `ppc64le`, `ppc64`, or `s390x`). Aliases `ia32`, `amd64`, `arm`, and `arm64` are normalized to `x86`, `x64`, `armv7`, and `aarch64`. Supported values vary by distribution and operating system. Defaults to the action runner's architecture."
|
description: "The architecture of the package (defaults to the action runner's architecture)"
|
||||||
required: false
|
required: false
|
||||||
jdk-file:
|
jdk-file:
|
||||||
description: 'Path to where the compressed JDK is located'
|
description: 'Path to where the compressed JDK is located'
|
||||||
@@ -87,13 +87,6 @@ inputs:
|
|||||||
cache-dependency-path:
|
cache-dependency-path:
|
||||||
description: 'The path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.'
|
description: 'The path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.'
|
||||||
required: false
|
required: false
|
||||||
cache-path:
|
|
||||||
description: 'The path to cache instead of the default dependency cache path for the selected package manager. This option can be used with the `cache` option and supports a list of paths and exclusion patterns.'
|
|
||||||
required: false
|
|
||||||
cache-read-only:
|
|
||||||
description: 'Restore dependency caches without saving cache changes in the post action.'
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
job-status:
|
job-status:
|
||||||
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
|
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
|
||||||
required: false
|
required: false
|
||||||
@@ -103,7 +96,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||||
mvn-toolchain-id:
|
mvn-toolchain-id:
|
||||||
description: 'Name of Maven Toolchain ID if the default name of "${distribution}_${java-version}" is not wanted. When supplied, the number of IDs must match the number of Java versions. See examples of supported syntax in Advanced Usage file'
|
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
|
required: false
|
||||||
mvn-toolchain-vendor:
|
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'
|
description: 'Name of Maven Toolchain Vendor if the default name of "${distribution}" is not wanted. See examples of supported syntax in Advanced Usage file'
|
||||||
|
|||||||
113
dist/cleanup/index.js
vendored
113
dist/cleanup/index.js
vendored
@@ -97338,8 +97338,6 @@ const MAVEN_GPG_PASSPHRASE_DEFAULT_ENV = 'MAVEN_GPG_PASSPHRASE';
|
|||||||
const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
|
const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
|
||||||
const INPUT_CACHE = 'cache';
|
const INPUT_CACHE = 'cache';
|
||||||
const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
|
const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
|
||||||
const INPUT_CACHE_PATH = 'cache-path';
|
|
||||||
const INPUT_CACHE_READ_ONLY = 'cache-read-only';
|
|
||||||
const INPUT_JOB_STATUS = 'job-status';
|
const INPUT_JOB_STATUS = 'job-status';
|
||||||
const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
||||||
const M2_DIR = '.m2';
|
const M2_DIR = '.m2';
|
||||||
@@ -97367,18 +97365,7 @@ function getTempDir() {
|
|||||||
return tempDirectory;
|
return tempDirectory;
|
||||||
}
|
}
|
||||||
function util_getBooleanInput(inputName, defaultValue = false) {
|
function util_getBooleanInput(inputName, defaultValue = false) {
|
||||||
const inputValue = getInput(inputName);
|
return ((core.getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE');
|
||||||
const normalizedValue = inputValue.trim().toLowerCase();
|
|
||||||
if (!normalizedValue) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
if (normalizedValue === 'true') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (normalizedValue === 'false') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
throw new Error(`Invalid value '${inputValue}' for boolean input '${inputName}'. Expected 'true' or 'false'.`);
|
|
||||||
}
|
}
|
||||||
function getVersionFromToolcachePath(toolPath) {
|
function getVersionFromToolcachePath(toolPath) {
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
@@ -97772,7 +97759,6 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
|||||||
|
|
||||||
|
|
||||||
const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
||||||
const STATE_CACHE_PATHS = 'cache-paths';
|
|
||||||
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
||||||
const CACHE_KEY_PREFIX = 'setup-java';
|
const CACHE_KEY_PREFIX = 'setup-java';
|
||||||
const supportedPackageManager = [
|
const supportedPackageManager = [
|
||||||
@@ -97854,21 +97840,6 @@ function findPackageManager(id) {
|
|||||||
}
|
}
|
||||||
return packageManager;
|
return packageManager;
|
||||||
}
|
}
|
||||||
function resolveCachePaths(packageManager, cachePaths) {
|
|
||||||
return cachePaths.length > 0 ? cachePaths : packageManager.path;
|
|
||||||
}
|
|
||||||
function getCachePathsFromState(packageManager) {
|
|
||||||
const cachePathsState = getState(STATE_CACHE_PATHS);
|
|
||||||
if (!cachePathsState) {
|
|
||||||
return packageManager.path;
|
|
||||||
}
|
|
||||||
const cachePaths = JSON.parse(cachePathsState);
|
|
||||||
if (!Array.isArray(cachePaths) ||
|
|
||||||
!cachePaths.every(cachePath => typeof cachePath === 'string')) {
|
|
||||||
throw new Error('Invalid cache paths retrieved from state.');
|
|
||||||
}
|
|
||||||
return cachePaths;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* State keys used to carry an additional cache's restore-time information over
|
* State keys used to carry an additional cache's restore-time information over
|
||||||
* to the post (save) action, scoped by the additional cache name.
|
* to the post (save) action, scoped by the additional cache name.
|
||||||
@@ -97911,33 +97882,17 @@ async function computeAdditionalCacheKey(additionalCache) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Restore the dependency cache
|
* Restore the dependency cache
|
||||||
* @param id ID of the package manager, should be "maven", "gradle", or "sbt"
|
* @param id ID of the package manager, should be "maven" or "gradle"
|
||||||
* @param cacheDependencyPath The path to a dependency file
|
* @param cacheDependencyPath The path to a dependency file
|
||||||
* @param cachePaths Paths to cache instead of the package manager defaults
|
|
||||||
*/
|
*/
|
||||||
async function restore(id, cacheDependencyPath, cachePaths = []) {
|
async function restore(id, cacheDependencyPath) {
|
||||||
const packageManager = findPackageManager(id);
|
const packageManager = findPackageManager(id);
|
||||||
const resolvedCachePaths = resolveCachePaths(packageManager, cachePaths);
|
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
|
||||||
const [primaryKey, preparedAdditionalCaches] = await Promise.all([
|
|
||||||
computeCacheKey(packageManager, cacheDependencyPath),
|
|
||||||
prepareAdditionalCaches(packageManager.additionalCaches ?? [])
|
|
||||||
]);
|
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||||
core.saveState(STATE_CACHE_PATHS, JSON.stringify(resolvedCachePaths));
|
|
||||||
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||||
for (const preparedCache of preparedAdditionalCaches) {
|
|
||||||
core.debug(`${preparedCache.cache.name} primary key is ${preparedCache.primaryKey}`);
|
|
||||||
core.saveState(additionalCachePrimaryKeyState(preparedCache.cache.name), preparedCache.primaryKey);
|
|
||||||
}
|
|
||||||
await Promise.all([
|
|
||||||
restorePrimaryCache(packageManager, resolvedCachePaths, primaryKey),
|
|
||||||
...preparedAdditionalCaches.map(preparedCache => restoreAdditionalCache(preparedCache))
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
async function restorePrimaryCache(packageManager, cachePaths, primaryKey) {
|
|
||||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
// 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(cachePaths, primaryKey);
|
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||||
if (matchedKey) {
|
if (matchedKey) {
|
||||||
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||||
core.setOutput('cache-hit', matchedKey === primaryKey);
|
core.setOutput('cache-hit', matchedKey === primaryKey);
|
||||||
@@ -97947,35 +97902,29 @@ async function restorePrimaryCache(packageManager, cachePaths, primaryKey) {
|
|||||||
core.setOutput('cache-hit', false);
|
core.setOutput('cache-hit', false);
|
||||||
core.info(`${packageManager.id} cache is not found`);
|
core.info(`${packageManager.id} cache is not found`);
|
||||||
}
|
}
|
||||||
|
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
||||||
|
await restoreAdditionalCache(additionalCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Compute keys for additional caches (e.g. build-tool wrapper distributions).
|
* Restore an additional cache (e.g. a build-tool wrapper distribution) that is
|
||||||
* Additional caches without a matching configuration file are omitted.
|
* keyed independently of the main dependency cache so that it survives changes
|
||||||
|
* to volatile dependency files. Skips silently when the project does not use
|
||||||
|
* the corresponding feature.
|
||||||
*/
|
*/
|
||||||
async function prepareAdditionalCaches(additionalCaches) {
|
async function restoreAdditionalCache(additionalCache) {
|
||||||
const preparedCaches = await Promise.all(additionalCaches.map(async (additionalCache) => {
|
const primaryKey = await computeAdditionalCacheKey(additionalCache);
|
||||||
const primaryKey = await computeAdditionalCacheKey(additionalCache);
|
if (!primaryKey) {
|
||||||
if (!primaryKey) {
|
core.debug(`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`);
|
||||||
core.debug(`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`);
|
return;
|
||||||
return undefined;
|
}
|
||||||
}
|
core.debug(`${additionalCache.name} primary key is ${primaryKey}`);
|
||||||
return { cache: additionalCache, primaryKey };
|
core.saveState(additionalCachePrimaryKeyState(additionalCache.name), primaryKey);
|
||||||
}));
|
|
||||||
return preparedCaches.filter((preparedCache) => preparedCache !== undefined);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Restore an additional cache keyed independently of the main dependency cache.
|
|
||||||
*/
|
|
||||||
async function restoreAdditionalCache(preparedCache) {
|
|
||||||
const { cache: additionalCache, primaryKey } = preparedCache;
|
|
||||||
const matchedKey = await cache.restoreCache(additionalCache.path, primaryKey);
|
const matchedKey = await cache.restoreCache(additionalCache.path, primaryKey);
|
||||||
if (matchedKey) {
|
if (matchedKey) {
|
||||||
core.saveState(additionalCacheMatchedKeyState(additionalCache.name), matchedKey);
|
core.saveState(additionalCacheMatchedKeyState(additionalCache.name), matchedKey);
|
||||||
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
core.info(`${additionalCache.name} cache is not found`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Save the dependency cache
|
* Save the dependency cache
|
||||||
@@ -97983,18 +97932,11 @@ async function restoreAdditionalCache(preparedCache) {
|
|||||||
*/
|
*/
|
||||||
async function save(id) {
|
async function save(id) {
|
||||||
const packageManager = findPackageManager(id);
|
const packageManager = findPackageManager(id);
|
||||||
const cachePaths = getCachePathsFromState(packageManager);
|
|
||||||
const matchedKey = getState(CACHE_MATCHED_KEY);
|
const matchedKey = getState(CACHE_MATCHED_KEY);
|
||||||
// Inputs are re-evaluated 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 = getState(STATE_CACHE_PRIMARY_KEY);
|
const primaryKey = getState(STATE_CACHE_PRIMARY_KEY);
|
||||||
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
||||||
try {
|
await saveAdditionalCache(packageManager, additionalCache);
|
||||||
await saveAdditionalCache(packageManager, additionalCache);
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
const err = error;
|
|
||||||
warning(`Failed to save ${additionalCache.name} cache: ${err.message}. Continuing with primary cache save.`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
warning('Error retrieving key from state.');
|
warning('Error retrieving key from state.');
|
||||||
@@ -98006,7 +97948,7 @@ async function save(id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const cacheId = await cache_saveCache(cachePaths, primaryKey);
|
const cacheId = await cache_saveCache(packageManager.path, primaryKey);
|
||||||
if (cacheId === -1) {
|
if (cacheId === -1) {
|
||||||
// saveCache returns -1 without throwing when the cache was not saved,
|
// saveCache returns -1 without throwing when the cache was not saved,
|
||||||
// e.g. a reserve collision or a read-only token (fork PR). @actions/cache
|
// e.g. a reserve collision or a read-only token (fork PR). @actions/cache
|
||||||
@@ -98076,7 +98018,7 @@ async function saveAdditionalCache(packageManager, additionalCache) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
||||||
warning(`Failed to save ${additionalCache.name} cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with \`--no-daemon\` option. Refer to https://github.com/actions/cache/issues/454 for details.`);
|
warning('Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for details.');
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -98123,14 +98065,7 @@ async function removePrivateKeyFromKeychain() {
|
|||||||
async function cleanup_java_saveCache() {
|
async function cleanup_java_saveCache() {
|
||||||
const jobStatus = isJobStatusSuccess();
|
const jobStatus = isJobStatusSuccess();
|
||||||
const cache = getInput(INPUT_CACHE);
|
const cache = getInput(INPUT_CACHE);
|
||||||
if (!jobStatus || !cache) {
|
return jobStatus && cache ? save(cache) : Promise.resolve();
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (util_getBooleanInput(INPUT_CACHE_READ_ONLY, false)) {
|
|
||||||
info('Cache saving is skipped because cache-read-only is enabled.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await save(cache);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* The save process is best-effort, and it should not make the workflow fail
|
* The save process is best-effort, and it should not make the workflow fail
|
||||||
|
|||||||
1166
dist/setup/index.js
vendored
1166
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -321,10 +321,12 @@ The package types have these meanings:
|
|||||||
| `graalvm-community` | `jdk` | Stable GraalVM Community releases for JDK 17 and later only. |
|
| `graalvm-community` | `jdk` | Stable GraalVM Community releases for JDK 17 and later only. |
|
||||||
| `jetbrains` | `jdk`, `jre`, `jdk+jcef`, `jre+jcef`, `jdk+ft`, `jre+ft` | JetBrains publishes selected LTS-based releases rather than every OpenJDK patch. JDK/JRE and JCEF bundles start with the Java 11 release family; FreeType bundles start with Java 17. Exact package, LTS family, patch, OS, and architecture availability is determined from release assets. |
|
| `jetbrains` | `jdk`, `jre`, `jdk+jcef`, `jre+jcef`, `jdk+ft`, `jre+ft` | JetBrains publishes selected LTS-based releases rather than every OpenJDK patch. JDK/JRE and JCEF bundles start with the Java 11 release family; FreeType bundles start with Java 17. Exact package, LTS family, patch, OS, and architecture availability is determined from release assets. |
|
||||||
| `kona` | `jdk` | Stable Java 8, 11, 17, 21, and 25 releases only. |
|
| `kona` | `jdk` | Stable Java 8, 11, 17, 21, and 25 releases only. |
|
||||||
| `jdkfile` | `jdk` | The package contents and version are supplied by `jdk-file`; `setup-java` validates the package type but does not inspect the archive contents. |
|
| `jdkfile` | `jdk` (recommended) | The package contents and version are supplied by `jdk-file`; `setup-java` does not validate them. `java-package` only separates the local archive's tool-cache entry, so use `jdk` unless separate cache namespaces are required. |
|
||||||
|
|
||||||
Values outside this table are unsupported. The action rejects them before
|
Values outside this table are unsupported even when a distribution forwards the
|
||||||
checking the tool cache or requesting a vendor catalog.
|
value to its vendor API instead of rejecting it immediately. In that case, the
|
||||||
|
action normally fails with a version-not-found error because no matching
|
||||||
|
artifact exists.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
@@ -484,38 +486,6 @@ jobs:
|
|||||||
> which provides purpose-built caching (see the
|
> which provides purpose-built caching (see the
|
||||||
> [setup-gradle documentation](https://github.com/gradle/actions/blob/main/docs/setup-gradle.md)).
|
> [setup-gradle documentation](https://github.com/gradle/actions/blob/main/docs/setup-gradle.md)).
|
||||||
|
|
||||||
## Platform and architecture compatibility
|
|
||||||
|
|
||||||
The `architecture` input is normalized before setup-java checks the tool cache
|
|
||||||
or contacts a vendor. `amd64`, `ia32`, `arm`, and `arm64` are accepted aliases
|
|
||||||
for `x64`, `x86`, `armv7`, and `aarch64`. The table lists the combinations
|
|
||||||
setup-java validates up front; an individual Java patch release can still be
|
|
||||||
absent from a vendor catalog.
|
|
||||||
|
|
||||||
| Distribution | Linux | macOS | Windows | Other / version restrictions |
|
|
||||||
| --- | --- | --- | --- | --- |
|
|
||||||
| `temurin` | `x64`, `x86`, `armv7`, `aarch64`, `ppc64le`, `s390x` | `x64`, `aarch64` | `x64`, `x86`, `aarch64` | Linux `armv7` is available through Java 17. |
|
|
||||||
| `adopt`, `adopt-hotspot` | `x64`, `x86`, `armv7`, `aarch64`, `ppc64le`, `s390x` | `x64`, `aarch64` | `x64`, `x86`, `aarch64` | HotSpot requests try Temurin before the archived catalog; Linux `armv7` is available through Java 17. |
|
|
||||||
| `adopt-openj9` | `x64`, `x86`, `aarch64`, `ppc64le`, `s390x` | `x64` | `x64`, `x86` | Uses the archived AdoptOpenJDK OpenJ9 catalog. |
|
|
||||||
| `zulu` | `x64`, `x86`, `armv7`, `aarch64` | `x64`, `aarch64` | `x64`, `x86`, `aarch64` | |
|
|
||||||
| `liberica` | `x64`, `x86`, `armv7`, `aarch64`, `ppc64le` | `x64`, `aarch64` | `x64`, `x86`, `aarch64` | Solaris: `x64`. |
|
|
||||||
| `liberica-nik` | `x64`, `aarch64` | `x64`, `aarch64` | `x64`, `aarch64` | |
|
|
||||||
| `microsoft` | `x64`, `aarch64` | `x64`, `aarch64` | `x64`, `aarch64` | |
|
|
||||||
| `semeru` | `x64`, `x86`, `ppc64le`, `ppc64`, `s390x`, `aarch64` | `x64`, `aarch64` | `x64`, `aarch64` | |
|
|
||||||
| `corretto` | `x64`, `x86`, `armv7`, `aarch64` | `x64`, `aarch64` | `x64`, `x86` | `x86` is limited to Java 11 or earlier; Linux `armv7` is available for Java 11. |
|
|
||||||
| `oracle` | `x64`, `aarch64` | `x64`, `aarch64` | `x64` | |
|
|
||||||
| `oracle-openjdk` | `x64`, `aarch64` | `x64`, `aarch64` | `x64` | |
|
|
||||||
| `dragonwell` | `x64`, `aarch64` | — | `x64` | |
|
|
||||||
| `sapmachine` | `x64`, `aarch64`, `ppc64le` | `x64`, `aarch64` | `x64`, `aarch64` | |
|
|
||||||
| `graalvm`, `graalvm-community` | `x64`, `aarch64` | `x64`, `aarch64` | `x64` | |
|
|
||||||
| `jetbrains` | `x64`, `aarch64` | `x64`, `aarch64` | `x64`, `aarch64` | |
|
|
||||||
| `kona` | `x64`, `aarch64` | `x64`, `aarch64` | `x64` | |
|
|
||||||
| `jdkfile` | Any | Any | Any | Local archives are not restricted because setup-java does not inspect their contents. |
|
|
||||||
|
|
||||||
Unsupported combinations fail with a platform-capability error before a cache
|
|
||||||
lookup or vendor request. A supported combination can still produce a
|
|
||||||
version-not-found error when the requested release was not published.
|
|
||||||
|
|
||||||
## Installing custom Java architecture
|
## Installing custom Java architecture
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -922,9 +892,9 @@ See the help docs on [Publishing a Package with Gradle](https://help.github.com/
|
|||||||
## Hosted Tool Cache
|
## 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.
|
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 Eclipse Temurin (`temurin`) are cached on GitHub-hosted runners. Using a cached version avoids downloading a JDK.
|
Currently, LTS versions of Eclipse Temurin (`temurin`) are cached on the GitHub Hosted Runners.
|
||||||
|
|
||||||
The tools cache gets updated on a weekly basis. See the installed Java versions for [Ubuntu](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md#java), [Windows](https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md#java), and [macOS](https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md#java).
|
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
|
## 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.
|
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.
|
||||||
@@ -1010,7 +980,7 @@ steps:
|
|||||||
- run: java --version
|
- run: java --version
|
||||||
```
|
```
|
||||||
|
|
||||||
When installing multiple Java versions, use the same multiline syntax as `java-version`. You must declare exactly one ID for every Java version that will be installed. The action fails before installing a JDK unless the number of `mvn-toolchain-id` entries matches the number of `java-version` entries, or is exactly one when `java-version-file` is used.
|
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
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
134
src/cache.ts
134
src/cache.ts
@@ -9,7 +9,6 @@ import * as core from '@actions/core';
|
|||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
|
|
||||||
const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
||||||
const STATE_CACHE_PATHS = 'cache-paths';
|
|
||||||
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
||||||
const CACHE_KEY_PREFIX = 'setup-java';
|
const CACHE_KEY_PREFIX = 'setup-java';
|
||||||
|
|
||||||
@@ -37,11 +36,6 @@ interface AdditionalCache {
|
|||||||
pattern: string[];
|
pattern: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PreparedAdditionalCache {
|
|
||||||
cache: AdditionalCache;
|
|
||||||
primaryKey: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PackageManager {
|
interface PackageManager {
|
||||||
id: 'maven' | 'gradle' | 'sbt';
|
id: 'maven' | 'gradle' | 'sbt';
|
||||||
/**
|
/**
|
||||||
@@ -137,29 +131,6 @@ function findPackageManager(id: string): PackageManager {
|
|||||||
return packageManager;
|
return packageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCachePaths(
|
|
||||||
packageManager: PackageManager,
|
|
||||||
cachePaths: string[]
|
|
||||||
): string[] {
|
|
||||||
return cachePaths.length > 0 ? cachePaths : packageManager.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCachePathsFromState(packageManager: PackageManager): string[] {
|
|
||||||
const cachePathsState = core.getState(STATE_CACHE_PATHS);
|
|
||||||
if (!cachePathsState) {
|
|
||||||
return packageManager.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cachePaths: unknown = JSON.parse(cachePathsState);
|
|
||||||
if (
|
|
||||||
!Array.isArray(cachePaths) ||
|
|
||||||
!cachePaths.every(cachePath => typeof cachePath === 'string')
|
|
||||||
) {
|
|
||||||
throw new Error('Invalid cache paths retrieved from state.');
|
|
||||||
}
|
|
||||||
return cachePaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State keys used to carry an additional cache's restore-time information over
|
* State keys used to carry an additional cache's restore-time information over
|
||||||
* to the post (save) action, scoped by the additional cache name.
|
* to the post (save) action, scoped by the additional cache name.
|
||||||
@@ -213,52 +184,18 @@ async function computeAdditionalCacheKey(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore the dependency cache
|
* Restore the dependency cache
|
||||||
* @param id ID of the package manager, should be "maven", "gradle", or "sbt"
|
* @param id ID of the package manager, should be "maven" or "gradle"
|
||||||
* @param cacheDependencyPath The path to a dependency file
|
* @param cacheDependencyPath The path to a dependency file
|
||||||
* @param cachePaths Paths to cache instead of the package manager defaults
|
|
||||||
*/
|
*/
|
||||||
export async function restore(
|
export async function restore(id: string, cacheDependencyPath: string) {
|
||||||
id: string,
|
|
||||||
cacheDependencyPath: string,
|
|
||||||
cachePaths: string[] = []
|
|
||||||
) {
|
|
||||||
const packageManager = findPackageManager(id);
|
const packageManager = findPackageManager(id);
|
||||||
const resolvedCachePaths = resolveCachePaths(packageManager, cachePaths);
|
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
|
||||||
const [primaryKey, preparedAdditionalCaches] = await Promise.all([
|
|
||||||
computeCacheKey(packageManager, cacheDependencyPath),
|
|
||||||
prepareAdditionalCaches(packageManager.additionalCaches ?? [])
|
|
||||||
]);
|
|
||||||
|
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||||
core.saveState(STATE_CACHE_PATHS, JSON.stringify(resolvedCachePaths));
|
|
||||||
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||||
|
|
||||||
for (const preparedCache of preparedAdditionalCaches) {
|
|
||||||
core.debug(
|
|
||||||
`${preparedCache.cache.name} primary key is ${preparedCache.primaryKey}`
|
|
||||||
);
|
|
||||||
core.saveState(
|
|
||||||
additionalCachePrimaryKeyState(preparedCache.cache.name),
|
|
||||||
preparedCache.primaryKey
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
restorePrimaryCache(packageManager, resolvedCachePaths, primaryKey),
|
|
||||||
...preparedAdditionalCaches.map(preparedCache =>
|
|
||||||
restoreAdditionalCache(preparedCache)
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function restorePrimaryCache(
|
|
||||||
packageManager: PackageManager,
|
|
||||||
cachePaths: string[],
|
|
||||||
primaryKey: string
|
|
||||||
) {
|
|
||||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
// 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(cachePaths, primaryKey);
|
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||||
if (matchedKey) {
|
if (matchedKey) {
|
||||||
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||||
core.setOutput('cache-hit', matchedKey === primaryKey);
|
core.setOutput('cache-hit', matchedKey === primaryKey);
|
||||||
@@ -267,39 +204,32 @@ async function restorePrimaryCache(
|
|||||||
core.setOutput('cache-hit', false);
|
core.setOutput('cache-hit', false);
|
||||||
core.info(`${packageManager.id} cache is not found`);
|
core.info(`${packageManager.id} cache is not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
||||||
|
await restoreAdditionalCache(additionalCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute keys for additional caches (e.g. build-tool wrapper distributions).
|
* Restore an additional cache (e.g. a build-tool wrapper distribution) that is
|
||||||
* Additional caches without a matching configuration file are omitted.
|
* keyed independently of the main dependency cache so that it survives changes
|
||||||
|
* to volatile dependency files. Skips silently when the project does not use
|
||||||
|
* the corresponding feature.
|
||||||
*/
|
*/
|
||||||
async function prepareAdditionalCaches(
|
async function restoreAdditionalCache(additionalCache: AdditionalCache) {
|
||||||
additionalCaches: AdditionalCache[]
|
const primaryKey = await computeAdditionalCacheKey(additionalCache);
|
||||||
): Promise<PreparedAdditionalCache[]> {
|
if (!primaryKey) {
|
||||||
const preparedCaches = await Promise.all(
|
core.debug(
|
||||||
additionalCaches.map(async additionalCache => {
|
`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`
|
||||||
const primaryKey = await computeAdditionalCacheKey(additionalCache);
|
);
|
||||||
if (!primaryKey) {
|
return;
|
||||||
core.debug(
|
}
|
||||||
`No file matched [${additionalCache.pattern}] for the ${additionalCache.name} cache, skipping.`
|
core.debug(`${additionalCache.name} primary key is ${primaryKey}`);
|
||||||
);
|
core.saveState(
|
||||||
return undefined;
|
additionalCachePrimaryKeyState(additionalCache.name),
|
||||||
}
|
primaryKey
|
||||||
return {cache: additionalCache, primaryKey};
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return preparedCaches.filter(
|
|
||||||
(preparedCache): preparedCache is PreparedAdditionalCache =>
|
|
||||||
preparedCache !== undefined
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restore an additional cache keyed independently of the main dependency cache.
|
|
||||||
*/
|
|
||||||
async function restoreAdditionalCache(preparedCache: PreparedAdditionalCache) {
|
|
||||||
const {cache: additionalCache, primaryKey} = preparedCache;
|
|
||||||
const matchedKey = await cache.restoreCache(additionalCache.path, primaryKey);
|
const matchedKey = await cache.restoreCache(additionalCache.path, primaryKey);
|
||||||
if (matchedKey) {
|
if (matchedKey) {
|
||||||
core.saveState(
|
core.saveState(
|
||||||
@@ -307,8 +237,6 @@ async function restoreAdditionalCache(preparedCache: PreparedAdditionalCache) {
|
|||||||
matchedKey
|
matchedKey
|
||||||
);
|
);
|
||||||
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
core.info(`${additionalCache.name} cache restored from key: ${matchedKey}`);
|
||||||
} else {
|
|
||||||
core.info(`${additionalCache.name} cache is not found`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,21 +246,13 @@ async function restoreAdditionalCache(preparedCache: PreparedAdditionalCache) {
|
|||||||
*/
|
*/
|
||||||
export async function save(id: string) {
|
export async function save(id: string) {
|
||||||
const packageManager = findPackageManager(id);
|
const packageManager = findPackageManager(id);
|
||||||
const cachePaths = getCachePathsFromState(packageManager);
|
|
||||||
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
||||||
|
|
||||||
// Inputs are re-evaluated 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);
|
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||||
|
|
||||||
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
for (const additionalCache of packageManager.additionalCaches ?? []) {
|
||||||
try {
|
await saveAdditionalCache(packageManager, additionalCache);
|
||||||
await saveAdditionalCache(packageManager, additionalCache);
|
|
||||||
} catch (error) {
|
|
||||||
const err = error as Error;
|
|
||||||
core.warning(
|
|
||||||
`Failed to save ${additionalCache.name} cache: ${err.message}. Continuing with primary cache save.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
@@ -346,7 +266,7 @@ export async function save(id: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const cacheId = await cache.saveCache(cachePaths, primaryKey);
|
const cacheId = await cache.saveCache(packageManager.path, primaryKey);
|
||||||
if (cacheId === -1) {
|
if (cacheId === -1) {
|
||||||
// saveCache returns -1 without throwing when the cache was not saved,
|
// saveCache returns -1 without throwing when the cache was not saved,
|
||||||
// e.g. a reserve collision or a read-only token (fork PR). @actions/cache
|
// e.g. a reserve collision or a read-only token (fork PR). @actions/cache
|
||||||
@@ -440,7 +360,7 @@ async function saveAdditionalCache(
|
|||||||
} else {
|
} else {
|
||||||
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
if (isProbablyGradleDaemonProblem(packageManager, err)) {
|
||||||
core.warning(
|
core.warning(
|
||||||
`Failed to save ${additionalCache.name} cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with \`--no-daemon\` option. Refer to https://github.com/actions/cache/issues/454 for details.`
|
'Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for details.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
import {createHash, timingSafeEqual} from 'crypto';
|
|
||||||
import {createReadStream} from 'fs';
|
|
||||||
import {pipeline} from 'stream/promises';
|
|
||||||
|
|
||||||
import {ChecksumMetadata} from './distributions/base-models.js';
|
|
||||||
|
|
||||||
export interface ChecksumVerificationContext {
|
|
||||||
distribution: string;
|
|
||||||
version: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sanitizedSource(source: string | undefined): string {
|
|
||||||
if (!source) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const url = new URL(source);
|
|
||||||
return ` from ${url.origin}${url.pathname}`;
|
|
||||||
} catch {
|
|
||||||
return ' from an invalid checksum source';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Length, in hex characters, of a digest produced by each supported algorithm.
|
|
||||||
// Exported so callers (e.g. fetchChecksum) can infer which algorithm a vendor
|
|
||||||
// actually used when it doesn't disclose it via the checksum URL/filename.
|
|
||||||
export function expectedDigestLength(
|
|
||||||
algorithm: ChecksumMetadata['algorithm']
|
|
||||||
): number {
|
|
||||||
return algorithm === 'sha256' ? 64 : algorithm === 'sha512' ? 128 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeExpectedDigest(checksum: ChecksumMetadata): string {
|
|
||||||
const algorithm = checksum.algorithm;
|
|
||||||
const digest =
|
|
||||||
typeof checksum.value === 'string'
|
|
||||||
? checksum.value.trim().toLowerCase()
|
|
||||||
: '';
|
|
||||||
const expectedLength = expectedDigestLength(algorithm);
|
|
||||||
|
|
||||||
if (expectedLength === 0) {
|
|
||||||
throw new Error(
|
|
||||||
`Unsupported checksum algorithm '${String(algorithm)}'${sanitizedSource(checksum.source)}. Supported algorithms are sha256 and sha512.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!new RegExp(`^[a-f0-9]{${expectedLength}}$`).test(digest)) {
|
|
||||||
throw new Error(
|
|
||||||
`Malformed ${algorithm} checksum metadata${sanitizedSource(checksum.source)}: expected a ${expectedLength}-character hexadecimal digest.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return digest;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function calculateChecksum(
|
|
||||||
filePath: string,
|
|
||||||
algorithm: ChecksumMetadata['algorithm']
|
|
||||||
): Promise<string> {
|
|
||||||
const hash = createHash(algorithm);
|
|
||||||
await pipeline(createReadStream(filePath), hash);
|
|
||||||
return hash.digest('hex');
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function verifyChecksum(
|
|
||||||
filePath: string,
|
|
||||||
checksum: ChecksumMetadata,
|
|
||||||
context: ChecksumVerificationContext
|
|
||||||
): Promise<void> {
|
|
||||||
const expected = normalizeExpectedDigest(checksum);
|
|
||||||
const actual = await calculateChecksum(filePath, checksum.algorithm);
|
|
||||||
const matches = timingSafeEqual(
|
|
||||||
Buffer.from(expected, 'hex'),
|
|
||||||
Buffer.from(actual, 'hex')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!matches) {
|
|
||||||
throw new Error(
|
|
||||||
`Checksum verification failed for ${context.distribution} version ${context.version}: ${checksum.algorithm} expected ${expected}, actual ${actual}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as gpg from './gpg.js';
|
import * as gpg from './gpg.js';
|
||||||
import * as constants from './constants.js';
|
import * as constants from './constants.js';
|
||||||
import {getBooleanInput, isJobStatusSuccess} from './util.js';
|
import {isJobStatusSuccess} from './util.js';
|
||||||
import {save} from './cache.js';
|
import {save} from './cache.js';
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
@@ -28,16 +28,7 @@ async function removePrivateKeyFromKeychain() {
|
|||||||
async function saveCache() {
|
async function saveCache() {
|
||||||
const jobStatus = isJobStatusSuccess();
|
const jobStatus = isJobStatusSuccess();
|
||||||
const cache = core.getInput(constants.INPUT_CACHE);
|
const cache = core.getInput(constants.INPUT_CACHE);
|
||||||
if (!jobStatus || !cache) {
|
return jobStatus && cache ? save(cache) : Promise.resolve();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getBooleanInput(constants.INPUT_CACHE_READ_ONLY, false)) {
|
|
||||||
core.info('Cache saving is skipped because cache-read-only is enabled.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await save(cache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ export const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
|
|||||||
|
|
||||||
export const INPUT_CACHE = 'cache';
|
export const INPUT_CACHE = 'cache';
|
||||||
export const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
|
export const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
|
||||||
export const INPUT_CACHE_PATH = 'cache-path';
|
|
||||||
export const INPUT_CACHE_READ_ONLY = 'cache-read-only';
|
|
||||||
export const INPUT_JOB_STATUS = 'job-status';
|
export const INPUT_JOB_STATUS = 'job-status';
|
||||||
|
|
||||||
export const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
export const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
||||||
|
|||||||
@@ -105,12 +105,7 @@ export class AdoptDistribution extends JavaBase {
|
|||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
version: item.version_data.semver,
|
version: item.version_data.semver,
|
||||||
url: item.binaries[0].package.link,
|
url: item.binaries[0].package.link
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: item.binaries[0].package.checksum,
|
|
||||||
source: item.binaries[0].package.checksum_link
|
|
||||||
}
|
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -138,7 +133,7 @@ export class AdoptDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
@@ -260,9 +255,4 @@ export class AdoptDistribution extends JavaBase {
|
|||||||
return process.platform;
|
return process.platform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected distributionArchitecture(): string {
|
|
||||||
const architecture = super.distributionArchitecture();
|
|
||||||
return architecture === 'armv7' ? 'arm' : architecture;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,17 +10,12 @@ import {
|
|||||||
isVersionSatisfies
|
isVersionSatisfies
|
||||||
} from '../util.js';
|
} from '../util.js';
|
||||||
import {
|
import {
|
||||||
ChecksumAlgorithm,
|
|
||||||
ChecksumMetadata,
|
|
||||||
JavaDownloadRelease,
|
JavaDownloadRelease,
|
||||||
JavaInstallerOptions,
|
JavaInstallerOptions,
|
||||||
JavaInstallerResults
|
JavaInstallerResults
|
||||||
} from './base-models.js';
|
} from './base-models.js';
|
||||||
import {MACOS_JAVA_CONTENT_POSTFIX} from '../constants.js';
|
import {MACOS_JAVA_CONTENT_POSTFIX} from '../constants.js';
|
||||||
import {RetryingHttpClient} from '../retrying-http-client.js';
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import {expectedDigestLength, verifyChecksum} from '../checksum.js';
|
|
||||||
import {normalizeArchitecture} from './platform-types.js';
|
|
||||||
|
|
||||||
export abstract class JavaBase {
|
export abstract class JavaBase {
|
||||||
protected http: httpm.HttpClient;
|
protected http: httpm.HttpClient;
|
||||||
@@ -39,16 +34,17 @@ export abstract class JavaBase {
|
|||||||
protected distribution: string,
|
protected distribution: string,
|
||||||
installerOptions: JavaInstallerOptions
|
installerOptions: JavaInstallerOptions
|
||||||
) {
|
) {
|
||||||
this.http = new RetryingHttpClient('actions/setup-java');
|
this.http = new httpm.HttpClient('actions/setup-java', undefined, {
|
||||||
|
allowRetries: true,
|
||||||
|
maxRetries: 3
|
||||||
|
});
|
||||||
|
|
||||||
({
|
({
|
||||||
version: this.version,
|
version: this.version,
|
||||||
stable: this.stable,
|
stable: this.stable,
|
||||||
latest: this.latest
|
latest: this.latest
|
||||||
} = this.normalizeVersion(installerOptions.version));
|
} = this.normalizeVersion(installerOptions.version));
|
||||||
this.architecture = normalizeArchitecture(
|
this.architecture = installerOptions.architecture || os.arch();
|
||||||
installerOptions.architecture || os.arch()
|
|
||||||
);
|
|
||||||
this.packageType = installerOptions.packageType;
|
this.packageType = installerOptions.packageType;
|
||||||
this.checkLatest = installerOptions.checkLatest;
|
this.checkLatest = installerOptions.checkLatest;
|
||||||
this.forceDownload = installerOptions.forceDownload ?? false;
|
this.forceDownload = installerOptions.forceDownload ?? false;
|
||||||
@@ -67,101 +63,6 @@ export abstract class JavaBase {
|
|||||||
range: string
|
range: string
|
||||||
): Promise<JavaDownloadRelease>;
|
): Promise<JavaDownloadRelease>;
|
||||||
|
|
||||||
protected async downloadAndVerify(
|
|
||||||
javaRelease: JavaDownloadRelease
|
|
||||||
): Promise<string> {
|
|
||||||
const archivePath = await tc.downloadTool(javaRelease.url);
|
|
||||||
const checksum = javaRelease.checksum;
|
|
||||||
if (!checksum || !checksum.value?.trim()) {
|
|
||||||
core.debug(
|
|
||||||
`No authoritative checksum is available for ${this.distribution} version ${javaRelease.version}; skipping checksum verification.`
|
|
||||||
);
|
|
||||||
return archivePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await verifyChecksum(archivePath, checksum, {
|
|
||||||
distribution: this.distribution,
|
|
||||||
version: javaRelease.version
|
|
||||||
});
|
|
||||||
core.debug(
|
|
||||||
`Verified ${checksum.algorithm} checksum for ${this.distribution} version ${javaRelease.version}.`
|
|
||||||
);
|
|
||||||
return archivePath;
|
|
||||||
} catch (error) {
|
|
||||||
let cleanupError: unknown;
|
|
||||||
let cleanupFailed = false;
|
|
||||||
try {
|
|
||||||
await fs.promises.rm(archivePath, {force: true});
|
|
||||||
} catch (caughtCleanupError) {
|
|
||||||
cleanupError = caughtCleanupError;
|
|
||||||
cleanupFailed = true;
|
|
||||||
}
|
|
||||||
if (cleanupFailed) {
|
|
||||||
throw new Error(
|
|
||||||
`${(error as Error).message} Failed to remove the downloaded archive after verification failure: ${(cleanupError as Error).message}`,
|
|
||||||
{cause: error}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async fetchChecksum(
|
|
||||||
checksumUrl: string,
|
|
||||||
algorithm: ChecksumAlgorithm | ChecksumAlgorithm[]
|
|
||||||
): Promise<ChecksumMetadata | undefined> {
|
|
||||||
// Some vendors (e.g. JetBrains) publish a single, generically-named
|
|
||||||
// checksum sibling (`.checksum`) whose digest algorithm isn't disclosed
|
|
||||||
// by the URL and has changed across releases. Accepting a list of
|
|
||||||
// candidate algorithms lets callers pass every algorithm the vendor is
|
|
||||||
// known to use; the actual algorithm is then inferred from the length of
|
|
||||||
// the returned digest.
|
|
||||||
const algorithms = Array.isArray(algorithm) ? algorithm : [algorithm];
|
|
||||||
const algorithmLabel = algorithms.join(' or ');
|
|
||||||
|
|
||||||
const response = await this.http.get(checksumUrl);
|
|
||||||
const statusCode = response.message.statusCode;
|
|
||||||
const source = (() => {
|
|
||||||
try {
|
|
||||||
const url = new URL(checksumUrl);
|
|
||||||
return `${url.origin}${url.pathname}`;
|
|
||||||
} catch {
|
|
||||||
return 'an invalid checksum URL';
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
if (statusCode === httpm.HttpCodes.NotFound) {
|
|
||||||
core.debug(
|
|
||||||
`No authoritative ${algorithmLabel} checksum is available for ${this.distribution} from ${source}; skipping checksum verification.`
|
|
||||||
);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statusCode !== httpm.HttpCodes.OK) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to fetch the authoritative ${algorithmLabel} checksum for ${this.distribution} from ${source} (HTTP ${statusCode}).`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await response.readBody();
|
|
||||||
const value = body.trim().split(/\s+/, 1)[0] ?? '';
|
|
||||||
if (!value) {
|
|
||||||
throw new Error(
|
|
||||||
`Received an empty authoritative ${algorithmLabel} checksum for ${this.distribution} from ${source}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prefer the strongest algorithm whose digest length matches what was
|
|
||||||
// actually returned; fall back to the first candidate (preserving prior
|
|
||||||
// behavior/error messages) when the digest doesn't match any of them.
|
|
||||||
const resolvedAlgorithm =
|
|
||||||
algorithms.find(algo => value.length === expectedDigestLength(algo)) ??
|
|
||||||
algorithms[0];
|
|
||||||
|
|
||||||
return {algorithm: resolvedAlgorithm, value, source: checksumUrl};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async setupJava(): Promise<JavaInstallerResults> {
|
public async setupJava(): Promise<JavaInstallerResults> {
|
||||||
if (this.verifySignature && !this.supportsSignatureVerification()) {
|
if (this.verifySignature && !this.supportsSignatureVerification()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -174,19 +75,113 @@ export abstract class JavaBase {
|
|||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
} else {
|
} else {
|
||||||
core.info('Trying to resolve the latest version from remote');
|
core.info('Trying to resolve the latest version from remote');
|
||||||
try {
|
const MAX_RETRIES = 4;
|
||||||
const javaRelease = await this.findPackageForDownload(this.version);
|
const RETRY_DELAY_MS = 2000;
|
||||||
core.info(`Resolved latest version as ${javaRelease.version}`);
|
const retryableCodes = [
|
||||||
if (!this.forceDownload && foundJava?.version === javaRelease.version) {
|
'ETIMEDOUT',
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
'ECONNRESET',
|
||||||
} else {
|
'ENOTFOUND',
|
||||||
core.info('Trying to download...');
|
'ECONNREFUSED'
|
||||||
foundJava = await this.downloadTool(javaRelease);
|
];
|
||||||
core.info(`Java ${foundJava.version} was downloaded`);
|
let retries = MAX_RETRIES;
|
||||||
|
while (retries > 0) {
|
||||||
|
try {
|
||||||
|
// Clear console timers before each attempt to prevent conflicts
|
||||||
|
if (retries < MAX_RETRIES && core.isDebug()) {
|
||||||
|
const consoleAny = console as any;
|
||||||
|
consoleAny._times?.clear?.();
|
||||||
|
}
|
||||||
|
const javaRelease = await this.findPackageForDownload(this.version);
|
||||||
|
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||||
|
if (
|
||||||
|
!this.forceDownload &&
|
||||||
|
foundJava?.version === javaRelease.version
|
||||||
|
) {
|
||||||
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
|
} else {
|
||||||
|
core.info('Trying to download...');
|
||||||
|
foundJava = await this.downloadTool(javaRelease);
|
||||||
|
core.info(`Java ${foundJava.version} was downloaded`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (error: any) {
|
||||||
|
retries--;
|
||||||
|
// Check if error is retryable (including aggregate errors)
|
||||||
|
const isRetryable =
|
||||||
|
(error instanceof tc.HTTPError &&
|
||||||
|
error.httpStatusCode &&
|
||||||
|
[429, 502, 503, 504, 522].includes(error.httpStatusCode)) ||
|
||||||
|
retryableCodes.includes(error?.code) ||
|
||||||
|
(error?.errors &&
|
||||||
|
Array.isArray(error.errors) &&
|
||||||
|
error.errors.some((err: any) =>
|
||||||
|
retryableCodes.includes(err?.code)
|
||||||
|
));
|
||||||
|
if (retries > 0 && isRetryable) {
|
||||||
|
core.debug(
|
||||||
|
`Attempt failed due to network or timeout issues, initiating retry... (${retries} attempts left)`
|
||||||
|
);
|
||||||
|
await new Promise(r => setTimeout(r, RETRY_DELAY_MS));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (error instanceof tc.HTTPError) {
|
||||||
|
if (error.httpStatusCode === 403) {
|
||||||
|
core.error('HTTP 403: Permission denied or access restricted.');
|
||||||
|
} else if (error.httpStatusCode === 429) {
|
||||||
|
core.warning(
|
||||||
|
'HTTP 429: Rate limit exceeded. Please retry later.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
core.error(`HTTP ${error.httpStatusCode}: ${error.message}`);
|
||||||
|
}
|
||||||
|
} else if (error && error.errors && Array.isArray(error.errors)) {
|
||||||
|
core.error(
|
||||||
|
`Java setup failed due to network or configuration error(s)`
|
||||||
|
);
|
||||||
|
if (error instanceof Error && error.stack) {
|
||||||
|
core.debug(error.stack);
|
||||||
|
}
|
||||||
|
for (const err of error.errors) {
|
||||||
|
const endpoint = err?.address || err?.hostname || '';
|
||||||
|
const port = err?.port ? `:${err.port}` : '';
|
||||||
|
const message = err?.message || 'Aggregate error';
|
||||||
|
const endpointInfo = !message.includes(endpoint)
|
||||||
|
? ` ${endpoint}${port}`
|
||||||
|
: '';
|
||||||
|
const localInfo =
|
||||||
|
err.localAddress && err.localPort
|
||||||
|
? ` - Local (${err.localAddress}:${err.localPort})`
|
||||||
|
: '';
|
||||||
|
const logMessage = `${message}${endpointInfo}${localInfo}`;
|
||||||
|
core.error(logMessage);
|
||||||
|
core.debug(`${err.stack || err.message}`);
|
||||||
|
Object.entries(err).forEach(([key, value]) => {
|
||||||
|
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const message =
|
||||||
|
error instanceof Error ? error.message : JSON.stringify(error);
|
||||||
|
core.error(`Java setup process failed due to: ${message}`);
|
||||||
|
if (typeof error?.code === 'string') {
|
||||||
|
core.debug(error.stack);
|
||||||
|
}
|
||||||
|
const errorDetails = {
|
||||||
|
name: error.name,
|
||||||
|
message: error.message,
|
||||||
|
...Object.getOwnPropertyNames(error)
|
||||||
|
.filter(prop => !['name', 'message', 'stack'].includes(prop))
|
||||||
|
.reduce<{[key: string]: any}>((acc, prop) => {
|
||||||
|
acc[prop] = error[prop];
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
};
|
||||||
|
Object.entries(errorDetails).forEach(([key, value]) => {
|
||||||
|
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
|
||||||
this.logSetupError(error);
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundJava) {
|
if (!foundJava) {
|
||||||
@@ -214,68 +209,6 @@ export abstract class JavaBase {
|
|||||||
return foundJava;
|
return foundJava;
|
||||||
}
|
}
|
||||||
|
|
||||||
private logSetupError(error: any): void {
|
|
||||||
const httpStatusCode =
|
|
||||||
error instanceof tc.HTTPError
|
|
||||||
? error.httpStatusCode
|
|
||||||
: error instanceof httpm.HttpClientError
|
|
||||||
? error.statusCode
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (httpStatusCode) {
|
|
||||||
if (httpStatusCode === 403) {
|
|
||||||
core.error('HTTP 403: Permission denied or access restricted.');
|
|
||||||
} else if (httpStatusCode === 429) {
|
|
||||||
core.warning('HTTP 429: Rate limit exceeded. Please retry later.');
|
|
||||||
} else {
|
|
||||||
core.error(`HTTP ${httpStatusCode}: ${error.message}`);
|
|
||||||
}
|
|
||||||
} else if (error && error.errors && Array.isArray(error.errors)) {
|
|
||||||
core.error(`Java setup failed due to network or configuration error(s)`);
|
|
||||||
if (error instanceof Error && error.stack) {
|
|
||||||
core.debug(error.stack);
|
|
||||||
}
|
|
||||||
for (const err of error.errors) {
|
|
||||||
const endpoint = err?.address || err?.hostname || '';
|
|
||||||
const port = err?.port ? `:${err.port}` : '';
|
|
||||||
const message = err?.message || 'Aggregate error';
|
|
||||||
const endpointInfo = !message.includes(endpoint)
|
|
||||||
? ` ${endpoint}${port}`
|
|
||||||
: '';
|
|
||||||
const localInfo =
|
|
||||||
err.localAddress && err.localPort
|
|
||||||
? ` - Local (${err.localAddress}:${err.localPort})`
|
|
||||||
: '';
|
|
||||||
const logMessage = `${message}${endpointInfo}${localInfo}`;
|
|
||||||
core.error(logMessage);
|
|
||||||
core.debug(`${err.stack || err.message}`);
|
|
||||||
Object.entries(err).forEach(([key, value]) => {
|
|
||||||
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const message =
|
|
||||||
error instanceof Error ? error.message : JSON.stringify(error);
|
|
||||||
core.error(`Java setup process failed due to: ${message}`);
|
|
||||||
if (typeof error?.code === 'string') {
|
|
||||||
core.debug(error.stack);
|
|
||||||
}
|
|
||||||
const errorDetails = {
|
|
||||||
name: error.name,
|
|
||||||
message: error.message,
|
|
||||||
...Object.getOwnPropertyNames(error)
|
|
||||||
.filter(prop => !['name', 'message', 'stack'].includes(prop))
|
|
||||||
.reduce<{[key: string]: any}>((acc, prop) => {
|
|
||||||
acc[prop] = error[prop];
|
|
||||||
return acc;
|
|
||||||
}, {})
|
|
||||||
};
|
|
||||||
Object.entries(errorDetails).forEach(([key, value]) => {
|
|
||||||
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected get toolcacheFolderName(): string {
|
protected get toolcacheFolderName(): string {
|
||||||
return `Java_${this.distribution}_${this.packageType}`;
|
return `Java_${this.distribution}_${this.packageType}`;
|
||||||
}
|
}
|
||||||
@@ -454,6 +387,22 @@ export abstract class JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected distributionArchitecture(): string {
|
protected distributionArchitecture(): string {
|
||||||
return this.architecture;
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,8 @@ export interface JavaInstallerResults {
|
|||||||
path: string;
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChecksumAlgorithm = 'sha256' | 'sha512';
|
|
||||||
|
|
||||||
export interface ChecksumMetadata {
|
|
||||||
algorithm: ChecksumAlgorithm;
|
|
||||||
value: string;
|
|
||||||
source?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface JavaDownloadRelease {
|
export interface JavaDownloadRelease {
|
||||||
version: string;
|
version: string;
|
||||||
url: string;
|
url: string;
|
||||||
signatureUrl?: string;
|
signatureUrl?: string;
|
||||||
checksum?: ChecksumMetadata;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ import {
|
|||||||
ICorrettoAvailableVersions
|
ICorrettoAvailableVersions
|
||||||
} from './models.js';
|
} from './models.js';
|
||||||
|
|
||||||
const CORRETTO_VERSIONS_URL =
|
|
||||||
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json';
|
|
||||||
|
|
||||||
export class CorrettoDistribution extends JavaBase {
|
export class CorrettoDistribution extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
super('Corretto', installerOptions);
|
super('Corretto', installerOptions);
|
||||||
@@ -33,7 +30,7 @@ export class CorrettoDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
@@ -89,12 +86,7 @@ export class CorrettoDistribution extends JavaBase {
|
|||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
version: convertVersionToSemver(item.correttoVersion),
|
version: convertVersionToSemver(item.correttoVersion),
|
||||||
url: item.downloadLink,
|
url: item.downloadLink
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: item.checksum_sha256,
|
|
||||||
source: CORRETTO_VERSIONS_URL
|
|
||||||
}
|
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -118,14 +110,16 @@ export class CorrettoDistribution extends JavaBase {
|
|||||||
console.time('Retrieving available versions for Corretto took'); // eslint-disable-line no-console
|
console.time('Retrieving available versions for Corretto took'); // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const availableVersionsUrl =
|
||||||
|
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json';
|
||||||
const fetchCurrentVersions =
|
const fetchCurrentVersions =
|
||||||
await this.http.getJson<ICorrettoAllAvailableVersions>(
|
await this.http.getJson<ICorrettoAllAvailableVersions>(
|
||||||
CORRETTO_VERSIONS_URL
|
availableVersionsUrl
|
||||||
);
|
);
|
||||||
const fetchedCurrentVersions = fetchCurrentVersions.result;
|
const fetchedCurrentVersions = fetchCurrentVersions.result;
|
||||||
if (!fetchedCurrentVersions) {
|
if (!fetchedCurrentVersions) {
|
||||||
throw Error(
|
throw Error(
|
||||||
`Could not fetch latest corretto versions from ${CORRETTO_VERSIONS_URL}`
|
`Could not fetch latest corretto versions from ${availableVersionsUrl}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,11 +188,6 @@ export class CorrettoDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected distributionArchitecture(): string {
|
|
||||||
const architecture = super.distributionArchitecture();
|
|
||||||
return architecture === 'armv7' ? 'arm' : architecture;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getCorrettoVersion(resource: string): string {
|
private getCorrettoVersion(resource: string): string {
|
||||||
const regex = /(\d+.+)\//;
|
const regex = /(\d+.+)\//;
|
||||||
const match = regex.exec(resource);
|
const match = regex.exec(resource);
|
||||||
|
|||||||
@@ -22,78 +22,90 @@ import {
|
|||||||
import {JetBrainsDistribution} from './jetbrains/installer.js';
|
import {JetBrainsDistribution} from './jetbrains/installer.js';
|
||||||
import {KonaDistribution} from './kona/installer.js';
|
import {KonaDistribution} from './kona/installer.js';
|
||||||
import {OpenJdkDistribution} from './openjdk/installer.js';
|
import {OpenJdkDistribution} from './openjdk/installer.js';
|
||||||
import {JavaDistribution, validateJavaPackage} from './package-types.js';
|
|
||||||
import os from 'os';
|
enum JavaDistribution {
|
||||||
import {validateJavaPlatform} from './platform-types.js';
|
Adopt = 'adopt',
|
||||||
|
AdoptHotspot = 'adopt-hotspot',
|
||||||
|
AdoptOpenJ9 = 'adopt-openj9',
|
||||||
|
Temurin = 'temurin',
|
||||||
|
Zulu = 'zulu',
|
||||||
|
Liberica = 'liberica',
|
||||||
|
LibericaNik = 'liberica-nik',
|
||||||
|
JdkFile = 'jdkfile',
|
||||||
|
Microsoft = 'microsoft',
|
||||||
|
Semeru = 'semeru',
|
||||||
|
Corretto = 'corretto',
|
||||||
|
Oracle = 'oracle',
|
||||||
|
Dragonwell = 'dragonwell',
|
||||||
|
SapMachine = 'sapmachine',
|
||||||
|
GraalVM = 'graalvm',
|
||||||
|
GraalVMCommunity = 'graalvm-community',
|
||||||
|
JetBrains = 'jetbrains',
|
||||||
|
Kona = 'kona',
|
||||||
|
OracleOpenJdk = 'oracle-openjdk'
|
||||||
|
}
|
||||||
|
|
||||||
export function getJavaDistribution(
|
export function getJavaDistribution(
|
||||||
distributionName: string,
|
distributionName: string,
|
||||||
installerOptions: JavaInstallerOptions,
|
installerOptions: JavaInstallerOptions,
|
||||||
jdkFile?: string
|
jdkFile?: string
|
||||||
): JavaBase | null {
|
): JavaBase | null {
|
||||||
validateJavaPackage(
|
if (
|
||||||
distributionName,
|
installerOptions.packageType === 'jdk+jmods' &&
|
||||||
installerOptions.packageType,
|
distributionName !== JavaDistribution.Temurin
|
||||||
installerOptions.version
|
) {
|
||||||
);
|
throw new Error(
|
||||||
const architecture = validateJavaPlatform(
|
"java-package 'jdk+jmods' is only supported for distribution 'temurin'."
|
||||||
distributionName,
|
);
|
||||||
process.platform,
|
}
|
||||||
installerOptions.architecture || os.arch(),
|
|
||||||
installerOptions.version
|
|
||||||
);
|
|
||||||
const normalizedInstallerOptions = {
|
|
||||||
...installerOptions,
|
|
||||||
architecture
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (distributionName) {
|
switch (distributionName) {
|
||||||
case JavaDistribution.JdkFile:
|
case JavaDistribution.JdkFile:
|
||||||
return new LocalDistribution(normalizedInstallerOptions, jdkFile);
|
return new LocalDistribution(installerOptions, jdkFile);
|
||||||
case JavaDistribution.Adopt:
|
case JavaDistribution.Adopt:
|
||||||
case JavaDistribution.AdoptHotspot:
|
case JavaDistribution.AdoptHotspot:
|
||||||
return new AdoptDistribution(
|
return new AdoptDistribution(
|
||||||
normalizedInstallerOptions,
|
installerOptions,
|
||||||
AdoptImplementation.Hotspot
|
AdoptImplementation.Hotspot
|
||||||
);
|
);
|
||||||
case JavaDistribution.AdoptOpenJ9:
|
case JavaDistribution.AdoptOpenJ9:
|
||||||
return new AdoptDistribution(
|
return new AdoptDistribution(
|
||||||
normalizedInstallerOptions,
|
installerOptions,
|
||||||
AdoptImplementation.OpenJ9
|
AdoptImplementation.OpenJ9
|
||||||
);
|
);
|
||||||
case JavaDistribution.Temurin:
|
case JavaDistribution.Temurin:
|
||||||
return new TemurinDistribution(
|
return new TemurinDistribution(
|
||||||
normalizedInstallerOptions,
|
installerOptions,
|
||||||
TemurinImplementation.Hotspot
|
TemurinImplementation.Hotspot
|
||||||
);
|
);
|
||||||
case JavaDistribution.Zulu:
|
case JavaDistribution.Zulu:
|
||||||
return new ZuluDistribution(normalizedInstallerOptions);
|
return new ZuluDistribution(installerOptions);
|
||||||
case JavaDistribution.Liberica:
|
case JavaDistribution.Liberica:
|
||||||
return new LibericaDistributions(normalizedInstallerOptions);
|
return new LibericaDistributions(installerOptions);
|
||||||
case JavaDistribution.LibericaNik:
|
case JavaDistribution.LibericaNik:
|
||||||
return new LibericaNikDistributions(normalizedInstallerOptions);
|
return new LibericaNikDistributions(installerOptions);
|
||||||
case JavaDistribution.Microsoft:
|
case JavaDistribution.Microsoft:
|
||||||
return new MicrosoftDistributions(normalizedInstallerOptions);
|
return new MicrosoftDistributions(installerOptions);
|
||||||
case JavaDistribution.Semeru:
|
case JavaDistribution.Semeru:
|
||||||
return new SemeruDistribution(normalizedInstallerOptions);
|
return new SemeruDistribution(installerOptions);
|
||||||
case JavaDistribution.Corretto:
|
case JavaDistribution.Corretto:
|
||||||
return new CorrettoDistribution(normalizedInstallerOptions);
|
return new CorrettoDistribution(installerOptions);
|
||||||
case JavaDistribution.Oracle:
|
case JavaDistribution.Oracle:
|
||||||
return new OracleDistribution(normalizedInstallerOptions);
|
return new OracleDistribution(installerOptions);
|
||||||
case JavaDistribution.Dragonwell:
|
case JavaDistribution.Dragonwell:
|
||||||
return new DragonwellDistribution(normalizedInstallerOptions);
|
return new DragonwellDistribution(installerOptions);
|
||||||
case JavaDistribution.SapMachine:
|
case JavaDistribution.SapMachine:
|
||||||
return new SapMachineDistribution(normalizedInstallerOptions);
|
return new SapMachineDistribution(installerOptions);
|
||||||
case JavaDistribution.GraalVM:
|
case JavaDistribution.GraalVM:
|
||||||
return new GraalVMDistribution(normalizedInstallerOptions);
|
return new GraalVMDistribution(installerOptions);
|
||||||
case JavaDistribution.GraalVMCommunity:
|
case JavaDistribution.GraalVMCommunity:
|
||||||
return new GraalVMCommunityDistribution(normalizedInstallerOptions);
|
return new GraalVMCommunityDistribution(installerOptions);
|
||||||
case JavaDistribution.JetBrains:
|
case JavaDistribution.JetBrains:
|
||||||
return new JetBrainsDistribution(normalizedInstallerOptions);
|
return new JetBrainsDistribution(installerOptions);
|
||||||
case JavaDistribution.Kona:
|
case JavaDistribution.Kona:
|
||||||
return new KonaDistribution(normalizedInstallerOptions);
|
return new KonaDistribution(installerOptions);
|
||||||
case JavaDistribution.OracleOpenJdk:
|
case JavaDistribution.OracleOpenJdk:
|
||||||
return new OpenJdkDistribution(normalizedInstallerOptions);
|
return new OpenJdkDistribution(installerOptions);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,13 +46,7 @@ export class DragonwellDistribution extends JavaBase {
|
|||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
version: item.jdk_version,
|
version: item.jdk_version,
|
||||||
url: item.download_link,
|
url: item.download_link
|
||||||
checksum: item.checksum
|
|
||||||
? {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: item.checksum
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,7 +102,7 @@ export class DragonwellDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ type OsVersions = 'linux' | 'macos' | 'windows';
|
|||||||
interface GraalVMCommunityAsset {
|
interface GraalVMCommunityAsset {
|
||||||
name: string;
|
name: string;
|
||||||
browser_download_url: string;
|
browser_download_url: string;
|
||||||
digest?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GraalVMCommunityRelease {
|
interface GraalVMCommunityRelease {
|
||||||
@@ -67,7 +66,7 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
@@ -146,11 +145,7 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
const response = await this.http.head(fileUrl);
|
const response = await this.http.head(fileUrl);
|
||||||
this.handleHttpResponse(response, range);
|
this.handleHttpResponse(response, range);
|
||||||
|
|
||||||
return {
|
return {url: fileUrl, version: range};
|
||||||
url: fileUrl,
|
|
||||||
version: range,
|
|
||||||
checksum: await this.fetchChecksum(`${fileUrl}.sha256`, 'sha256')
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected validateVersionRange(range: string): void {
|
protected validateVersionRange(range: string): void {
|
||||||
@@ -289,8 +284,7 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
url: downloadUrl,
|
url: downloadUrl,
|
||||||
version: latestVersion.version,
|
version: latestVersion.version
|
||||||
checksum: await this.fetchChecksum(`${downloadUrl}.sha256`, 'sha256')
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,22 +456,9 @@ export class GraalVMCommunityDistribution extends GraalVMDistribution {
|
|||||||
for (const asset of release.assets ?? []) {
|
for (const asset of release.assets ?? []) {
|
||||||
const version = this.extractAssetVersion(asset.name, assetSuffix);
|
const version = this.extractAssetVersion(asset.name, assetSuffix);
|
||||||
if (version) {
|
if (version) {
|
||||||
const digest = asset.digest?.match(/^sha256:([a-f0-9]{64})$/i)?.[1];
|
|
||||||
if (!digest) {
|
|
||||||
core.debug(
|
|
||||||
`No authoritative sha256 digest is available for ${asset.name}; skipping checksum verification for this asset.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
versions.set(version, {
|
versions.set(version, {
|
||||||
version,
|
version,
|
||||||
url: asset.browser_download_url,
|
url: asset.browser_download_url
|
||||||
checksum: digest
|
|
||||||
? {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: digest,
|
|
||||||
source: GRAALVM_COMMUNITY_RELEASES_URL
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,17 +50,7 @@ export class JetBrainsDistribution extends JavaBase {
|
|||||||
throw this.createVersionNotFoundError(range, availableVersionStrings);
|
throw this.createVersionNotFoundError(range, availableVersionStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return resolvedFullVersion;
|
||||||
...resolvedFullVersion,
|
|
||||||
// JetBrains' `.checksum` sibling doesn't disclose its algorithm via the
|
|
||||||
// filename, and older JBR builds (e.g. JBR 11) publish a SHA-256 digest
|
|
||||||
// there while newer builds publish SHA-512. Accept either, preferring
|
|
||||||
// the stronger SHA-512 when the digest length is ambiguous.
|
|
||||||
checksum: await this.fetchChecksum(
|
|
||||||
`${resolvedFullVersion.url}.checksum`,
|
|
||||||
['sha512', 'sha256']
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async downloadTool(
|
protected async downloadTool(
|
||||||
@@ -70,7 +60,7 @@ export class JetBrainsDistribution extends JavaBase {
|
|||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
|
|
||||||
const javaArchivePath = await this.downloadAndVerify(javaRelease);
|
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, 'tar.gz');
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, 'tar.gz');
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ import {
|
|||||||
renameWinArchive
|
renameWinArchive
|
||||||
} from '../../util.js';
|
} from '../../util.js';
|
||||||
|
|
||||||
const KONA_RELEASES_URL =
|
|
||||||
'https://tencent.github.io/konajdk/releases/kona-v1.json';
|
|
||||||
|
|
||||||
export class KonaDistribution extends JavaBase {
|
export class KonaDistribution extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
super('Kona', installerOptions);
|
super('Kona', installerOptions);
|
||||||
@@ -33,7 +30,7 @@ export class KonaDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Kona JDK ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Kona JDK ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
const javaArchivePath = await this.downloadAndVerify(javaRelease);
|
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
|
|
||||||
@@ -77,14 +74,7 @@ export class KonaDistribution extends JavaBase {
|
|||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
version: item.version,
|
version: item.version,
|
||||||
url: item.downloadUrl,
|
url: item.downloadUrl
|
||||||
checksum: item.checksum
|
|
||||||
? {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: item.checksum,
|
|
||||||
source: KONA_RELEASES_URL
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
})
|
})
|
||||||
.sort((a, b) => -semver.compareBuild(a.version, b.version));
|
.sort((a, b) => -semver.compareBuild(a.version, b.version));
|
||||||
@@ -125,13 +115,16 @@ export class KonaDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async fetchReleaseInfo(): Promise<IKonaReleaseInfo | null> {
|
private async fetchReleaseInfo(): Promise<IKonaReleaseInfo | null> {
|
||||||
|
const releasesInfoUrl =
|
||||||
|
'https://tencent.github.io/konajdk/releases/kona-v1.json';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
core.debug(`Fetching Kona release info from URL: ${KONA_RELEASES_URL}`);
|
core.debug(`Fetching Kona release info from URL: ${releasesInfoUrl}`);
|
||||||
return (await this.http.getJson<IKonaReleaseInfo>(KONA_RELEASES_URL))
|
return (await this.http.getJson<IKonaReleaseInfo>(releasesInfoUrl))
|
||||||
.result;
|
.result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.debug(
|
core.debug(
|
||||||
`Fetching Kona release info from the URL: ${KONA_RELEASES_URL} failed with the error: ${
|
`Fetching Kona release info from the URL: ${releasesInfoUrl} failed with the error: ${
|
||||||
(err as Error).message
|
(err as Error).message
|
||||||
}`
|
}`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class LibericaNikDistributions extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class LibericaDistributions extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export class MicrosoftDistributions extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
if (this.verifySignature) {
|
if (this.verifySignature) {
|
||||||
if (!javaRelease.signatureUrl) {
|
if (!javaRelease.signatureUrl) {
|
||||||
@@ -114,11 +114,7 @@ export class MicrosoftDistributions extends JavaBase {
|
|||||||
return {
|
return {
|
||||||
url: file.download_url,
|
url: file.download_url,
|
||||||
signatureUrl,
|
signatureUrl,
|
||||||
version: foundRelease.version,
|
version: foundRelease.version
|
||||||
checksum: await this.fetchChecksum(
|
|
||||||
`${file.download_url}.sha256sum.txt`,
|
|
||||||
'sha256'
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,7 @@ export class OpenJdkDistribution extends JavaBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const release = matchingReleases[0];
|
return matchingReleases[0];
|
||||||
return {
|
|
||||||
...release,
|
|
||||||
checksum: await this.fetchChecksum(`${release.url}.sha256`, 'sha256')
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async downloadTool(
|
protected async downloadTool(
|
||||||
@@ -63,7 +59,7 @@ export class OpenJdkDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = javaRelease.url.endsWith('.zip') ? 'zip' : 'tar.gz';
|
const extension = javaRelease.url.endsWith('.zip') ? 'zip' : 'tar.gz';
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class OracleDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
@@ -112,11 +112,7 @@ export class OracleDistribution extends JavaBase {
|
|||||||
const response = await this.http.head(url);
|
const response = await this.http.head(url);
|
||||||
|
|
||||||
if (response.message.statusCode === HttpCodes.OK) {
|
if (response.message.statusCode === HttpCodes.OK) {
|
||||||
return {
|
return {url, version: range};
|
||||||
url,
|
|
||||||
version: range,
|
|
||||||
checksum: await this.fetchChecksum(`${url}.sha256`, 'sha256')
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.message.statusCode !== HttpCodes.NotFound) {
|
if (response.message.statusCode !== HttpCodes.NotFound) {
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
import semver from 'semver';
|
|
||||||
import {convertVersionToSemver} from '../util.js';
|
|
||||||
|
|
||||||
export enum JavaDistribution {
|
|
||||||
Adopt = 'adopt',
|
|
||||||
AdoptHotspot = 'adopt-hotspot',
|
|
||||||
AdoptOpenJ9 = 'adopt-openj9',
|
|
||||||
Temurin = 'temurin',
|
|
||||||
Zulu = 'zulu',
|
|
||||||
Liberica = 'liberica',
|
|
||||||
LibericaNik = 'liberica-nik',
|
|
||||||
JdkFile = 'jdkfile',
|
|
||||||
Microsoft = 'microsoft',
|
|
||||||
Semeru = 'semeru',
|
|
||||||
Corretto = 'corretto',
|
|
||||||
Oracle = 'oracle',
|
|
||||||
Dragonwell = 'dragonwell',
|
|
||||||
SapMachine = 'sapmachine',
|
|
||||||
GraalVM = 'graalvm',
|
|
||||||
GraalVMCommunity = 'graalvm-community',
|
|
||||||
JetBrains = 'jetbrains',
|
|
||||||
Kona = 'kona',
|
|
||||||
OracleOpenJdk = 'oracle-openjdk'
|
|
||||||
}
|
|
||||||
|
|
||||||
export const JAVA_PACKAGE_CAPABILITIES = {
|
|
||||||
[JavaDistribution.Adopt]: ['jdk', 'jre'],
|
|
||||||
[JavaDistribution.AdoptHotspot]: ['jdk', 'jre'],
|
|
||||||
[JavaDistribution.AdoptOpenJ9]: ['jdk', 'jre'],
|
|
||||||
[JavaDistribution.Temurin]: ['jdk', 'jre', 'jdk+jmods'],
|
|
||||||
[JavaDistribution.Zulu]: [
|
|
||||||
'jdk',
|
|
||||||
'jre',
|
|
||||||
'jdk+fx',
|
|
||||||
'jre+fx',
|
|
||||||
'jdk+crac',
|
|
||||||
'jre+crac'
|
|
||||||
],
|
|
||||||
[JavaDistribution.Liberica]: ['jdk', 'jre', 'jdk+fx', 'jre+fx'],
|
|
||||||
[JavaDistribution.LibericaNik]: ['jdk', 'jdk+fx'],
|
|
||||||
[JavaDistribution.JdkFile]: ['jdk'],
|
|
||||||
[JavaDistribution.Microsoft]: ['jdk'],
|
|
||||||
[JavaDistribution.Semeru]: ['jdk', 'jre'],
|
|
||||||
[JavaDistribution.Corretto]: ['jdk', 'jre'],
|
|
||||||
[JavaDistribution.Oracle]: ['jdk'],
|
|
||||||
[JavaDistribution.Dragonwell]: ['jdk'],
|
|
||||||
[JavaDistribution.SapMachine]: ['jdk', 'jre'],
|
|
||||||
[JavaDistribution.GraalVM]: ['jdk'],
|
|
||||||
[JavaDistribution.GraalVMCommunity]: ['jdk'],
|
|
||||||
[JavaDistribution.JetBrains]: [
|
|
||||||
'jdk',
|
|
||||||
'jre',
|
|
||||||
'jdk+jcef',
|
|
||||||
'jre+jcef',
|
|
||||||
'jdk+ft',
|
|
||||||
'jre+ft'
|
|
||||||
],
|
|
||||||
[JavaDistribution.Kona]: ['jdk'],
|
|
||||||
[JavaDistribution.OracleOpenJdk]: ['jdk']
|
|
||||||
} as const satisfies Record<JavaDistribution, readonly string[]>;
|
|
||||||
|
|
||||||
export function validateJavaPackage(
|
|
||||||
distributionName: string,
|
|
||||||
packageType: string,
|
|
||||||
version: string
|
|
||||||
): void {
|
|
||||||
if (!isJavaDistribution(distributionName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const supportedPackages: readonly string[] =
|
|
||||||
JAVA_PACKAGE_CAPABILITIES[distributionName];
|
|
||||||
if (!supportedPackages.includes(packageType)) {
|
|
||||||
throw createUnsupportedPackageError(
|
|
||||||
distributionName,
|
|
||||||
packageType,
|
|
||||||
supportedPackages
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
distributionName === JavaDistribution.Temurin &&
|
|
||||||
packageType === 'jdk+jmods' &&
|
|
||||||
!canResolveTemurinJmods(version)
|
|
||||||
) {
|
|
||||||
throw createUnsupportedPackageError(
|
|
||||||
distributionName,
|
|
||||||
packageType,
|
|
||||||
supportedPackages,
|
|
||||||
`Package 'jdk+jmods' requires Java 24 or later; requested version '${version}'.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isJavaDistribution(value: string): value is JavaDistribution {
|
|
||||||
return Object.prototype.hasOwnProperty.call(JAVA_PACKAGE_CAPABILITIES, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function canResolveTemurinJmods(version: string): boolean {
|
|
||||||
const normalizedVersion = version.trim().toLowerCase();
|
|
||||||
if (normalizedVersion === 'latest') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let normalizedRange = normalizedVersion
|
|
||||||
.replace(/-ea$/, '')
|
|
||||||
.replace('-ea.', '+');
|
|
||||||
if (/^\d+(\.\d+){3,}$/.test(normalizedRange)) {
|
|
||||||
normalizedRange = convertVersionToSemver(normalizedRange);
|
|
||||||
}
|
|
||||||
if (!semver.validRange(normalizedRange)) {
|
|
||||||
// JavaBase owns general version validation and its targeted error messages.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return semver.intersects(normalizedRange, '>=24.0.0', {
|
|
||||||
includePrerelease: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function createUnsupportedPackageError(
|
|
||||||
distributionName: JavaDistribution,
|
|
||||||
packageType: string,
|
|
||||||
supportedPackages: readonly string[],
|
|
||||||
detail?: string
|
|
||||||
): Error {
|
|
||||||
const message = [
|
|
||||||
`Java package '${packageType}' is not supported for distribution '${distributionName}'.`,
|
|
||||||
`Supported package types: ${supportedPackages.join(', ')}.`
|
|
||||||
];
|
|
||||||
if (detail) {
|
|
||||||
message.push(detail);
|
|
||||||
}
|
|
||||||
return new Error(message.join(' '));
|
|
||||||
}
|
|
||||||
@@ -1,306 +0,0 @@
|
|||||||
import semver from 'semver';
|
|
||||||
import {JavaDistribution} from './package-types.js';
|
|
||||||
|
|
||||||
export type JavaPlatform = 'linux' | 'macos' | 'windows' | 'solaris';
|
|
||||||
|
|
||||||
export type JavaArchitecture =
|
|
||||||
'x86' | 'x64' | 'armv7' | 'aarch64' | 'ppc64le' | 'ppc64' | 's390x';
|
|
||||||
|
|
||||||
interface VersionedArchitecture {
|
|
||||||
architecture: JavaArchitecture;
|
|
||||||
versionRange: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type ArchitectureCapability = JavaArchitecture | VersionedArchitecture;
|
|
||||||
|
|
||||||
interface RestrictedPlatformCapability {
|
|
||||||
unrestricted?: false;
|
|
||||||
platforms: Partial<Record<JavaPlatform, readonly ArchitectureCapability[]>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UnrestrictedPlatformCapability {
|
|
||||||
unrestricted: true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type JavaPlatformCapability =
|
|
||||||
RestrictedPlatformCapability | UnrestrictedPlatformCapability;
|
|
||||||
|
|
||||||
const X64_ARM64 = ['x64', 'aarch64'] as const;
|
|
||||||
const X64_X86 = ['x64', 'x86'] as const;
|
|
||||||
const STANDARD_LINUX = ['x64', 'x86', 'aarch64', 'ppc64le', 's390x'] as const;
|
|
||||||
|
|
||||||
export const JAVA_PLATFORM_CAPABILITIES: Record<
|
|
||||||
JavaDistribution,
|
|
||||||
JavaPlatformCapability
|
|
||||||
> = {
|
|
||||||
[JavaDistribution.Adopt]: {
|
|
||||||
platforms: {
|
|
||||||
linux: [...STANDARD_LINUX, {architecture: 'armv7', versionRange: '<18'}],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', 'x86', 'aarch64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.AdoptHotspot]: {
|
|
||||||
platforms: {
|
|
||||||
linux: [...STANDARD_LINUX, {architecture: 'armv7', versionRange: '<18'}],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', 'x86', 'aarch64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.AdoptOpenJ9]: {
|
|
||||||
platforms: {
|
|
||||||
linux: STANDARD_LINUX,
|
|
||||||
macos: ['x64'],
|
|
||||||
windows: X64_X86
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Temurin]: {
|
|
||||||
platforms: {
|
|
||||||
linux: [...STANDARD_LINUX, {architecture: 'armv7', versionRange: '<18'}],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', 'x86', 'aarch64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Zulu]: {
|
|
||||||
platforms: {
|
|
||||||
linux: ['x64', 'x86', 'armv7', 'aarch64'],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', 'x86', 'aarch64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Liberica]: {
|
|
||||||
platforms: {
|
|
||||||
linux: ['x64', 'x86', 'armv7', 'aarch64', 'ppc64le'],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', 'x86', 'aarch64'],
|
|
||||||
solaris: ['x64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.LibericaNik]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: X64_ARM64
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.JdkFile]: {
|
|
||||||
unrestricted: true
|
|
||||||
},
|
|
||||||
[JavaDistribution.Microsoft]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: X64_ARM64
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Semeru]: {
|
|
||||||
platforms: {
|
|
||||||
linux: ['x64', 'x86', 'ppc64le', 'ppc64', 's390x', 'aarch64'],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', 'aarch64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Corretto]: {
|
|
||||||
platforms: {
|
|
||||||
linux: [
|
|
||||||
'x64',
|
|
||||||
{architecture: 'x86', versionRange: '<12'},
|
|
||||||
{architecture: 'armv7', versionRange: '11'},
|
|
||||||
'aarch64'
|
|
||||||
],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64', {architecture: 'x86', versionRange: '<12'}]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Oracle]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Dragonwell]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
windows: ['x64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.SapMachine]: {
|
|
||||||
platforms: {
|
|
||||||
linux: ['x64', 'aarch64', 'ppc64le'],
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: X64_ARM64
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.GraalVM]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.GraalVMCommunity]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.JetBrains]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: X64_ARM64
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.Kona]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[JavaDistribution.OracleOpenJdk]: {
|
|
||||||
platforms: {
|
|
||||||
linux: X64_ARM64,
|
|
||||||
macos: X64_ARM64,
|
|
||||||
windows: ['x64']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const ARCHITECTURE_ALIASES: Readonly<Record<string, JavaArchitecture>> = {
|
|
||||||
amd64: 'x64',
|
|
||||||
arm: 'armv7',
|
|
||||||
ia32: 'x86',
|
|
||||||
arm64: 'aarch64'
|
|
||||||
};
|
|
||||||
const CANONICAL_ARCHITECTURES: readonly JavaArchitecture[] = [
|
|
||||||
'x86',
|
|
||||||
'x64',
|
|
||||||
'armv7',
|
|
||||||
'aarch64',
|
|
||||||
'ppc64le',
|
|
||||||
'ppc64',
|
|
||||||
's390x'
|
|
||||||
];
|
|
||||||
|
|
||||||
const PLATFORM_ALIASES: Readonly<
|
|
||||||
Partial<Record<NodeJS.Platform, JavaPlatform>>
|
|
||||||
> = {
|
|
||||||
darwin: 'macos',
|
|
||||||
linux: 'linux',
|
|
||||||
sunos: 'solaris',
|
|
||||||
win32: 'windows'
|
|
||||||
};
|
|
||||||
|
|
||||||
export function normalizeArchitecture(architecture: string): string {
|
|
||||||
const trimmedArchitecture = architecture.trim();
|
|
||||||
const normalizedArchitecture = trimmedArchitecture.toLowerCase();
|
|
||||||
return (
|
|
||||||
ARCHITECTURE_ALIASES[normalizedArchitecture] ??
|
|
||||||
(CANONICAL_ARCHITECTURES.includes(
|
|
||||||
normalizedArchitecture as JavaArchitecture
|
|
||||||
)
|
|
||||||
? normalizedArchitecture
|
|
||||||
: trimmedArchitecture)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizePlatform(
|
|
||||||
platform: NodeJS.Platform
|
|
||||||
): JavaPlatform | undefined {
|
|
||||||
return PLATFORM_ALIASES[platform];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function validateJavaPlatform(
|
|
||||||
distributionName: string,
|
|
||||||
platform: NodeJS.Platform,
|
|
||||||
architecture: string,
|
|
||||||
version: string
|
|
||||||
): string {
|
|
||||||
const normalizedArchitecture = normalizeArchitecture(architecture);
|
|
||||||
if (!isJavaDistribution(distributionName)) {
|
|
||||||
return normalizedArchitecture;
|
|
||||||
}
|
|
||||||
|
|
||||||
const capability = JAVA_PLATFORM_CAPABILITIES[distributionName];
|
|
||||||
if ('unrestricted' in capability && capability.unrestricted === true) {
|
|
||||||
return normalizedArchitecture;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedPlatform = normalizePlatform(platform);
|
|
||||||
const architectures = normalizedPlatform
|
|
||||||
? capability.platforms[normalizedPlatform]
|
|
||||||
: undefined;
|
|
||||||
const supported = architectures?.some(item => {
|
|
||||||
const architectureCapability =
|
|
||||||
typeof item === 'string' ? {architecture: item} : item;
|
|
||||||
return (
|
|
||||||
architectureCapability.architecture === normalizedArchitecture &&
|
|
||||||
(!('versionRange' in architectureCapability) ||
|
|
||||||
isVersionCompatible(version, architectureCapability.versionRange))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!supported) {
|
|
||||||
throw new Error(
|
|
||||||
`Distribution '${distributionName}' does not support operating system '${normalizedPlatform ?? platform}' with architecture '${normalizedArchitecture}' for Java version '${version}'. Supported combinations: ${formatSupportedCombinations(capability)}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return normalizedArchitecture;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isJavaDistribution(value: string): value is JavaDistribution {
|
|
||||||
return Object.prototype.hasOwnProperty.call(
|
|
||||||
JAVA_PLATFORM_CAPABILITIES,
|
|
||||||
value
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVersionCompatible(version: string, supportedRange: string): boolean {
|
|
||||||
let normalizedVersion = version.trim().toLowerCase();
|
|
||||||
if (normalizedVersion === 'latest') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (/^\d+(\.\d+){3,}$/.test(normalizedVersion)) {
|
|
||||||
normalizedVersion = normalizeExtendedVersionToSemver(normalizedVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestedRange = semver.validRange(
|
|
||||||
normalizedVersion.replace(/-ea$/, '')
|
|
||||||
);
|
|
||||||
const capabilityRange = semver.validRange(supportedRange);
|
|
||||||
if (!requestedRange || !capabilityRange) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeExtendedVersionToSemver(version: string): string {
|
|
||||||
const versionParts = version.split('.');
|
|
||||||
const mainVersion = versionParts.slice(0, 3).join('.');
|
|
||||||
if (versionParts.length > 3) {
|
|
||||||
return `${mainVersion}+${versionParts.slice(3).join('.')}`;
|
|
||||||
}
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
return semver.intersects(requestedRange, capabilityRange, {
|
|
||||||
includePrerelease: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatSupportedCombinations(
|
|
||||||
capability: RestrictedPlatformCapability
|
|
||||||
): string {
|
|
||||||
return Object.entries(capability.platforms)
|
|
||||||
.map(([platform, architectures]) => {
|
|
||||||
const values = architectures.map(item =>
|
|
||||||
typeof item === 'string'
|
|
||||||
? item
|
|
||||||
: `${item.architecture} (${item.versionRange})`
|
|
||||||
);
|
|
||||||
return `${platform} (${values.join(', ')})`;
|
|
||||||
})
|
|
||||||
.join('; ');
|
|
||||||
}
|
|
||||||
@@ -56,14 +56,7 @@ export class SapMachineDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const resolvedVersion = matchedVersions[0];
|
const resolvedVersion = matchedVersions[0];
|
||||||
const checksumUrl = resolvedVersion.url.replace(
|
return resolvedVersion;
|
||||||
/\.(?:tar\.gz|zip)$/,
|
|
||||||
'.sha256.txt'
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
...resolvedVersion,
|
|
||||||
checksum: await this.fetchChecksum(checksumUrl, 'sha256')
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getAvailableVersions(): Promise<ISapMachineVersions[]> {
|
private async getAvailableVersions(): Promise<ISapMachineVersions[]> {
|
||||||
@@ -111,7 +104,7 @@ export class SapMachineDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
|
|||||||
@@ -69,12 +69,7 @@ export class SemeruDistribution extends JavaBase {
|
|||||||
: item.version_data.semver.replace('-beta+', '+');
|
: item.version_data.semver.replace('-beta+', '+');
|
||||||
return {
|
return {
|
||||||
version: formattedVersion,
|
version: formattedVersion,
|
||||||
url: item.binaries[0].package.link,
|
url: item.binaries[0].package.link
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: item.binaries[0].package.checksum,
|
|
||||||
source: item.binaries[0].package.checksum_link
|
|
||||||
}
|
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,7 +104,7 @@ export class SemeruDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
|
|||||||
@@ -69,12 +69,7 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
return {
|
return {
|
||||||
version: formattedVersion,
|
version: formattedVersion,
|
||||||
url: item.binaries[0].package.link,
|
url: item.binaries[0].package.link,
|
||||||
signatureUrl: item.binaries[0].package.signature_link,
|
signatureUrl: item.binaries[0].package.signature_link
|
||||||
checksum: {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: item.binaries[0].package.checksum,
|
|
||||||
source: item.binaries[0].package.checksum_link
|
|
||||||
}
|
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -137,7 +132,7 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async downloadPackage(release: JavaDownloadRelease): Promise<string> {
|
private async downloadPackage(release: JavaDownloadRelease): Promise<string> {
|
||||||
const archivePath = await this.downloadAndVerify(release);
|
const archivePath = await tc.downloadTool(release.url);
|
||||||
|
|
||||||
if (this.verifySignature) {
|
if (this.verifySignature) {
|
||||||
if (!release.signatureUrl) {
|
if (!release.signatureUrl) {
|
||||||
@@ -282,9 +277,4 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
return process.platform;
|
return process.platform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected distributionArchitecture(): string {
|
|
||||||
const architecture = super.distributionArchitecture();
|
|
||||||
return architecture === 'armv7' ? 'arm' : architecture;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import fs from 'fs';
|
|||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
import {JavaBase} from '../base-installer.js';
|
import {JavaBase} from '../base-installer.js';
|
||||||
import {IZuluPackageDetails, IZuluVersions} from './models.js';
|
import {IZuluVersions} from './models.js';
|
||||||
import {
|
import {
|
||||||
extractJdkFile,
|
extractJdkFile,
|
||||||
getDownloadArchiveExtension,
|
getDownloadArchiveExtension,
|
||||||
@@ -20,15 +20,6 @@ import {
|
|||||||
JavaInstallerResults
|
JavaInstallerResults
|
||||||
} from '../base-models.js';
|
} from '../base-models.js';
|
||||||
|
|
||||||
// The Azul Metadata API only reports the sha256 checksum on the
|
|
||||||
// package-details endpoint, keyed by package_uuid, so the resolved candidate
|
|
||||||
// must retain its UUID after sorting until the single follow-up request is made.
|
|
||||||
interface ZuluResolvedRelease {
|
|
||||||
version: string;
|
|
||||||
url: string;
|
|
||||||
packageUuid: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ZuluDistribution extends JavaBase {
|
export class ZuluDistribution extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
super('Zulu', installerOptions);
|
super('Zulu', installerOptions);
|
||||||
@@ -49,8 +40,7 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
return {
|
return {
|
||||||
version: convertVersionToSemver(javaVersion),
|
version: convertVersionToSemver(javaVersion),
|
||||||
url: item.download_url,
|
url: item.download_url,
|
||||||
zuluVersion: convertVersionToSemver(item.distro_version),
|
zuluVersion: convertVersionToSemver(item.distro_version)
|
||||||
packageUuid: item.package_uuid
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,11 +54,12 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
-semver.compareBuild(a.zuluVersion, b.zuluVersion)
|
-semver.compareBuild(a.zuluVersion, b.zuluVersion)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.map((item): ZuluResolvedRelease => ({
|
.map(item => {
|
||||||
version: item.version,
|
return {
|
||||||
url: item.url,
|
version: item.version,
|
||||||
packageUuid: item.packageUuid
|
url: item.url
|
||||||
}));
|
} as JavaDownloadRelease;
|
||||||
|
});
|
||||||
|
|
||||||
const resolvedFullVersion =
|
const resolvedFullVersion =
|
||||||
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||||
@@ -79,29 +70,7 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
throw this.createVersionNotFoundError(version, availableVersionStrings);
|
throw this.createVersionNotFoundError(version, availableVersionStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageDetailsUrl = `https://api.azul.com/metadata/v1/zulu/packages/${resolvedFullVersion.packageUuid}`;
|
return resolvedFullVersion;
|
||||||
const packageDetails = (
|
|
||||||
await this.http.getJson<IZuluPackageDetails>(packageDetailsUrl)
|
|
||||||
).result;
|
|
||||||
const digest = packageDetails?.sha256_hash?.match(/^[a-f0-9]{64}$/i)?.[0];
|
|
||||||
|
|
||||||
if (!digest) {
|
|
||||||
core.debug(
|
|
||||||
`No authoritative sha256 checksum is available for Zulu version ${resolvedFullVersion.version} from ${packageDetailsUrl}; skipping checksum verification.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
version: resolvedFullVersion.version,
|
|
||||||
url: resolvedFullVersion.url,
|
|
||||||
checksum: digest
|
|
||||||
? {
|
|
||||||
algorithm: 'sha256',
|
|
||||||
value: digest,
|
|
||||||
source: packageDetailsUrl
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async downloadTool(
|
protected async downloadTool(
|
||||||
@@ -110,7 +79,7 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await this.downloadAndVerify(javaRelease);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
@@ -221,8 +190,6 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
// would let a 32-bit request resolve to a 64-bit JDK. Use "i686" to
|
// would let a 32-bit request resolve to a 64-bit JDK. Use "i686" to
|
||||||
// target only genuine 32-bit builds, matching the legacy API behavior.
|
// target only genuine 32-bit builds, matching the legacy API behavior.
|
||||||
return 'i686';
|
return 'i686';
|
||||||
case 'armv7':
|
|
||||||
return 'arm';
|
|
||||||
case 'aarch64':
|
case 'aarch64':
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
return 'aarch64';
|
return 'aarch64';
|
||||||
|
|||||||
@@ -10,7 +10,3 @@ export interface IZuluVersions {
|
|||||||
latest: boolean;
|
latest: boolean;
|
||||||
availability_type: string;
|
availability_type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IZuluPackageDetails {
|
|
||||||
sha256_hash?: string;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,166 +0,0 @@
|
|||||||
import * as core from '@actions/core';
|
|
||||||
import * as httpm from '@actions/http-client';
|
|
||||||
import type {OutgoingHttpHeaders} from 'http';
|
|
||||||
|
|
||||||
const RETRYABLE_HTTP_STATUS_CODES = new Set([429, 502, 503, 504, 522]);
|
|
||||||
const RETRYABLE_NETWORK_ERROR_CODES = new Set([
|
|
||||||
'ETIMEDOUT',
|
|
||||||
'ECONNRESET',
|
|
||||||
'ENOTFOUND',
|
|
||||||
'ECONNREFUSED'
|
|
||||||
]);
|
|
||||||
const RETRYABLE_HTTP_VERBS = new Set(['OPTIONS', 'GET', 'DELETE', 'HEAD']);
|
|
||||||
|
|
||||||
export interface HttpRetryOptions {
|
|
||||||
maxAttempts?: number;
|
|
||||||
baseDelayMs?: number;
|
|
||||||
maxDelayMs?: number;
|
|
||||||
sleep?: (delayMs: number) => Promise<void>;
|
|
||||||
random?: () => number;
|
|
||||||
now?: () => number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class RetryingHttpClient extends httpm.HttpClient {
|
|
||||||
private readonly maxAttempts: number;
|
|
||||||
private readonly baseDelayMs: number;
|
|
||||||
private readonly maxDelayMs: number;
|
|
||||||
private readonly sleep: (delayMs: number) => Promise<void>;
|
|
||||||
private readonly random: () => number;
|
|
||||||
private readonly now: () => number;
|
|
||||||
|
|
||||||
constructor(userAgent?: string, retryOptions: HttpRetryOptions = {}) {
|
|
||||||
super(userAgent, undefined, {allowRetries: false});
|
|
||||||
this.maxAttempts = retryOptions.maxAttempts ?? 4;
|
|
||||||
this.baseDelayMs = retryOptions.baseDelayMs ?? 1000;
|
|
||||||
this.maxDelayMs = retryOptions.maxDelayMs ?? 10000;
|
|
||||||
this.sleep =
|
|
||||||
retryOptions.sleep ??
|
|
||||||
(delayMs => new Promise(resolve => setTimeout(resolve, delayMs)));
|
|
||||||
this.random = retryOptions.random ?? Math.random;
|
|
||||||
this.now = retryOptions.now ?? Date.now;
|
|
||||||
|
|
||||||
if (this.maxAttempts < 1) {
|
|
||||||
throw new Error('maxAttempts must be at least 1');
|
|
||||||
}
|
|
||||||
if (this.baseDelayMs < 0 || this.maxDelayMs < this.baseDelayMs) {
|
|
||||||
throw new Error(
|
|
||||||
'baseDelayMs must be non-negative and no greater than maxDelayMs'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async request(
|
|
||||||
verb: string,
|
|
||||||
requestUrl: string,
|
|
||||||
data: string | NodeJS.ReadableStream | null,
|
|
||||||
headers?: OutgoingHttpHeaders
|
|
||||||
): Promise<httpm.HttpClientResponse> {
|
|
||||||
if (!RETRYABLE_HTTP_VERBS.has(verb)) {
|
|
||||||
return super.request(verb, requestUrl, data, headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let attempt = 1; attempt <= this.maxAttempts; attempt++) {
|
|
||||||
try {
|
|
||||||
const response = await super.request(verb, requestUrl, data, headers);
|
|
||||||
const statusCode = response.message.statusCode;
|
|
||||||
if (
|
|
||||||
!statusCode ||
|
|
||||||
!RETRYABLE_HTTP_STATUS_CODES.has(statusCode) ||
|
|
||||||
attempt === this.maxAttempts
|
|
||||||
) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
const delayMs = this.getDelayMs(
|
|
||||||
attempt,
|
|
||||||
response.message.headers['retry-after']
|
|
||||||
);
|
|
||||||
await response.readBody();
|
|
||||||
this.logRetry(attempt, delayMs, `HTTP ${statusCode}`);
|
|
||||||
await this.sleep(delayMs);
|
|
||||||
} catch (error) {
|
|
||||||
if (!isRetryableNetworkError(error) || attempt === this.maxAttempts) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const delayMs = this.getDelayMs(attempt);
|
|
||||||
this.logRetry(attempt, delayMs, getErrorMessage(error));
|
|
||||||
await this.sleep(delayMs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('HTTP retry attempts exhausted unexpectedly');
|
|
||||||
}
|
|
||||||
|
|
||||||
private getDelayMs(
|
|
||||||
failedAttempt: number,
|
|
||||||
retryAfter?: string | string[]
|
|
||||||
): number {
|
|
||||||
const exponentialDelay = Math.min(
|
|
||||||
this.maxDelayMs,
|
|
||||||
this.baseDelayMs * 2 ** (failedAttempt - 1)
|
|
||||||
);
|
|
||||||
const jitteredDelay = Math.floor(
|
|
||||||
exponentialDelay / 2 + this.random() * (exponentialDelay / 2)
|
|
||||||
);
|
|
||||||
const retryAfterDelay = parseRetryAfter(retryAfter, this.now());
|
|
||||||
return Math.min(
|
|
||||||
this.maxDelayMs,
|
|
||||||
Math.max(jitteredDelay, retryAfterDelay ?? 0)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private logRetry(
|
|
||||||
failedAttempt: number,
|
|
||||||
delayMs: number,
|
|
||||||
reason: string
|
|
||||||
): void {
|
|
||||||
core.info(
|
|
||||||
`Request attempt ${failedAttempt} of ${this.maxAttempts} failed (${reason}); retrying in ${delayMs} ms`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseRetryAfter(
|
|
||||||
value: string | string[] | undefined,
|
|
||||||
nowMs: number
|
|
||||||
): number | undefined {
|
|
||||||
const retryAfter = Array.isArray(value) ? value[0] : value;
|
|
||||||
if (!retryAfter) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/^\d+$/.test(retryAfter.trim())) {
|
|
||||||
return Number(retryAfter) * 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
const retryAt = Date.parse(retryAfter);
|
|
||||||
if (Number.isNaN(retryAt) || retryAt <= nowMs) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return retryAt - nowMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isRetryableNetworkError(error: unknown): boolean {
|
|
||||||
if (!isErrorRecord(error)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
typeof error.code === 'string' &&
|
|
||||||
RETRYABLE_NETWORK_ERROR_CODES.has(error.code)
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
Array.isArray(error.errors) &&
|
|
||||||
error.errors.some(nestedError => isRetryableNetworkError(nestedError))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isErrorRecord(error: unknown): error is Record<string, unknown> {
|
|
||||||
return typeof error === 'object' && error !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getErrorMessage(error: unknown): string {
|
|
||||||
return error instanceof Error ? error.message : 'network error';
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,7 @@ import {JavaInstallerOptions} from './distributions/base-models.js';
|
|||||||
import {configureMavenArgs} from './maven-args.js';
|
import {configureMavenArgs} from './maven-args.js';
|
||||||
import {configureProblemMatcher} from './problem-matcher.js';
|
import {configureProblemMatcher} from './problem-matcher.js';
|
||||||
|
|
||||||
export async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||||
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
|
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
|
||||||
@@ -28,7 +28,6 @@ export async function run() {
|
|||||||
const cacheDependencyPath = core.getInput(
|
const cacheDependencyPath = core.getInput(
|
||||||
constants.INPUT_CACHE_DEPENDENCY_PATH
|
constants.INPUT_CACHE_DEPENDENCY_PATH
|
||||||
);
|
);
|
||||||
const cachePath = core.getMultilineInput(constants.INPUT_CACHE_PATH);
|
|
||||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||||
const forceDownload = getBooleanInput(
|
const forceDownload = getBooleanInput(
|
||||||
constants.INPUT_FORCE_DOWNLOAD,
|
constants.INPUT_FORCE_DOWNLOAD,
|
||||||
@@ -41,18 +40,18 @@ export async function run() {
|
|||||||
);
|
);
|
||||||
const verifySignaturePublicKey =
|
const verifySignaturePublicKey =
|
||||||
core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
||||||
const toolchainIds = core.getMultilineInput(
|
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
||||||
constants.INPUT_MVN_TOOLCHAIN_ID
|
|
||||||
);
|
|
||||||
|
|
||||||
core.startGroup('Installed distributions');
|
core.startGroup('Installed distributions');
|
||||||
|
|
||||||
|
if (versions.length !== toolchainIds.length) {
|
||||||
|
toolchainIds = [];
|
||||||
|
}
|
||||||
|
|
||||||
if (!versions.length && !versionFile) {
|
if (!versions.length && !versionFile) {
|
||||||
throw new Error('java-version or java-version-file input expected');
|
throw new Error('java-version or java-version-file input expected');
|
||||||
}
|
}
|
||||||
|
|
||||||
toolchains.validateToolchainIds(versions, versionFile, toolchainIds);
|
|
||||||
|
|
||||||
if (!versions.length) {
|
if (!versions.length) {
|
||||||
core.debug(
|
core.debug(
|
||||||
'java-version input is empty, looking for java-version-file input'
|
'java-version input is empty, looking for java-version-file input'
|
||||||
@@ -133,19 +132,14 @@ export async function run() {
|
|||||||
await auth.configureAuthentication();
|
await auth.configureAuthentication();
|
||||||
configureMavenArgs();
|
configureMavenArgs();
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
await restore(cache, cacheDependencyPath, cachePath);
|
await restore(cache, cacheDependencyPath);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed((error as Error).message);
|
core.setFailed((error as Error).message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
run();
|
||||||
run();
|
|
||||||
} else {
|
|
||||||
// https://nodejs.org/api/modules.html#modules_accessing_the_main_module
|
|
||||||
core.info('the script is loaded as a module, so skipping the execution');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getJdkFileInput(): string {
|
function getJdkFileInput(): string {
|
||||||
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
||||||
|
|||||||
@@ -14,23 +14,6 @@ interface JdkInfo {
|
|||||||
jdkHome: string;
|
jdkHome: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateToolchainIds(
|
|
||||||
versions: string[],
|
|
||||||
versionFile: string,
|
|
||||||
toolchainIds: string[]
|
|
||||||
) {
|
|
||||||
if (!toolchainIds.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionCount = versions.length || (versionFile ? 1 : 0);
|
|
||||||
if (versionCount !== toolchainIds.length) {
|
|
||||||
throw new Error(
|
|
||||||
`The number of Maven toolchain IDs (${toolchainIds.length}) must match the number of Java versions (${versionCount})`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function configureToolchains(
|
export async function configureToolchains(
|
||||||
version: string,
|
version: string,
|
||||||
distributionName: string,
|
distributionName: string,
|
||||||
|
|||||||
17
src/util.ts
17
src/util.ts
@@ -20,21 +20,8 @@ export function getTempDir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBooleanInput(inputName: string, defaultValue = false) {
|
export function getBooleanInput(inputName: string, defaultValue = false) {
|
||||||
const inputValue = core.getInput(inputName);
|
return (
|
||||||
const normalizedValue = inputValue.trim().toLowerCase();
|
(core.getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE'
|
||||||
|
|
||||||
if (!normalizedValue) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
if (normalizedValue === 'true') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (normalizedValue === 'false') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(
|
|
||||||
`Invalid value '${inputValue}' for boolean input '${inputName}'. Expected 'true' or 'false'.`
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user