Skip to content

Commit

Permalink
Fix archive suffix for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed Nov 22, 2021
1 parent dbf2bc7 commit aa7837f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 89 deletions.
54 changes: 15 additions & 39 deletions __tests__/distributors/microsoft-installer.test.ts
@@ -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;
Expand All @@ -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 () => {
Expand All @@ -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'])(
Expand Down
33 changes: 15 additions & 18 deletions dist/setup/index.js
Expand Up @@ -14281,9 +14281,13 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
}
findPackageForDownload(range) {
return __awaiter(this, void 0, void 0, function* () {
if (this.architecture !== 'x64' && this.architecture != 'aarch64') {
throw new Error(`Unsupported architecture: ${this.architecture}`);
}
const availableVersionsRaw = yield 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)
}));
const satisfiedVersion = availableVersions
Expand Down Expand Up @@ -14315,35 +14319,28 @@ class MicrosoftDistributions extends base_installer_1.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;
});
}
getArchitectureOptions() {
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}`);
}
}
getPlatformOption(platform = process.platform) {
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}`);
}
Expand Down
43 changes: 18 additions & 25 deletions src/distributions/microsoft/installer.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
}));

Expand Down Expand Up @@ -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}`
Expand Down
12 changes: 5 additions & 7 deletions src/distributions/microsoft/models.ts
@@ -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 {
Expand Down

0 comments on commit aa7837f

Please sign in to comment.