mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 18:06:45 +00:00
Add microsoft distribution of the JDK.
This commit is contained in:
parent
5f00602cd1
commit
1bc25281d6
8 changed files with 26593 additions and 23332 deletions
16
.github/workflows/e2e-versions.yml
vendored
16
.github/workflows/e2e-versions.yml
vendored
|
@ -14,13 +14,14 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
setup-java-major-versions:
|
setup-java-major-versions:
|
||||||
|
if: ${{ matrix.distribution != 'microsoft' || matrix.version != '8' }}
|
||||||
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
||||||
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: ['temurin', 'adopt', 'adopt-openj9', 'zulu', 'liberica'] # internally 'adopt-hotspot' is the same as 'adopt'
|
distribution: ['temurin', 'adopt', 'adopt-openj9', 'zulu', 'liberica', 'microsoft' ] # internally 'adopt-hotspot' is the same as 'adopt'
|
||||||
version: ['8', '11', '16']
|
version: ['8', '11', '16']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
@ -175,16 +176,25 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-java-custom-architecture:
|
setup-java-custom-architecture:
|
||||||
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x86) - ${{ matrix.os }}
|
# Only Zulu provides x86 arch for now and only for windows / ubuntu
|
||||||
|
# Only Microsoft provides arm64 for windows / ubuntu / os x
|
||||||
|
if: ${{ (matrix.distribution == 'zulu' && matrix.architecture == 'x86' && matrix.os != 'macos-latest' ) || (matrix.distribution == 'microsoft' && matrix.architecture == 'arm64') }}
|
||||||
|
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-${{ matrix.architecture }}) - ${{ 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:
|
||||||
|
<<<<<<< HEAD
|
||||||
# Only Zulu and Liberica provides x86 arch for now and only for windows / ubuntu
|
# Only Zulu and Liberica provides x86 arch for now and only for windows / ubuntu
|
||||||
os: [windows-latest, ubuntu-latest]
|
os: [windows-latest, ubuntu-latest]
|
||||||
distribution: ['zulu', 'liberica']
|
distribution: ['zulu', 'liberica']
|
||||||
|
=======
|
||||||
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
|
distribution: ['zulu', 'microsoft']
|
||||||
|
>>>>>>> Add microsoft distribution of the JDK.
|
||||||
version: ['11']
|
version: ['11']
|
||||||
|
architecture: [ 'x86', 'arm64' ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -194,7 +204,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
java-version: ${{ matrix.version }}
|
java-version: ${{ matrix.version }}
|
||||||
architecture: x86
|
architecture: ${{ matrix.architecture }}
|
||||||
- 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
|
||||||
|
|
|
@ -59,6 +59,7 @@ Currently, the following distributions are supported:
|
||||||
| `adopt` or `adopt-hotspot` | Adopt OpenJDK Hotspot | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
| `adopt` or `adopt-hotspot` | Adopt OpenJDK Hotspot | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
||||||
| `adopt-openj9` | Adopt OpenJDK OpenJ9 | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
| `adopt-openj9` | Adopt OpenJDK OpenJ9 | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
|
||||||
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
|
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
|
||||||
|
| `microsoft` | Microsoft OpenJDK | [Link](https://www.microsoft.com/openjdk) | [Link](https://docs.microsoft.com/java/openjdk/faq)
|
||||||
|
|
||||||
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
|
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
|
||||||
|
|
||||||
|
|
100
__tests__/distributors/microsoft-installer.test.ts
Normal file
100
__tests__/distributors/microsoft-installer.test.ts
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
distribution = new MicrosoftDistributions({
|
||||||
|
version: '',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['17.x', '17.0.1', 'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.tar.gz'],
|
||||||
|
['16.0.x', '16.0.2', 'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.tar.gz'],
|
||||||
|
['11.0.13', '11.0.13', 'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.tar.gz'],
|
||||||
|
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
||||||
|
const result = await distribution['findPackageForDownload'](input);
|
||||||
|
expect(result.version).toBe(expectedVersion);
|
||||||
|
var os: string;
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'darwin':
|
||||||
|
os = 'macos';
|
||||||
|
break;
|
||||||
|
case 'win32':
|
||||||
|
os = 'windows';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
os = process.platform.toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
expect(result.url).toBe(expectedUrl.replace('{{OS_TYPE}}', os));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error', async () => {
|
||||||
|
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||||
|
/Could not find satisfied version for semver */
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getPlatformOption', () => {
|
||||||
|
const distributions = new MicrosoftDistributions({
|
||||||
|
architecture: 'x64',
|
||||||
|
version: '11',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['linux', 'linux'],
|
||||||
|
['darwin', 'macos'],
|
||||||
|
['win32', 'windows'],
|
||||||
|
])('os version %s -> %s', (input, expected) => {
|
||||||
|
const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
|
||||||
|
'not support os version %s',
|
||||||
|
input => {
|
||||||
|
expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow(
|
||||||
|
/Platform '\w+' is not supported\. Supported platforms: .+/
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
20061
dist/cleanup/index.js
vendored
20061
dist/cleanup/index.js
vendored
File diff suppressed because one or more lines are too long
20491
dist/setup/index.js
vendored
20491
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -5,6 +5,7 @@ import { ZuluDistribution } from './zulu/installer';
|
||||||
import { AdoptDistribution, AdoptImplementation } from './adopt/installer';
|
import { AdoptDistribution, AdoptImplementation } from './adopt/installer';
|
||||||
import { TemurinDistribution, TemurinImplementation } from './temurin/installer';
|
import { TemurinDistribution, TemurinImplementation } from './temurin/installer';
|
||||||
import { LibericaDistributions } from './liberica/installer';
|
import { LibericaDistributions } from './liberica/installer';
|
||||||
|
import { MicrosoftDistributions } from './microsoft/installer';
|
||||||
|
|
||||||
enum JavaDistribution {
|
enum JavaDistribution {
|
||||||
Adopt = 'adopt',
|
Adopt = 'adopt',
|
||||||
|
@ -13,7 +14,8 @@ enum JavaDistribution {
|
||||||
Temurin = 'temurin',
|
Temurin = 'temurin',
|
||||||
Zulu = 'zulu',
|
Zulu = 'zulu',
|
||||||
Liberica = 'liberica',
|
Liberica = 'liberica',
|
||||||
JdkFile = 'jdkfile'
|
JdkFile = 'jdkfile',
|
||||||
|
Microsoft = 'microsoft'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getJavaDistribution(
|
export function getJavaDistribution(
|
||||||
|
@ -35,6 +37,8 @@ export function getJavaDistribution(
|
||||||
return new ZuluDistribution(installerOptions);
|
return new ZuluDistribution(installerOptions);
|
||||||
case JavaDistribution.Liberica:
|
case JavaDistribution.Liberica:
|
||||||
return new LibericaDistributions(installerOptions);
|
return new LibericaDistributions(installerOptions);
|
||||||
|
case JavaDistribution.Microsoft:
|
||||||
|
return new MicrosoftDistributions(installerOptions);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
123
src/distributions/microsoft/installer.ts
Normal file
123
src/distributions/microsoft/installer.ts
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
import { JavaBase } from '../base-installer';
|
||||||
|
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||||
|
import semver from 'semver';
|
||||||
|
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
import { ArchitectureOptions, MicrosoftVersion, OsVersions } from './models';
|
||||||
|
import * as tc from '@actions/tool-cache';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const supportedPlatform = `'linux', 'macos', 'windows'`;
|
||||||
|
|
||||||
|
const supportedArchitecture = `'x64', 'armv7', 'aarch64'`;
|
||||||
|
|
||||||
|
export class MicrosoftDistributions extends JavaBase {
|
||||||
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
|
super('Microsoft', installerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||||
|
core.info(
|
||||||
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
|
);
|
||||||
|
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
|
core.info(`Extracting Java archive...`);
|
||||||
|
const extension = getDownloadArchiveExtension();
|
||||||
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||||
|
|
||||||
|
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||||
|
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||||
|
|
||||||
|
const javaPath = await tc.cacheDir(
|
||||||
|
archivePath,
|
||||||
|
this.toolcacheFolderName,
|
||||||
|
this.getToolcacheVersionName(javaRelease.version),
|
||||||
|
this.architecture
|
||||||
|
);
|
||||||
|
|
||||||
|
return { version: javaRelease.version, path: javaPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||||
|
const availableVersionsRaw = await this.getAvailableVersions();
|
||||||
|
|
||||||
|
const availableVersions = availableVersionsRaw.map(item => ({
|
||||||
|
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion}-${this.getPlatformOption()}-${this.architecture}.tar.gz`,
|
||||||
|
version: this.convertVersionToSemver(item)
|
||||||
|
}));
|
||||||
|
|
||||||
|
const satisfiedVersion = availableVersions
|
||||||
|
.filter(item => isVersionSatisfies(range, item.version))
|
||||||
|
.sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
|
||||||
|
|
||||||
|
if (!satisfiedVersion) {
|
||||||
|
const availableOptions = availableVersions.map(item => item.version).join(', ');
|
||||||
|
const availableOptionsMessage = availableOptions
|
||||||
|
? `\nAvailable versions: ${availableOptions}`
|
||||||
|
: '';
|
||||||
|
throw new Error(
|
||||||
|
`Could not find satisfied version for semver ${range}. ${availableOptionsMessage}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return satisfiedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getAvailableVersions(): Promise<MicrosoftVersion[]> {
|
||||||
|
console.time('microsoft-retrieve-available-versions');
|
||||||
|
|
||||||
|
// TODO get these dynamically!
|
||||||
|
var jdkVersions = [{
|
||||||
|
majorVersion: 17,
|
||||||
|
minorVersion: 0,
|
||||||
|
patchVersion: 1,
|
||||||
|
fullVersion: '17.0.1.12.1'
|
||||||
|
}, {
|
||||||
|
majorVersion: 16,
|
||||||
|
minorVersion: 0,
|
||||||
|
patchVersion: 2,
|
||||||
|
fullVersion: '16.0.2.7.1'
|
||||||
|
}, {
|
||||||
|
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 {
|
||||||
|
switch (platform) {
|
||||||
|
case 'darwin':
|
||||||
|
return 'macos';
|
||||||
|
case 'win32':
|
||||||
|
return 'windows';
|
||||||
|
case 'linux':
|
||||||
|
return 'linux';
|
||||||
|
default:
|
||||||
|
throw new Error(
|
||||||
|
`Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private convertVersionToSemver(version: MicrosoftVersion): string {
|
||||||
|
return `${version.majorVersion}.${version.minorVersion}.${version.patchVersion}`;
|
||||||
|
}
|
||||||
|
}
|
17
src/distributions/microsoft/models.ts
Normal file
17
src/distributions/microsoft/models.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
export type Bitness = '32' | '64';
|
||||||
|
export type ArchType = 'arm' | 'ppc' | 'sparc' | 'x86';
|
||||||
|
|
||||||
|
export type OsVersions = 'linux' | 'linux-musl' | 'macos' | 'solaris' | 'windows';
|
||||||
|
|
||||||
|
export interface ArchitectureOptions {
|
||||||
|
bitness: Bitness;
|
||||||
|
arch: ArchType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MicrosoftVersion {
|
||||||
|
downloadUrl?: string;
|
||||||
|
majorVersion: number;
|
||||||
|
minorVersion: number;
|
||||||
|
patchVersion: number;
|
||||||
|
fullVersion: string;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue