diff --git a/.github/workflows/basic-validation.yml b/.github/workflows/basic-validation.yml index e93e5800..37fa323e 100644 --- a/.github/workflows/basic-validation.yml +++ b/.github/workflows/basic-validation.yml @@ -16,4 +16,4 @@ jobs: name: Basic validation uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main with: - node-version: '24.x' + node-version: '20.x' diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 90ef986a..509ea6cc 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -16,4 +16,4 @@ jobs: name: Check dist/ uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main with: - node-version: '24.x' + node-version: '20.x' diff --git a/.licenses/npm/@types/node.dep.yml b/.licenses/npm/@types/node.dep.yml index 06fb919d..86544f48 100644 --- a/.licenses/npm/@types/node.dep.yml +++ b/.licenses/npm/@types/node.dep.yml @@ -1,6 +1,6 @@ --- name: "@types/node" -version: 20.11.24 +version: 24.1.0 type: npm summary: TypeScript definitions for node homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node diff --git a/.licenses/npm/undici-types.dep.yml b/.licenses/npm/undici-types.dep.yml index a65b8aff..370219bf 100644 --- a/.licenses/npm/undici-types.dep.yml +++ b/.licenses/npm/undici-types.dep.yml @@ -1,15 +1,17 @@ --- name: undici-types -version: 5.26.5 +version: 7.8.0 type: npm summary: A stand-alone types package for Undici homepage: https://undici.nodejs.org license: mit licenses: -- sources: Auto-generated MIT license text +- sources: LICENSE text: | MIT License + Copyright (c) Matteo Collina and Undici contributors + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 110b5cc3..eedf9484 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -8,10 +8,6 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/adopt.json'; describe('getAvailableVersions', () => { @@ -195,7 +191,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const installerOptions: JavaInstallerOptions = { version: '17', diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index acf9f0c2..08a95828 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -14,10 +14,6 @@ import { import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - class EmptyJavaBase extends JavaBase { constructor(installerOptions: JavaInstallerOptions) { super('Empty', installerOptions); @@ -291,7 +287,7 @@ describe('setupJava', () => { spyCoreSetOutput = jest.spyOn(core, 'setOutput'); spyCoreSetOutput.mockImplementation(() => undefined); - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture('x86')); + jest.spyOn(os, 'arch').mockReturnValue('x86' as ReturnType); }); afterEach(() => { diff --git a/__tests__/distributors/corretto-installer.test.ts b/__tests__/distributors/corretto-installer.test.ts index 059020f5..38a96481 100644 --- a/__tests__/distributors/corretto-installer.test.ts +++ b/__tests__/distributors/corretto-installer.test.ts @@ -6,10 +6,6 @@ import * as util from '../../src/util'; import os from 'os'; import {isGeneratorFunction} from 'util/types'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/corretto.json'; describe('getAvailableVersions', () => { @@ -207,28 +203,24 @@ describe('getAvailableVersions', () => { }); it.each([ - ['arm64', 'aarch64'], - ['amd64', 'x64'] + ['amd64', 'x64'], + ['arm64', 'aarch64'] ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); - const version = '17'; - const installerOptions: JavaInstallerOptions = { - version, + const distribution = new CorrettoDistribution({ + version: '17', architecture: '', // to get default value packageType: 'jdk', checkLatest: false - }; - - const distribution = new CorrettoDistribution(installerOptions); - mockPlatform(distribution, 'macos'); + }); const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`; const availableVersion = await distribution['findPackageForDownload']( - version + '17' ); expect(availableVersion).not.toBeNull(); expect(availableVersion.url).toBe(expectedLink); diff --git a/__tests__/distributors/graalvm-installer.test.ts b/__tests__/distributors/graalvm-installer.test.ts index 8c2ab52b..3c07d3f2 100644 --- a/__tests__/distributors/graalvm-installer.test.ts +++ b/__tests__/distributors/graalvm-installer.test.ts @@ -1,9 +1,5 @@ import {GraalVMDistribution} from '../../src/distributions/graalvm/installer'; import os from 'os'; - -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} import * as core from '@actions/core'; import {getDownloadArchiveExtension} from '../../src/util'; import {HttpClient} from '@actions/http-client'; @@ -102,31 +98,32 @@ describe('findPackageForDownload', () => { }); it.each([ - ['amd64', 'x64'], - ['arm64', 'aarch64'] + ['amd64', ['x64', 'amd64']], + ['arm64', ['aarch64', 'arm64']] ])( 'defaults to os.arch(): %s mapped to distro arch: %s', - async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); - jest.spyOn(os, 'platform').mockReturnValue('linux'); + async (osArch: string, distroArchs: string[]) => { + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); - const version = '21'; - const distro = new GraalVMDistribution({ - version, + const distribution = new GraalVMDistribution({ + version: '21', architecture: '', // to get default value packageType: 'jdk', checkLatest: false }); const osType = distribution.getPlatform(); - if (osType === 'windows' && distroArch == 'aarch64') { + if (osType === 'windows' && distroArchs.includes('aarch64')) { return; // skip, aarch64 is not available for Windows } const archiveType = getDownloadArchiveExtension(); - const result = await distro['findPackageForDownload'](version); - const expectedUrl = `https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_${osType}-${distroArch}_bin.${archiveType}`; + const result = await distribution['findPackageForDownload']('21'); - expect(result.url).toBe(expectedUrl); + const expectedUrls = distroArchs.map(distroArch => + `https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_${osType}-${distroArch}_bin.${archiveType}` + ); + + expect(expectedUrls).toContain(result.url); } ); diff --git a/__tests__/distributors/liberica-installer.test.ts b/__tests__/distributors/liberica-installer.test.ts index dada9223..25f6db05 100644 --- a/__tests__/distributors/liberica-installer.test.ts +++ b/__tests__/distributors/liberica-installer.test.ts @@ -6,10 +6,6 @@ import { import {HttpClient} from '@actions/http-client'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/liberica.json'; describe('getAvailableVersions', () => { @@ -109,9 +105,9 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: DistroArch) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); - const distribution = new LibericaDistributions({ + const distributions = new LibericaDistributions({ version: '17', architecture: '', // to get default value packageType: 'jdk', @@ -121,11 +117,11 @@ describe('getAvailableVersions', () => { const additionalParams = '&installation-type=archive&fields=downloadUrl%2Cversion%2CfeatureVersion%2CinterimVersion%2C' + 'updateVersion%2CbuildVersion'; - distribution['getPlatformOption'] = () => 'macos'; + distributions['getPlatformOption'] = () => 'macos'; const buildUrl = `https://api.bell-sw.com/v1/liberica/releases?os=macos&bundle-type=jdk&bitness=${distroArch.bitness}&arch=${distroArch.arch}&build-type=all${additionalParams}`; - await distribution['getAvailableVersions'](); + await distributions['getAvailableVersions'](); expect(spyHttpClient.mock.calls).toHaveLength(1); expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl); diff --git a/__tests__/distributors/liberica-linux-installer.test.ts b/__tests__/distributors/liberica-linux-installer.test.ts index a5511a12..6971f763 100644 --- a/__tests__/distributors/liberica-linux-installer.test.ts +++ b/__tests__/distributors/liberica-linux-installer.test.ts @@ -6,10 +6,6 @@ import { import {HttpClient} from '@actions/http-client'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/liberica-linux.json'; describe('getAvailableVersions', () => { @@ -109,7 +105,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: DistroArch) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const distribution = new LibericaDistributions({ version: '17', diff --git a/__tests__/distributors/liberica-windows-installer.test.ts b/__tests__/distributors/liberica-windows-installer.test.ts index 1cbf18d2..38822a7f 100644 --- a/__tests__/distributors/liberica-windows-installer.test.ts +++ b/__tests__/distributors/liberica-windows-installer.test.ts @@ -6,10 +6,6 @@ import { import {HttpClient} from '@actions/http-client'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/liberica-windows.json'; describe('getAvailableVersions', () => { @@ -109,7 +105,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: DistroArch) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const distribution = new LibericaDistributions({ version: '17', diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index ee526ff2..0c9f6022 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -1,9 +1,5 @@ import {MicrosoftDistributions} from '../../src/distributions/microsoft/installer'; import os from 'os'; - -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} import data from '../data/microsoft.json'; import * as httpm from '@actions/http-client'; import * as core from '@actions/core'; @@ -99,7 +95,7 @@ describe('findPackageForDownload', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); jest.spyOn(os, 'platform').mockReturnValue('darwin'); const version = '17'; @@ -123,7 +119,7 @@ describe('findPackageForDownload', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); jest.spyOn(os, 'platform').mockReturnValue('linux'); const version = '17'; @@ -147,7 +143,7 @@ describe('findPackageForDownload', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); jest.spyOn(os, 'platform').mockReturnValue('win32'); const version = '17'; diff --git a/__tests__/distributors/oracle-installer.test.ts b/__tests__/distributors/oracle-installer.test.ts index edb90b32..7211d8e6 100644 --- a/__tests__/distributors/oracle-installer.test.ts +++ b/__tests__/distributors/oracle-installer.test.ts @@ -1,9 +1,5 @@ import {OracleDistribution} from '../../src/distributions/oracle/installer'; import os from 'os'; - -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} import * as core from '@actions/core'; import {getDownloadArchiveExtension} from '../../src/util'; import {HttpClient} from '@actions/http-client'; @@ -99,7 +95,7 @@ describe('findPackageForDownload', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); jest.spyOn(os, 'platform').mockReturnValue('linux'); const version = '18'; diff --git a/__tests__/distributors/temurin-installer.test.ts b/__tests__/distributors/temurin-installer.test.ts index 0bdedaad..7aa19dca 100644 --- a/__tests__/distributors/temurin-installer.test.ts +++ b/__tests__/distributors/temurin-installer.test.ts @@ -1,9 +1,5 @@ import {HttpClient} from '@actions/http-client'; import os from 'os'; - -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} import { TemurinDistribution, TemurinImplementation @@ -151,7 +147,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: string) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(distroArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const installerOptions: JavaInstallerOptions = { version: '17', diff --git a/__tests__/distributors/zulu-installer.test.ts b/__tests__/distributors/zulu-installer.test.ts index 1b0fe449..99b9756e 100644 --- a/__tests__/distributors/zulu-installer.test.ts +++ b/__tests__/distributors/zulu-installer.test.ts @@ -1,14 +1,9 @@ import {HttpClient} from '@actions/http-client'; -import * as semver from 'semver'; import {ZuluDistribution} from '../../src/distributions/zulu/installer'; import {IZuluVersions} from '../../src/distributions/zulu/models'; import * as utils from '../../src/util'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/zulu-releases-default.json'; describe('getAvailableVersions', () => { @@ -130,7 +125,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: DistroArch) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const distribution = new ZuluDistribution({ version: '17', diff --git a/__tests__/distributors/zulu-linux-installer.test.ts b/__tests__/distributors/zulu-linux-installer.test.ts index 946dbdda..9897e080 100644 --- a/__tests__/distributors/zulu-linux-installer.test.ts +++ b/__tests__/distributors/zulu-linux-installer.test.ts @@ -5,10 +5,6 @@ import {IZuluVersions} from '../../src/distributions/zulu/models'; import * as utils from '../../src/util'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/zulu-linux.json'; describe('getAvailableVersions', () => { @@ -130,7 +126,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: DistroArch) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const distribution = new ZuluDistribution({ version: '17', @@ -139,7 +135,9 @@ describe('getAvailableVersions', () => { checkLatest: false }); distribution['getPlatformOption'] = () => 'linux'; - const buildUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?os=linux&ext=zip&bundle_type=jdk&javafx=false&arch=${distroArch.arch}&hw_bitness=${distroArch.bitness}&release_status=ga`; + // Override extension for linux default arch case to match util behavior + spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz'); + const buildUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?os=linux&ext=tar.gz&bundle_type=jdk&javafx=false&arch=${distroArch.arch}&hw_bitness=${distroArch.bitness}&release_status=ga`; await distribution['getAvailableVersions'](); diff --git a/__tests__/distributors/zulu-windows-installer.test.ts b/__tests__/distributors/zulu-windows-installer.test.ts index b8e802eb..e22f1488 100644 --- a/__tests__/distributors/zulu-windows-installer.test.ts +++ b/__tests__/distributors/zulu-windows-installer.test.ts @@ -5,10 +5,6 @@ import {IZuluVersions} from '../../src/distributions/zulu/models'; import * as utils from '../../src/util'; import os from 'os'; -function mockArchitecture(arch: string): NodeJS.Architecture { - return arch as NodeJS.Architecture; -} - import manifestData from '../data/zulu-windows.json'; describe('getAvailableVersions', () => { @@ -130,7 +126,7 @@ describe('getAvailableVersions', () => { ])( 'defaults to os.arch(): %s mapped to distro arch: %s', async (osArch: string, distroArch: DistroArch) => { - jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch)); + jest.spyOn(os, 'arch').mockReturnValue(osArch as ReturnType); const distribution = new ZuluDistribution({ version: '17', diff --git a/__tests__/toolchains.test.ts b/__tests__/toolchains.test.ts index 6d4bea26..483077dc 100644 --- a/__tests__/toolchains.test.ts +++ b/__tests__/toolchains.test.ts @@ -6,8 +6,7 @@ import * as io from '@actions/io'; import * as toolchains from '../src/toolchains'; import {M2_DIR, MVN_TOOLCHAINS_FILE} from '../src/constants'; -const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-java-test-')); -const m2Dir = path.join(tempDir, M2_DIR); +const m2Dir = path.join(__dirname, M2_DIR); const toolchainsFile = path.join(m2Dir, MVN_TOOLCHAINS_FILE); describe('toolchains tests', () => { @@ -17,7 +16,7 @@ describe('toolchains tests', () => { beforeEach(async () => { await io.rmRF(m2Dir); spyOSHomedir = jest.spyOn(os, 'homedir'); - spyOSHomedir.mockReturnValue(tempDir); + spyOSHomedir.mockReturnValue(__dirname); spyInfo = jest.spyOn(core, 'info'); spyInfo.mockImplementation(() => null); }, 300000); @@ -25,7 +24,6 @@ describe('toolchains tests', () => { afterAll(async () => { try { await io.rmRF(m2Dir); - await io.rmRF(tempDir); } catch { console.log('Failed to remove test directories'); } @@ -42,7 +40,7 @@ describe('toolchains tests', () => { jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64' }; - const altHome = path.join(tempDir, 'runner', 'toolchains'); + const altHome = path.join(__dirname, 'runner', 'toolchains'); const altToolchainsFile = path.join(altHome, MVN_TOOLCHAINS_FILE); await io.rmRF(altHome); // ensure it doesn't already exist