Skip to content

Commit 2dfa201

Browse files
basic validation failure fix (actions#682)
1 parent 7467385 commit 2dfa201

File tree

5 files changed

+105
-67
lines changed

5 files changed

+105
-67
lines changed

__tests__/distributors/sapmachine-installer.test.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { HttpClient } from '@actions/http-client';
2-
import { SapMachineDistribution } from '../../src/distributions/sapmachine/installer';
1+
import {HttpClient} from '@actions/http-client';
2+
import {SapMachineDistribution} from '../../src/distributions/sapmachine/installer';
33
import * as utils from '../../src/util';
44

55
import manifestData from '../data/sapmachine.json';
@@ -43,13 +43,13 @@ describe('getAvailableVersions', () => {
4343
spyHttpClient.mockReturnValueOnce({
4444
statusCode: 404,
4545
headers: {},
46-
result: ""
47-
})
46+
result: ''
47+
});
4848
spyHttpClient.mockReturnValueOnce({
4949
statusCode: 200,
5050
headers: {},
5151
result: manifestData
52-
})
52+
});
5353

5454
const version = '17';
5555
const distribution = new SapMachineDistribution({
@@ -65,8 +65,10 @@ describe('getAvailableVersions', () => {
6565
version
6666
);
6767
expect(availableVersion).not.toBeNull();
68-
expect(availableVersion.url).toBe('https://github.com/SAP/SapMachine/releases/download/sapmachine-17.0.10/sapmachine-jdk-17.0.10_linux-x64_bin.tar.gz');
69-
})
68+
expect(availableVersion.url).toBe(
69+
'https://github.com/SAP/SapMachine/releases/download/sapmachine-17.0.10/sapmachine-jdk-17.0.10_linux-x64_bin.tar.gz'
70+
);
71+
});
7072
});
7173

7274
describe('getAvailableVersions', () => {
@@ -77,7 +79,7 @@ describe('getAvailableVersions', () => {
7779
['16.0.1', 'x64', 'linux', 71],
7880
['23-ea', 'x64', 'linux', 798],
7981
['23-ea', 'aarch64', 'windows', 0],
80-
['23-ea', 'x64', 'windows', 750],
82+
['23-ea', 'x64', 'windows', 750]
8183
])(
8284
'should get right number of available versions from JSON',
8385
async (
@@ -209,7 +211,7 @@ describe('getAvailableVersions', () => {
209211
'x64',
210212
'jdk',
211213
'https://github.com/SAP/SapMachine/releases/download/sapmachine-17.0.10/sapmachine-jdk-17.0.10_linux-x64-musl_bin.tar.gz'
212-
],
214+
]
213215
])(
214216
'should return proper link according to the specified java-version, platform and arch',
215217
async (
@@ -224,8 +226,7 @@ describe('getAvailableVersions', () => {
224226
version: version,
225227
architecture: arch,
226228
packageType: packageType,
227-
checkLatest: false,
228-
229+
checkLatest: false
229230
});
230231
mockPlatform(distribution, platform);
231232

@@ -247,15 +248,20 @@ describe('getAvailableVersions', () => {
247248
['8-ea', 'linux', 'x64', '8'],
248249
['21.0.3+7', 'linux', 'x64', '21.0.3+7'],
249250
['21.0.3+8-ea', 'linux', 'x64', '21.0.3+8'],
250-
['17', 'linux-muse', 'aarch64'],
251+
['17', 'linux-muse', 'aarch64']
251252
])(
252253
'should throw when required version of JDK can not be found in the JSON',
253-
async (version: string, platform: string, arch: string, normalizedVersion: string = version) => {
254+
async (
255+
version: string,
256+
platform: string,
257+
arch: string,
258+
normalizedVersion: string = version
259+
) => {
254260
const distribution = new SapMachineDistribution({
255261
version: version,
256262
architecture: arch,
257263
packageType: 'jdk',
258-
checkLatest: false,
264+
checkLatest: false
259265
});
260266
mockPlatform(distribution, platform);
261267

@@ -280,7 +286,9 @@ describe('getAvailableVersions', () => {
280286
mockPlatform(distribution, platform);
281287
await expect(
282288
distribution['findPackageForDownload'](jdkVersion)
283-
).rejects.toThrow('SapMachine provides only the `jdk` and `jre` package type');
289+
).rejects.toThrow(
290+
'SapMachine provides only the `jdk` and `jre` package type'
291+
);
284292
});
285293
});
286294
});

dist/setup/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125012,7 +125012,7 @@ class SapMachineDistribution extends base_installer_1.JavaBase {
125012125012
continue;
125013125013
}
125014125014
// skip earlyAccessVersions if stable version requested
125015-
if (this.stable && buildVersionMap.ea === "true") {
125015+
if (this.stable && buildVersionMap.ea === 'true') {
125016125016
continue;
125017125017
}
125018125018
for (const [edition, editionAssets] of Object.entries(buildVersionMap.assets)) {
@@ -125038,7 +125038,7 @@ class SapMachineDistribution extends base_installer_1.JavaBase {
125038125038
version: buildVersionWithoutPrefix,
125039125039
checksum: contentTypeAssets.checksum,
125040125040
downloadLink: contentTypeAssets.url,
125041-
packageType: edition,
125041+
packageType: edition
125042125042
});
125043125043
}
125044125044
}

src/distributions/distribution-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum JavaDistribution {
2525
Corretto = 'corretto',
2626
Oracle = 'oracle',
2727
Dragonwell = 'dragonwell',
28-
SapMachine = 'sapmachine',
28+
SapMachine = 'sapmachine'
2929
}
3030

3131
export function getJavaDistribution(

src/distributions/sapmachine/installer.ts

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as core from '@actions/core';
22
import * as tc from '@actions/tool-cache';
33
import semver from 'semver';
44
import fs from 'fs';
5-
import { OutgoingHttpHeaders } from 'http';
5+
import {OutgoingHttpHeaders} from 'http';
66
import path from 'path';
77
import {
88
convertVersionToSemver,
@@ -11,13 +11,13 @@ import {
1111
getGitHubHttpHeaders,
1212
isVersionSatisfies
1313
} from '../../util';
14-
import { JavaBase } from '../base-installer';
14+
import {JavaBase} from '../base-installer';
1515
import {
1616
JavaDownloadRelease,
1717
JavaInstallerOptions,
1818
JavaInstallerResults
1919
} from '../base-models';
20-
import { ISapMachineAllVersions, ISapMachineVersions } from './models';
20+
import {ISapMachineAllVersions, ISapMachineVersions} from './models';
2121

2222
export class SapMachineDistribution extends JavaBase {
2323
constructor(installerOptions: JavaInstallerOptions) {
@@ -27,10 +27,12 @@ export class SapMachineDistribution extends JavaBase {
2727
protected async findPackageForDownload(
2828
version: string
2929
): Promise<JavaDownloadRelease> {
30-
core.debug(`Only stable versions: ${this.stable}`)
30+
core.debug(`Only stable versions: ${this.stable}`);
3131

3232
if (!['jdk', 'jre'].includes(this.packageType)) {
33-
throw new Error('SapMachine provides only the `jdk` and `jre` package type');
33+
throw new Error(
34+
'SapMachine provides only the `jdk` and `jre` package type'
35+
);
3436
}
3537

3638
const availableVersions = await this.getAvailableVersions();
@@ -60,10 +62,15 @@ export class SapMachineDistribution extends JavaBase {
6062
const platform = this.getPlatformOption();
6163
const arch = this.distributionArchitecture();
6264

63-
let fetchedReleasesJson = await this.fetchReleasesFromUrl('https://sap.github.io/SapMachine/assets/data/sapmachine-releases-all.json')
65+
let fetchedReleasesJson = await this.fetchReleasesFromUrl(
66+
'https://sap.github.io/SapMachine/assets/data/sapmachine-releases-all.json'
67+
);
6468

6569
if (!fetchedReleasesJson) {
66-
fetchedReleasesJson = await this.fetchReleasesFromUrl('https://api.github.com/repos/SAP/SapMachine/contents/assets/data/sapmachine-releases-all.json?ref=gh-pages', getGitHubHttpHeaders());
70+
fetchedReleasesJson = await this.fetchReleasesFromUrl(
71+
'https://api.github.com/repos/SAP/SapMachine/contents/assets/data/sapmachine-releases-all.json?ref=gh-pages',
72+
getGitHubHttpHeaders()
73+
);
6774
}
6875

6976
if (!fetchedReleasesJson) {
@@ -117,29 +124,42 @@ export class SapMachineDistribution extends JavaBase {
117124
this.architecture
118125
);
119126

120-
return { version: javaRelease.version, path: javaPath };
127+
return {version: javaRelease.version, path: javaPath};
121128
}
122129

123130
private parseVersions(
124131
platform: string,
125132
arch: string,
126-
versions: ISapMachineAllVersions,
133+
versions: ISapMachineAllVersions
127134
): ISapMachineVersions[] {
128135
const eligibleVersions: ISapMachineVersions[] = [];
129136

130137
for (const [, majorVersionMap] of Object.entries(versions)) {
131138
for (const [, jdkVersionMap] of Object.entries(majorVersionMap.updates)) {
132-
for (const [buildVersion, buildVersionMap] of Object.entries(jdkVersionMap)) {
133-
let buildVersionWithoutPrefix = buildVersion.replace('sapmachine-', '');
139+
for (const [buildVersion, buildVersionMap] of Object.entries(
140+
jdkVersionMap
141+
)) {
142+
let buildVersionWithoutPrefix = buildVersion.replace(
143+
'sapmachine-',
144+
''
145+
);
134146
if (!buildVersionWithoutPrefix.includes('.')) {
135147
// replace major version with major.minor.patch and keep the remaining build identifier after the + as is with regex
136-
buildVersionWithoutPrefix = buildVersionWithoutPrefix.replace(/(\d+)(\+.*)?/, '$1.0.0$2');
148+
buildVersionWithoutPrefix = buildVersionWithoutPrefix.replace(
149+
/(\d+)(\+.*)?/,
150+
'$1.0.0$2'
151+
);
137152
}
138153
// replace + with . to convert to semver format if we have more than 3 version digits
139154
if (buildVersionWithoutPrefix.split('.').length > 3) {
140-
buildVersionWithoutPrefix = buildVersionWithoutPrefix.replace('+', '.');
155+
buildVersionWithoutPrefix = buildVersionWithoutPrefix.replace(
156+
'+',
157+
'.'
158+
);
141159
}
142-
buildVersionWithoutPrefix = convertVersionToSemver(buildVersionWithoutPrefix);
160+
buildVersionWithoutPrefix = convertVersionToSemver(
161+
buildVersionWithoutPrefix
162+
);
143163

144164
// ignore invalid version
145165
if (!semver.valid(buildVersionWithoutPrefix)) {
@@ -148,23 +168,29 @@ export class SapMachineDistribution extends JavaBase {
148168
}
149169

150170
// skip earlyAccessVersions if stable version requested
151-
if (this.stable && buildVersionMap.ea === "true") {
171+
if (this.stable && buildVersionMap.ea === 'true') {
152172
continue;
153173
}
154174

155-
for (const [edition, editionAssets] of Object.entries(buildVersionMap.assets)) {
175+
for (const [edition, editionAssets] of Object.entries(
176+
buildVersionMap.assets
177+
)) {
156178
if (this.packageType !== edition) {
157179
continue;
158180
}
159-
for (const [archAndPlatForm, archAssets] of Object.entries(editionAssets)) {
160-
let expectedArchAndPlatform = `${platform}-${arch}`
181+
for (const [archAndPlatForm, archAssets] of Object.entries(
182+
editionAssets
183+
)) {
184+
let expectedArchAndPlatform = `${platform}-${arch}`;
161185
if (platform === 'linux-musl') {
162-
expectedArchAndPlatform = `linux-${arch}-musl`
186+
expectedArchAndPlatform = `linux-${arch}-musl`;
163187
}
164188
if (archAndPlatForm !== expectedArchAndPlatform) {
165-
continue
189+
continue;
166190
}
167-
for (const [contentType, contentTypeAssets] of Object.entries(archAssets)) {
191+
for (const [contentType, contentTypeAssets] of Object.entries(
192+
archAssets
193+
)) {
168194
// skip if not tar.gz and zip files
169195
if (contentType !== 'tar.gz' && contentType !== 'zip') {
170196
continue;
@@ -175,7 +201,7 @@ export class SapMachineDistribution extends JavaBase {
175201
version: buildVersionWithoutPrefix,
176202
checksum: contentTypeAssets.checksum,
177203
downloadLink: contentTypeAssets.url,
178-
packageType: edition,
204+
packageType: edition
179205
});
180206
}
181207
}
@@ -206,7 +232,7 @@ export class SapMachineDistribution extends JavaBase {
206232
case 'win32':
207233
return 'windows';
208234
case 'darwin':
209-
return 'macos'
235+
return 'macos';
210236
case 'linux':
211237
// figure out if alpine/musl
212238
if (fs.existsSync('/etc/alpine-release')) {
@@ -218,7 +244,10 @@ export class SapMachineDistribution extends JavaBase {
218244
}
219245
}
220246

221-
private async fetchReleasesFromUrl(url: string, headers: OutgoingHttpHeaders = {}): Promise<ISapMachineAllVersions | null> {
247+
private async fetchReleasesFromUrl(
248+
url: string,
249+
headers: OutgoingHttpHeaders = {}
250+
): Promise<ISapMachineAllVersions | null> {
222251
try {
223252
core.debug(
224253
`Trying to fetch available SapMachine versions info from the primary url: ${url}`
@@ -229,7 +258,8 @@ export class SapMachineDistribution extends JavaBase {
229258
return releases;
230259
} catch (err) {
231260
core.debug(
232-
`Fetching SapMachine versions info from the link: ${url} ended up with the error: ${(err as Error).message
261+
`Fetching SapMachine versions info from the link: ${url} ended up with the error: ${
262+
(err as Error).message
233263
}`
234264
);
235265
return null;
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
export interface ISapMachineAllVersions {
2-
[major: string]: {
3-
lts: string,
4-
updates: {
5-
[full_version: string]: {
6-
[sapmachineBuild: string]: {
7-
release_url: string,
8-
ea: string,
9-
assets: {
10-
[packageType: string]: {
11-
[arch: string]: {
12-
[content_type: string]: {
13-
name: string,
14-
checksum: string,
15-
url: string
16-
};
17-
};
18-
};
19-
};
2+
[major: string]: {
3+
lts: string;
4+
updates: {
5+
[full_version: string]: {
6+
[sapmachineBuild: string]: {
7+
release_url: string;
8+
ea: string;
9+
assets: {
10+
[packageType: string]: {
11+
[arch: string]: {
12+
[content_type: string]: {
13+
name: string;
14+
checksum: string;
15+
url: string;
2016
};
17+
};
2118
};
19+
};
2220
};
21+
};
2322
};
23+
};
2424
}
2525

2626
export interface ISapMachineVersions {
27-
os: string;
28-
architecture: string;
29-
version: string;
30-
checksum: string;
31-
downloadLink: string;
32-
packageType: string;
27+
os: string;
28+
architecture: string;
29+
version: string;
30+
checksum: string;
31+
downloadLink: string;
32+
packageType: string;
3333
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy