mirror of
https://github.com/actions/setup-java.git
synced 2025-03-13 09:37:03 +00:00
Fix archive suffix for Windows.
This commit is contained in:
parent
2828873ff8
commit
f073089abe
4 changed files with 6679 additions and 74 deletions
|
@ -1,34 +1,4 @@
|
|||
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
|
||||
import { ArchitectureOptions } from '../../src/distributions/microsoft/models';
|
||||
|
||||
describe('getArchitectureOptions', () => {
|
||||
it.each([
|
||||
['x64', { bitness: '64', arch: 'x86' }],
|
||||
['aarch64', { bitness: '64', arch: 'arm' }]
|
||||
] as [string, ArchitectureOptions][])('parse architecture %s -> %s', (input, expected) => {
|
||||
const distributions = new MicrosoftDistributions({
|
||||
architecture: input,
|
||||
checkLatest: false,
|
||||
packageType: '',
|
||||
version: ''
|
||||
});
|
||||
|
||||
expect(distributions['getArchitectureOptions']()).toEqual(expected);
|
||||
});
|
||||
|
||||
it.each(['armv6', 's390x'])('not support architecture %s', input => {
|
||||
const distributions = new MicrosoftDistributions({
|
||||
architecture: input,
|
||||
checkLatest: false,
|
||||
packageType: '',
|
||||
version: ''
|
||||
});
|
||||
|
||||
expect(() => distributions['getArchitectureOptions']()).toThrow(
|
||||
/Architecture '\w+' is not supported\. Supported architectures: .*/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
let distribution: MicrosoftDistributions;
|
||||
|
@ -46,34 +16,39 @@ describe('findPackageForDownload', () => {
|
|||
[
|
||||
'17.x',
|
||||
'17.0.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.tar.gz'
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'16.0.x',
|
||||
'16.0.2',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.tar.gz'
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'11.0.13',
|
||||
'11.0.13',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.tar.gz'
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
]
|
||||
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
||||
const result = await distribution['findPackageForDownload'](input);
|
||||
expect(result.version).toBe(expectedVersion);
|
||||
var os: string;
|
||||
var archive: string;
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
os = 'macos';
|
||||
archive = 'tar.gz';
|
||||
break;
|
||||
case 'win32':
|
||||
os = 'windows';
|
||||
archive = 'zip';
|
||||
break;
|
||||
default:
|
||||
os = process.platform.toString();
|
||||
archive = 'tar.gz';
|
||||
break;
|
||||
}
|
||||
expect(result.url).toBe(expectedUrl.replace('{{OS_TYPE}}', os));
|
||||
const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive);
|
||||
expect(result.url).toBe(url);
|
||||
});
|
||||
|
||||
it('should throw an error', async () => {
|
||||
|
@ -92,13 +67,14 @@ describe('getPlatformOption', () => {
|
|||
});
|
||||
|
||||
it.each([
|
||||
['linux', 'linux'],
|
||||
['darwin', 'macos'],
|
||||
['win32', 'windows']
|
||||
])('os version %s -> %s', (input, expected) => {
|
||||
['linux', 'tar.gz', 'linux'],
|
||||
['darwin', 'tar.gz', 'macos'],
|
||||
['win32', 'zip', 'windows']
|
||||
])('os version %s -> %s', (input, expectedArchive, expectedOs) => {
|
||||
const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
expect(actual.archive).toEqual(expectedArchive);
|
||||
expect(actual.os).toEqual(expectedOs);
|
||||
});
|
||||
|
||||
it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
|
||||
|
|
6644
package-lock.json
generated
6644
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@ import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from
|
|||
import semver from 'semver';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import * as core from '@actions/core';
|
||||
import { ArchitectureOptions, MicrosoftVersion, OsVersions } from './models';
|
||||
import { MicrosoftVersion, PlatformOptions } from './models';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
@ -41,12 +41,14 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
if (this.architecture !== 'x64' && this.architecture != 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
|
||||
const opts = this.getPlatformOption();
|
||||
const availableVersions = availableVersionsRaw.map(item => ({
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${
|
||||
item.fullVersion
|
||||
}-${this.getPlatformOption()}-${this.architecture}.tar.gz`,
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion}-${opts.os}-${this.architecture}.${opts.archive}`,
|
||||
version: this.convertVersionToSemver(item)
|
||||
}));
|
||||
|
||||
|
@ -83,39 +85,30 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
minorVersion: 0,
|
||||
patchVersion: 2,
|
||||
fullVersion: '16.0.2.7.1'
|
||||
},
|
||||
{
|
||||
}
|
||||
];
|
||||
|
||||
// M1 is only supported for Java 16 & 17
|
||||
if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
|
||||
jdkVersions.push({
|
||||
majorVersion: 11,
|
||||
minorVersion: 0,
|
||||
patchVersion: 13,
|
||||
fullVersion: '11.0.13.8.1'
|
||||
}
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
return jdkVersions;
|
||||
}
|
||||
|
||||
private getArchitectureOptions(): ArchitectureOptions {
|
||||
switch (this.architecture) {
|
||||
case 'x64':
|
||||
return { bitness: '64', arch: 'x86' };
|
||||
case 'aarch64':
|
||||
return { bitness: '64', arch: 'arm' };
|
||||
default:
|
||||
throw new Error(
|
||||
`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private getPlatformOption(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||
private getPlatformOption(platform: NodeJS.Platform = process.platform): PlatformOptions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
return { archive: 'tar.gz', os: 'macos' };
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
return { archive: 'zip', os: 'windows' };
|
||||
case 'linux':
|
||||
return 'linux';
|
||||
return { archive: 'tar.gz', os: 'linux' };
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
export type Bitness = '32' | '64';
|
||||
export type ArchType = 'arm' | 'ppc' | 'sparc' | 'x86';
|
||||
export type OsVersions = 'linux' | 'macos' | 'windows';
|
||||
export type ArchiveType = 'tar.gz' | 'zip';
|
||||
|
||||
export type OsVersions = 'linux' | 'linux-musl' | 'macos' | 'solaris' | 'windows';
|
||||
|
||||
export interface ArchitectureOptions {
|
||||
bitness: Bitness;
|
||||
arch: ArchType;
|
||||
export interface PlatformOptions {
|
||||
archive: ArchiveType;
|
||||
os: OsVersions;
|
||||
}
|
||||
|
||||
export interface MicrosoftVersion {
|
||||
|
|
Loading…
Add table
Reference in a new issue