mirror of
				https://github.com/actions/setup-java.git
				synced 2025-11-04 08:20:54 +00:00 
			
		
		
		
	pull latest main
This commit is contained in:
		
					parent
					
						
							
								793a1df84f
							
						
					
				
			
			
				commit
				
					
						e9a0f2c685
					
				
			
		
					 8 changed files with 172 additions and 92 deletions
				
			
		
							
								
								
									
										76
									
								
								.github/workflows/e2e-versions.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										76
									
								
								.github/workflows/e2e-versions.yml
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -29,7 +29,6 @@ jobs:
 | 
				
			||||||
        id: setup-java
 | 
					        id: setup-java
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          java-version: ${{ matrix.version }}
 | 
					          java-version: ${{ matrix.version }}
 | 
				
			||||||
          java-package: 'jdk'
 | 
					 | 
				
			||||||
          distribution: ${{ matrix.distribution }}
 | 
					          distribution: ${{ matrix.distribution }}
 | 
				
			||||||
      - name: Verify Java
 | 
					      - name: Verify Java
 | 
				
			||||||
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
					        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
				
			||||||
| 
						 | 
					@ -45,17 +44,19 @@ jobs:
 | 
				
			||||||
        os: [macos-latest, windows-latest, ubuntu-latest]
 | 
					        os: [macos-latest, windows-latest, ubuntu-latest]
 | 
				
			||||||
        distribution: ['adoptium', 'zulu']
 | 
					        distribution: ['adoptium', 'zulu']
 | 
				
			||||||
        version:
 | 
					        version:
 | 
				
			||||||
        - '8.0.282'
 | 
					 | 
				
			||||||
        - '11.0'
 | 
					        - '11.0'
 | 
				
			||||||
        - '11.0.10'
 | 
					        - '8.0.282'
 | 
				
			||||||
        - '15.0'
 | 
					        - '11.0.2+7'
 | 
				
			||||||
        exclude:
 | 
					        include:
 | 
				
			||||||
          - os: windows-latest
 | 
					          - distribution: 'adoptium'
 | 
				
			||||||
            distribution: 'zulu'
 | 
					            version: '12.0.2+10.1'
 | 
				
			||||||
            version: '8.0.282'
 | 
					            os: macos-latest
 | 
				
			||||||
          - os: windows-latest
 | 
					          - distribution: 'adoptium'
 | 
				
			||||||
            distribution: 'zulu'
 | 
					            version: '12.0.2+10.1'
 | 
				
			||||||
            version: '11.0.10'
 | 
					            os: windows-latest
 | 
				
			||||||
 | 
					          - distribution: 'adoptium'
 | 
				
			||||||
 | 
					            version: '12.0.2+10.1'
 | 
				
			||||||
 | 
					            os: ubuntu-latest
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Checkout
 | 
					      - name: Checkout
 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
| 
						 | 
					@ -64,22 +65,20 @@ jobs:
 | 
				
			||||||
        id: setup-java
 | 
					        id: setup-java
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          java-version: ${{ matrix.version }}
 | 
					          java-version: ${{ matrix.version }}
 | 
				
			||||||
          java-package: jdk
 | 
					 | 
				
			||||||
          distribution: ${{ matrix.distribution }}
 | 
					          distribution: ${{ matrix.distribution }}
 | 
				
			||||||
      - name: Verify Java
 | 
					      - name: Verify Java
 | 
				
			||||||
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
					        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
				
			||||||
        shell: bash
 | 
					        shell: bash
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  setup-java-ea-versions:
 | 
					  setup-java-ea-versions-zulu:
 | 
				
			||||||
    name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
 | 
					    name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
 | 
				
			||||||
    needs: setup-java-major-minor-versions
 | 
					    needs: setup-java-major-minor-versions
 | 
				
			||||||
    runs-on: ${{ matrix.os }}
 | 
					    runs-on: ${{ matrix.os }}
 | 
				
			||||||
    strategy:
 | 
					    strategy:
 | 
				
			||||||
      fail-fast: false
 | 
					      fail-fast: false
 | 
				
			||||||
      matrix:
 | 
					      matrix:
 | 
				
			||||||
        os: [macos-latest, windows-latest, ubuntu-latest]
 | 
					        os: [macos-latest, windows-latest, ubuntu-latest]
 | 
				
			||||||
        distribution: ['adoptium', 'zulu']
 | 
					        version: ['17-ea', '15.0.0-ea.14']
 | 
				
			||||||
        version: ['14-ea', '15-ea']
 | 
					 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Checkout
 | 
					      - name: Checkout
 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
| 
						 | 
					@ -88,11 +87,26 @@ jobs:
 | 
				
			||||||
        id: setup-java
 | 
					        id: setup-java
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          java-version: ${{ matrix.version }}
 | 
					          java-version: ${{ matrix.version }}
 | 
				
			||||||
          java-package: jdk
 | 
					          distribution: zulu
 | 
				
			||||||
          distribution: ${{ matrix.distribution }}
 | 
					
 | 
				
			||||||
      - name: Verify Java
 | 
					  setup-java-ea-versions-adoptium:
 | 
				
			||||||
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
					    name: adoptium ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
 | 
				
			||||||
        shell: bash
 | 
					    needs: setup-java-major-minor-versions
 | 
				
			||||||
 | 
					    runs-on: ${{ matrix.os }}
 | 
				
			||||||
 | 
					    strategy:
 | 
				
			||||||
 | 
					      fail-fast: false
 | 
				
			||||||
 | 
					      matrix:
 | 
				
			||||||
 | 
					        os: [macos-latest, windows-latest, ubuntu-latest]
 | 
				
			||||||
 | 
					        version: ['17-ea', '15.0.0-ea.14.1.202003160455']
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - name: Checkout
 | 
				
			||||||
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
 | 
					      - name: setup-java
 | 
				
			||||||
 | 
					        uses: ./
 | 
				
			||||||
 | 
					        id: setup-java
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          java-version: ${{ matrix.version }}
 | 
				
			||||||
 | 
					          distribution: adoptium
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setup-java-custom-package-type:
 | 
					  setup-java-custom-package-type:
 | 
				
			||||||
    name: ${{ matrix.distribution }} ${{ matrix.version }} (${{ matrix.java-package }}-x64) - ${{ matrix.os }}
 | 
					    name: ${{ matrix.distribution }} ${{ matrix.version }} (${{ matrix.java-package }}-x64) - ${{ matrix.os }}
 | 
				
			||||||
| 
						 | 
					@ -105,18 +119,7 @@ jobs:
 | 
				
			||||||
        distribution: ['adoptium', 'zulu']
 | 
					        distribution: ['adoptium', 'zulu']
 | 
				
			||||||
        java-package: ['jre']
 | 
					        java-package: ['jre']
 | 
				
			||||||
        version:
 | 
					        version:
 | 
				
			||||||
        - '8.0.282'
 | 
					 | 
				
			||||||
        - '11.0.10'
 | 
					 | 
				
			||||||
        - '15.0'
 | 
					        - '15.0'
 | 
				
			||||||
        exclude:
 | 
					 | 
				
			||||||
          - os: windows-latest
 | 
					 | 
				
			||||||
            distribution: 'zulu'
 | 
					 | 
				
			||||||
            java-package: 'jre'
 | 
					 | 
				
			||||||
            version: '8.0.282'
 | 
					 | 
				
			||||||
          - os: windows-latest
 | 
					 | 
				
			||||||
            java-package: 'jre'
 | 
					 | 
				
			||||||
            distribution: 'zulu'
 | 
					 | 
				
			||||||
            version: '11.0.10'
 | 
					 | 
				
			||||||
        include:
 | 
					        include:
 | 
				
			||||||
          - distribution: 'zulu'
 | 
					          - distribution: 'zulu'
 | 
				
			||||||
            java-package: jre+fx
 | 
					            java-package: jre+fx
 | 
				
			||||||
| 
						 | 
					@ -150,7 +153,7 @@ jobs:
 | 
				
			||||||
        # Only Zulu provides x86 arch for now and only for windows / ubuntu
 | 
					        # Only Zulu provides x86 arch for now and only for windows / ubuntu
 | 
				
			||||||
        os: [windows-latest, ubuntu-latest]
 | 
					        os: [windows-latest, ubuntu-latest]
 | 
				
			||||||
        distribution: ['zulu']
 | 
					        distribution: ['zulu']
 | 
				
			||||||
        version: ['8', '11']
 | 
					        version: ['11']
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Checkout
 | 
					      - name: Checkout
 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
| 
						 | 
					@ -160,7 +163,4 @@ jobs:
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          distribution: ${{ matrix.distribution }}
 | 
					          distribution: ${{ matrix.distribution }}
 | 
				
			||||||
          java-version: ${{ matrix.version }}
 | 
					          java-version: ${{ matrix.version }}
 | 
				
			||||||
          architecture: x86
 | 
					          architecture: x86
 | 
				
			||||||
      - name: Verify Java
 | 
					 | 
				
			||||||
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
					 | 
				
			||||||
        shell: bash
 | 
					 | 
				
			||||||
| 
						 | 
					@ -528,6 +528,47 @@
 | 
				
			||||||
            "semver": "12.0.2+10.2"
 | 
					            "semver": "12.0.2+10.2"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "binaries": [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "architecture": "x64",
 | 
				
			||||||
 | 
					                "download_count": 24493,
 | 
				
			||||||
 | 
					                "heap_size": "normal",
 | 
				
			||||||
 | 
					                "image_type": "jdk",
 | 
				
			||||||
 | 
					                "jvm_impl": "hotspot",
 | 
				
			||||||
 | 
					                "os": "mac",
 | 
				
			||||||
 | 
					                "package": {
 | 
				
			||||||
 | 
					                    "checksum": "9919eee037554d40c7d2f219bbd654f2bf119e16a2f4d284d8dedaf525ee59e6",
 | 
				
			||||||
 | 
					                    "checksum_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz.sha256.txt",
 | 
				
			||||||
 | 
					                    "download_count": 22907,
 | 
				
			||||||
 | 
					                    "link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz",
 | 
				
			||||||
 | 
					                    "metadata_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz.json",
 | 
				
			||||||
 | 
					                    "name": "OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz",
 | 
				
			||||||
 | 
					                    "size": 198392994
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                "project": "jdk",
 | 
				
			||||||
 | 
					                "scm_ref": "jdk-12.0.2+9_adopt",
 | 
				
			||||||
 | 
					                "updated_at": "2019-07-18T20:27:24Z"
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "download_count": 396318,
 | 
				
			||||||
 | 
					        "id": "MDc6UmVsZWFzZTE4NzE2Mzk5.S/VUFSgnrVIv8A==",
 | 
				
			||||||
 | 
					        "release_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/tag/jdk-12.0.2%2B10",
 | 
				
			||||||
 | 
					        "release_name": "jdk-12.0.2+9",
 | 
				
			||||||
 | 
					        "release_type": "ga",
 | 
				
			||||||
 | 
					        "timestamp": "2019-07-18T20:26:29Z",
 | 
				
			||||||
 | 
					        "updated_at": "2019-07-18T20:26:29Z",
 | 
				
			||||||
 | 
					        "vendor": "adoptopenjdk",
 | 
				
			||||||
 | 
					        "version_data": {
 | 
				
			||||||
 | 
					            "adopt_build_number": 1,
 | 
				
			||||||
 | 
					            "build": 10,
 | 
				
			||||||
 | 
					            "major": 12,
 | 
				
			||||||
 | 
					            "minor": 0,
 | 
				
			||||||
 | 
					            "openjdk_version": "12.0.2+9",
 | 
				
			||||||
 | 
					            "security": 2,
 | 
				
			||||||
 | 
					            "semver": "12.0.2+9.1"
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        "binaries": [
 | 
					        "binaries": [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +96,10 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
    ['15.0.1', '15.0.1+9.1'],
 | 
					    ['15.0.1', '15.0.1+9.1'],
 | 
				
			||||||
    ['11.x', '11.0.10+9'],
 | 
					    ['11.x', '11.0.10+9'],
 | 
				
			||||||
    ['x', '15.0.2+7'],
 | 
					    ['x', '15.0.2+7'],
 | 
				
			||||||
    ['12', '12.0.2+10.3'] // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly
 | 
					    ['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly
 | 
				
			||||||
 | 
					    ['12.0.2+10.1', '12.0.2+10.1'],
 | 
				
			||||||
 | 
					    ['15.0.1+9', '15.0.1+9'],
 | 
				
			||||||
 | 
					    ['15.0.1+9.1', '15.0.1+9.1']
 | 
				
			||||||
  ])('version is resolved correctly %s -> %s', async (input, expected) => {
 | 
					  ])('version is resolved correctly %s -> %s', async (input, expected) => {
 | 
				
			||||||
    const distribution = new AdoptiumDistribution({
 | 
					    const distribution = new AdoptiumDistribution({
 | 
				
			||||||
      version: '11',
 | 
					      version: '11',
 | 
				
			||||||
| 
						 | 
					@ -104,7 +107,7 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
      packageType: 'jdk'
 | 
					      packageType: 'jdk'
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    distribution['getAvailableVersions'] = async () => manifestData;
 | 
					    distribution['getAvailableVersions'] = async () => manifestData;
 | 
				
			||||||
    const resolvedVersion = await distribution['findPackageForDownload'](new semver.Range(input));
 | 
					    const resolvedVersion = await distribution['findPackageForDownload'](input);
 | 
				
			||||||
    expect(resolvedVersion.version).toBe(expected);
 | 
					    expect(resolvedVersion.version).toBe(expected);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -115,9 +118,9 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
      packageType: 'jdk'
 | 
					      packageType: 'jdk'
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    distribution['getAvailableVersions'] = async () => manifestData;
 | 
					    distribution['getAvailableVersions'] = async () => manifestData;
 | 
				
			||||||
    await expect(
 | 
					    await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
 | 
				
			||||||
      distribution['findPackageForDownload'](new semver.Range('9.0.8'))
 | 
					      /Could not find satisfied version for SemVer */
 | 
				
			||||||
    ).rejects.toThrowError(/Could not find satisfied version for SemVer */);
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('version is not found', async () => {
 | 
					  it('version is not found', async () => {
 | 
				
			||||||
| 
						 | 
					@ -127,9 +130,9 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
      packageType: 'jdk'
 | 
					      packageType: 'jdk'
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    distribution['getAvailableVersions'] = async () => manifestData;
 | 
					    distribution['getAvailableVersions'] = async () => manifestData;
 | 
				
			||||||
    await expect(
 | 
					    await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
 | 
				
			||||||
      distribution['findPackageForDownload'](new semver.Range('7.x'))
 | 
					      /Could not find satisfied version for SemVer */
 | 
				
			||||||
    ).rejects.toThrowError(/Could not find satisfied version for SemVer */);
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('version list is empty', async () => {
 | 
					  it('version list is empty', async () => {
 | 
				
			||||||
| 
						 | 
					@ -139,8 +142,8 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
      packageType: 'jdk'
 | 
					      packageType: 'jdk'
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    distribution['getAvailableVersions'] = async () => [];
 | 
					    distribution['getAvailableVersions'] = async () => [];
 | 
				
			||||||
    await expect(
 | 
					    await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError(
 | 
				
			||||||
      distribution['findPackageForDownload'](new semver.Range('11'))
 | 
					      /Could not find satisfied version for SemVer */
 | 
				
			||||||
    ).rejects.toThrowError(/Could not find satisfied version for SemVer */);
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
import * as tc from '@actions/tool-cache';
 | 
					import * as tc from '@actions/tool-cache';
 | 
				
			||||||
import * as core from '@actions/core';
 | 
					import * as core from '@actions/core';
 | 
				
			||||||
 | 
					import * as util from '../../src/util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import path from 'path';
 | 
					import path from 'path';
 | 
				
			||||||
import * as semver from 'semver';
 | 
					import * as semver from 'semver';
 | 
				
			||||||
| 
						 | 
					@ -23,7 +24,7 @@ class EmptyJavaBase extends JavaBase {
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  protected async findPackageForDownload(range: semver.Range): Promise<JavaDownloadRelease> {
 | 
					  protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
 | 
				
			||||||
    const availableVersion = '11.0.8';
 | 
					    const availableVersion = '11.0.8';
 | 
				
			||||||
    if (!semver.satisfies(availableVersion, range)) {
 | 
					    if (!semver.satisfies(availableVersion, range)) {
 | 
				
			||||||
      throw new Error('Available version not found');
 | 
					      throw new Error('Available version not found');
 | 
				
			||||||
| 
						 | 
					@ -41,11 +42,11 @@ describe('findInToolcache', () => {
 | 
				
			||||||
  const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x64');
 | 
					  const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x64');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let mockJavaBase: EmptyJavaBase;
 | 
					  let mockJavaBase: EmptyJavaBase;
 | 
				
			||||||
  let spyTcFind: jest.SpyInstance;
 | 
					  let spyGetToolcachePath: jest.SpyInstance;
 | 
				
			||||||
  let spyTcFindAllVersions: jest.SpyInstance;
 | 
					  let spyTcFindAllVersions: jest.SpyInstance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  beforeEach(() => {
 | 
					  beforeEach(() => {
 | 
				
			||||||
    spyTcFind = jest.spyOn(tc, 'find');
 | 
					    spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
 | 
				
			||||||
    spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
 | 
					    spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,15 +75,17 @@ describe('findInToolcache', () => {
 | 
				
			||||||
    [{ version: '11', arch: 'x86', packageType: 'jre' }, null]
 | 
					    [{ version: '11', arch: 'x86', packageType: 'jre' }, null]
 | 
				
			||||||
  ])(`should find java for path %s -> %s`, (input, expected) => {
 | 
					  ])(`should find java for path %s -> %s`, (input, expected) => {
 | 
				
			||||||
    spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
 | 
					    spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
 | 
				
			||||||
    spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
 | 
					    spyGetToolcachePath.mockImplementation(
 | 
				
			||||||
      const semverVersion = new semver.Range(javaVersion);
 | 
					      (toolname: string, javaVersion: string, architecture: string) => {
 | 
				
			||||||
 | 
					        const semverVersion = new semver.Range(javaVersion);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
 | 
					        if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
 | 
				
			||||||
        return '';
 | 
					          return '';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
      return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    mockJavaBase = new EmptyJavaBase(input);
 | 
					    mockJavaBase = new EmptyJavaBase(input);
 | 
				
			||||||
    expect(mockJavaBase['findInToolcache']()).toEqual(expected);
 | 
					    expect(mockJavaBase['findInToolcache']()).toEqual(expected);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
| 
						 | 
					@ -108,7 +111,7 @@ describe('findInToolcache', () => {
 | 
				
			||||||
      '11.3.2-ea',
 | 
					      '11.3.2-ea',
 | 
				
			||||||
      '11.0.1'
 | 
					      '11.0.1'
 | 
				
			||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
    spyTcFind.mockImplementation(
 | 
					    spyGetToolcachePath.mockImplementation(
 | 
				
			||||||
      (toolname: string, javaVersion: string, architecture: string) =>
 | 
					      (toolname: string, javaVersion: string, architecture: string) =>
 | 
				
			||||||
        `/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
 | 
					        `/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
| 
						 | 
					@ -124,7 +127,7 @@ describe('setupJava', () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let mockJavaBase: EmptyJavaBase;
 | 
					  let mockJavaBase: EmptyJavaBase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let spyTcFind: jest.SpyInstance;
 | 
					  let spyGetToolcachePath: jest.SpyInstance;
 | 
				
			||||||
  let spyTcFindAllVersions: jest.SpyInstance;
 | 
					  let spyTcFindAllVersions: jest.SpyInstance;
 | 
				
			||||||
  let spyCoreDebug: jest.SpyInstance;
 | 
					  let spyCoreDebug: jest.SpyInstance;
 | 
				
			||||||
  let spyCoreInfo: jest.SpyInstance;
 | 
					  let spyCoreInfo: jest.SpyInstance;
 | 
				
			||||||
| 
						 | 
					@ -133,16 +136,18 @@ describe('setupJava', () => {
 | 
				
			||||||
  let spyCoreSetOutput: jest.SpyInstance;
 | 
					  let spyCoreSetOutput: jest.SpyInstance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  beforeEach(() => {
 | 
					  beforeEach(() => {
 | 
				
			||||||
    spyTcFind = jest.spyOn(tc, 'find');
 | 
					    spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
 | 
				
			||||||
    spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
 | 
					    spyGetToolcachePath.mockImplementation(
 | 
				
			||||||
      const semverVersion = new semver.Range(javaVersion);
 | 
					      (toolname: string, javaVersion: string, architecture: string) => {
 | 
				
			||||||
 | 
					        const semverVersion = new semver.Range(javaVersion);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
 | 
					        if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
 | 
				
			||||||
        return '';
 | 
					          return '';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
      return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
 | 
					    spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
 | 
				
			||||||
    spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
 | 
					    spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
 | 
				
			||||||
| 
						 | 
					@ -186,7 +191,7 @@ describe('setupJava', () => {
 | 
				
			||||||
  ])('should find java locally for %s', (input, expected) => {
 | 
					  ])('should find java locally for %s', (input, expected) => {
 | 
				
			||||||
    mockJavaBase = new EmptyJavaBase(input);
 | 
					    mockJavaBase = new EmptyJavaBase(input);
 | 
				
			||||||
    expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
					    expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
				
			||||||
    expect(spyTcFind).toHaveBeenCalled();
 | 
					    expect(spyGetToolcachePath).toHaveBeenCalled();
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it.each([
 | 
					  it.each([
 | 
				
			||||||
| 
						 | 
					@ -205,7 +210,7 @@ describe('setupJava', () => {
 | 
				
			||||||
  ])('download java with configuration %s', async (input, expected) => {
 | 
					  ])('download java with configuration %s', async (input, expected) => {
 | 
				
			||||||
    mockJavaBase = new EmptyJavaBase(input);
 | 
					    mockJavaBase = new EmptyJavaBase(input);
 | 
				
			||||||
    await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
					    await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
				
			||||||
    expect(spyTcFind).toHaveBeenCalled();
 | 
					    expect(spyGetToolcachePath).toHaveBeenCalled();
 | 
				
			||||||
    expect(spyCoreAddPath).toHaveBeenCalled();
 | 
					    expect(spyCoreAddPath).toHaveBeenCalled();
 | 
				
			||||||
    expect(spyCoreExportVariable).toHaveBeenCalled();
 | 
					    expect(spyCoreExportVariable).toHaveBeenCalled();
 | 
				
			||||||
    expect(spyCoreSetOutput).toHaveBeenCalled();
 | 
					    expect(spyCoreSetOutput).toHaveBeenCalled();
 | 
				
			||||||
| 
						 | 
					@ -228,11 +233,11 @@ describe('normalizeVersion', () => {
 | 
				
			||||||
  const DummyJavaBase = JavaBase as any;
 | 
					  const DummyJavaBase = JavaBase as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it.each([
 | 
					  it.each([
 | 
				
			||||||
    ['11', { version: new semver.Range('11'), stable: true }],
 | 
					    ['11', { version: '11', stable: true }],
 | 
				
			||||||
    ['11.0', { version: new semver.Range('11.0'), stable: true }],
 | 
					    ['11.0', { version: '11.0', stable: true }],
 | 
				
			||||||
    ['11.0.10', { version: new semver.Range('11.0.10'), stable: true }],
 | 
					    ['11.0.10', { version: '11.0.10', stable: true }],
 | 
				
			||||||
    ['11-ea', { version: new semver.Range('11'), stable: false }],
 | 
					    ['11-ea', { version: '11', stable: false }],
 | 
				
			||||||
    ['11.0.2-ea', { version: new semver.Range('11.0.2'), stable: false }]
 | 
					    ['11.0.2-ea', { version: '11.0.2', stable: false }]
 | 
				
			||||||
  ])('normalizeVersion from %s to %s', (input, expected) => {
 | 
					  ])('normalizeVersion from %s to %s', (input, expected) => {
 | 
				
			||||||
    expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(expected);
 | 
					    expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(expected);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ import * as core from '@actions/core';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import path from 'path';
 | 
					import path from 'path';
 | 
				
			||||||
import * as semver from 'semver';
 | 
					import * as semver from 'semver';
 | 
				
			||||||
import * as utils from '../../src/util';
 | 
					import * as util from '../../src/util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { LocalDistribution } from '../../src/distributions/local/installer';
 | 
					import { LocalDistribution } from '../../src/distributions/local/installer';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ describe('setupJava', () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let mockJavaBase: LocalDistribution;
 | 
					  let mockJavaBase: LocalDistribution;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let spyTcFind: jest.SpyInstance;
 | 
					  let spyGetToolcachePath: jest.SpyInstance;
 | 
				
			||||||
  let spyTcCacheDir: jest.SpyInstance;
 | 
					  let spyTcCacheDir: jest.SpyInstance;
 | 
				
			||||||
  let spyTcFindAllVersions: jest.SpyInstance;
 | 
					  let spyTcFindAllVersions: jest.SpyInstance;
 | 
				
			||||||
  let spyCoreDebug: jest.SpyInstance;
 | 
					  let spyCoreDebug: jest.SpyInstance;
 | 
				
			||||||
| 
						 | 
					@ -30,16 +30,18 @@ describe('setupJava', () => {
 | 
				
			||||||
  let expectedJdkFile = 'JavaLocalJdkFile';
 | 
					  let expectedJdkFile = 'JavaLocalJdkFile';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  beforeEach(() => {
 | 
					  beforeEach(() => {
 | 
				
			||||||
    spyTcFind = jest.spyOn(tc, 'find');
 | 
					    spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
 | 
				
			||||||
    spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
 | 
					    spyGetToolcachePath.mockImplementation(
 | 
				
			||||||
      const semverVersion = new semver.Range(javaVersion);
 | 
					      (toolname: string, javaVersion: string, architecture: string) => {
 | 
				
			||||||
 | 
					        const semverVersion = new semver.Range(javaVersion);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
 | 
					        if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
 | 
				
			||||||
        return '';
 | 
					          return '';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
      return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    spyTcCacheDir = jest.spyOn(tc, 'cacheDir');
 | 
					    spyTcCacheDir = jest.spyOn(tc, 'cacheDir');
 | 
				
			||||||
    spyTcCacheDir.mockImplementation(
 | 
					    spyTcCacheDir.mockImplementation(
 | 
				
			||||||
| 
						 | 
					@ -76,7 +78,7 @@ describe('setupJava', () => {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Spy on util methods
 | 
					    // Spy on util methods
 | 
				
			||||||
    spyUtilsExtractJdkFile = jest.spyOn(utils, 'extractJdkFile');
 | 
					    spyUtilsExtractJdkFile = jest.spyOn(util, 'extractJdkFile');
 | 
				
			||||||
    spyUtilsExtractJdkFile.mockImplementation(() => 'some/random/path/');
 | 
					    spyUtilsExtractJdkFile.mockImplementation(() => 'some/random/path/');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Spy on path methods
 | 
					    // Spy on path methods
 | 
				
			||||||
| 
						 | 
					@ -100,7 +102,7 @@ describe('setupJava', () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mockJavaBase = new LocalDistribution(inputs, jdkFile);
 | 
					    mockJavaBase = new LocalDistribution(inputs, jdkFile);
 | 
				
			||||||
    await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
					    await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
				
			||||||
    expect(spyTcFind).toHaveBeenCalled();
 | 
					    expect(spyGetToolcachePath).toHaveBeenCalled();
 | 
				
			||||||
    expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
 | 
					    expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
 | 
				
			||||||
    expect(spyCoreInfo).not.toHaveBeenCalledWith(
 | 
					    expect(spyCoreInfo).not.toHaveBeenCalledWith(
 | 
				
			||||||
      `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
 | 
					      `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
 | 
				
			||||||
| 
						 | 
					@ -117,7 +119,7 @@ describe('setupJava', () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mockJavaBase = new LocalDistribution(inputs, jdkFile);
 | 
					    mockJavaBase = new LocalDistribution(inputs, jdkFile);
 | 
				
			||||||
    await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
					    await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
 | 
				
			||||||
    expect(spyTcFind).toHaveBeenCalled();
 | 
					    expect(spyGetToolcachePath).toHaveBeenCalled();
 | 
				
			||||||
    expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
 | 
					    expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
 | 
				
			||||||
    expect(spyCoreInfo).not.toHaveBeenCalledWith(
 | 
					    expect(spyCoreInfo).not.toHaveBeenCalledWith(
 | 
				
			||||||
      `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
 | 
					      `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +96,10 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
    ['15', '15.0.2+7'],
 | 
					    ['15', '15.0.2+7'],
 | 
				
			||||||
    ['9.0.0', '9.0.0+0'],
 | 
					    ['9.0.0', '9.0.0+0'],
 | 
				
			||||||
    ['9.0', '9.0.1+0'],
 | 
					    ['9.0', '9.0.1+0'],
 | 
				
			||||||
    ['8.0.262', '8.0.262+19'] // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18]
 | 
					    ['8.0.262', '8.0.262+19'], // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18]
 | 
				
			||||||
 | 
					    ['8.0.262+17', '8.0.262+17'],
 | 
				
			||||||
 | 
					    ['15.0.1+8', '15.0.1+8'],
 | 
				
			||||||
 | 
					    ['15.0.1+9', '15.0.1+9']
 | 
				
			||||||
  ])('version is %s -> %s', async (input, expected) => {
 | 
					  ])('version is %s -> %s', async (input, expected) => {
 | 
				
			||||||
    const distribution = new ZuluDistribution({
 | 
					    const distribution = new ZuluDistribution({
 | 
				
			||||||
      version: input,
 | 
					      version: input,
 | 
				
			||||||
| 
						 | 
					@ -111,7 +114,7 @@ describe('findPackageForDownload', () => {
 | 
				
			||||||
  it('select correct bundle if there are multiple items with the same jdk version but different zulu versions', async () => {
 | 
					  it('select correct bundle if there are multiple items with the same jdk version but different zulu versions', async () => {
 | 
				
			||||||
    const distribution = new ZuluDistribution({ version: '', arch: 'x86', packageType: 'jdk' });
 | 
					    const distribution = new ZuluDistribution({ version: '', arch: 'x86', packageType: 'jdk' });
 | 
				
			||||||
    distribution['getAvailableVersions'] = async () => manifestData;
 | 
					    distribution['getAvailableVersions'] = async () => manifestData;
 | 
				
			||||||
    const result = await distribution['findPackageForDownload'](new semver.Range('11.0.5'));
 | 
					    const result = await distribution['findPackageForDownload']('11.0.5');
 | 
				
			||||||
    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'
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										22
									
								
								__tests__/util.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								__tests__/util.test.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,22 @@
 | 
				
			||||||
 | 
					import { isVersionSatisfies } from '../src/util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe('isVersionSatisfies', () => {
 | 
				
			||||||
 | 
					  it.each([
 | 
				
			||||||
 | 
					    ['x', '11.0.0', true],
 | 
				
			||||||
 | 
					    ['3', '3.7.1', true],
 | 
				
			||||||
 | 
					    ['3', '3.7.2', true],
 | 
				
			||||||
 | 
					    ['3', '3.7.2+4', true],
 | 
				
			||||||
 | 
					    ['2.5', '2.5.0', true],
 | 
				
			||||||
 | 
					    ['2.5', '2.5.0+1', true],
 | 
				
			||||||
 | 
					    ['2.5', '2.6.1', false],
 | 
				
			||||||
 | 
					    ['2.5.1', '2.5.0', false],
 | 
				
			||||||
 | 
					    ['2.5.1+3', '2.5.0', false],
 | 
				
			||||||
 | 
					    ['2.5.1+3', '2.5.1+3', true],
 | 
				
			||||||
 | 
					    ['2.5.1+3', '2.5.1+2', false],
 | 
				
			||||||
 | 
					    ['15.0.0+14', '15.0.0+14.1.202003190635', false],
 | 
				
			||||||
 | 
					    ['15.0.0+14.1.202003190635', '15.0.0+14.1.202003190635', true]
 | 
				
			||||||
 | 
					  ])('%s, %s -> %s', (inputRange: string, inputVersion: string, expected: boolean) => {
 | 
				
			||||||
 | 
					    const actual = isVersionSatisfies(inputRange, inputVersion);
 | 
				
			||||||
 | 
					    expect(actual).toBe(expected);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					@ -10,12 +10,16 @@ if [ -z "$2" ]; then
 | 
				
			||||||
  exit 1
 | 
					  exit 1
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EXPECTED_JAVA_VERSION=${1/-ea/}
 | 
					EXPECTED_JAVA_VERSION=$1
 | 
				
			||||||
EXPECTED_PATH=$2
 | 
					EXPECTED_PATH=$2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXPECTED_JAVA_VERSION=$(echo $EXPECTED_JAVA_VERSION | cut -d'+' -f1)
 | 
				
			||||||
if [[ $EXPECTED_JAVA_VERSION == 8 ]] || [[ $EXPECTED_JAVA_VERSION == 8.* ]]; then
 | 
					if [[ $EXPECTED_JAVA_VERSION == 8 ]] || [[ $EXPECTED_JAVA_VERSION == 8.* ]]; then
 | 
				
			||||||
  EXPECTED_JAVA_VERSION="1.${EXPECTED_JAVA_VERSION}"
 | 
					  EXPECTED_JAVA_VERSION="1.${EXPECTED_JAVA_VERSION}"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					if [[ $EXPECTED_JAVA_VERSION == *-ea* ]]; then
 | 
				
			||||||
 | 
					  EXPECTED_JAVA_VERSION=$(echo $EXPECTED_JAVA_VERSION | cut -d'-' -f1 | cut -d'.' -f1)
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ACTUAL_JAVA_VERSION="$(java -version 2>&1)"
 | 
					ACTUAL_JAVA_VERSION="$(java -version 2>&1)"
 | 
				
			||||||
echo "Found java version: $ACTUAL_JAVA_VERSION"
 | 
					echo "Found java version: $ACTUAL_JAVA_VERSION"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue