Skip to content

Commit 6558c67

Browse files
committed
improve code for verify tools
1 parent 079a7ff commit 6558c67

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

build/verify-tools.ts

+21-33
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
/* eslint-disable no-console */
2+
/* eslint-disable @typescript-eslint/no-misused-promises */
3+
/* eslint-disable no-await-in-loop */
4+
/* eslint-disable guard-for-in */
5+
/* eslint-disable no-restricted-syntax */
16
/*-----------------------------------------------------------------------------------------------
27
* Copyright (c) Red Hat, Inc. All rights reserved.
38
* Licensed under the MIT License. See LICENSE file in the project root for license information.
49
*-----------------------------------------------------------------------------------------------*/
5-
/* eslint-disable no-console */
610

7-
// import { CancellationToken } from 'vscode';
811
import { exec } from 'child_process';
912
import { tmpdir } from 'os';
1013
import { join, resolve } from 'path';
1114
import { existsSync } from 'fs-extra';
1215
import { fromFile } from 'hasha';
1316
import { sync } from 'mkdirp';
17+
import { exit } from 'shelljs';
1418
import configData = require('../src/cli/cli-config.json');
1519
import { DownloadUtil } from '../src/util/download';
16-
// import { Config } from '../src/cli/cli-config';
17-
// import loadJSON from '../src/util/parse';
18-
19-
// const configData = '../src/cli/cli-config.json';
2020

2121
async function downloadFileAndCreateSha256(
2222
targetFolder: string,
@@ -29,7 +29,6 @@ async function downloadFileAndCreateSha256(
2929
}
3030
const currentFile = join(targetFolder, fileName);
3131
console.log(`${currentFile} download started from ${reqURL}`);
32-
// const token: CancellationToken = null;
3332
await DownloadUtil.downloadFile(reqURL, currentFile, (current) => console.log(`${current}%`));
3433
const currentSHA256 = await fromFile(currentFile, { algorithm: 'sha256' });
3534
if (currentSHA256 === sha256sum) {
@@ -39,13 +38,12 @@ async function downloadFileAndCreateSha256(
3938
}
4039
}
4140

42-
function verifyTools(): void {
43-
Object.keys(configData).forEach((key) => {
41+
async function verifyTools(): Promise<void> {
42+
for (const key in configData) {
4443
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
45-
Object.keys(configData[key].platform).forEach((OS) => {
44+
for (const OS in configData[key].platform) {
4645
const targetFolder = resolve(tmpdir(), OS);
47-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
48-
downloadFileAndCreateSha256(
46+
await downloadFileAndCreateSha256(
4947
targetFolder,
5048
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5149
configData[key].platform[OS].dlFileName,
@@ -54,37 +52,27 @@ function verifyTools(): void {
5452
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5553
configData[key].platform[OS].sha256sum,
5654
);
57-
});
58-
});
55+
}
56+
}
5957
}
60-
// function verifyTools(): void {
61-
// loadJSON<KnConfig>(configData).then((data: KnConfig): void => {
62-
// Object.keys(data).forEach((key) => {
63-
// Object.keys(data[key].platform).forEach((OS) => {
64-
// const targetFolder = resolve(tmpdir(), OS);
65-
// downloadFileAndCreateSha256(
66-
// targetFolder,
67-
// data[key].platform[OS].dlFileName,
68-
// data[key].platform[OS].url,
69-
// data[key].platform[OS].sha256sum,
70-
// );
71-
// });
72-
// });
73-
// });
74-
// }
7558

7659
const fileCheckRegex = /\w*cli-config.json/;
7760

78-
exec('git diff --name-only origin/main -- .', (error, stdout) => {
61+
exec('git diff --name-only origin/main -- .', async (error, stdout) => {
7962
if (error) {
8063
throw error;
8164
}
8265
console.log('The changed files:');
8366
console.log(stdout);
8467
if (fileCheckRegex.test(stdout)) {
85-
console.log('cli-config.json is changed, starting download verification');
86-
verifyTools();
68+
console.log('tools.json is changed, starting download verification');
69+
try {
70+
await verifyTools();
71+
} catch (err) {
72+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
73+
exit(1);
74+
}
8775
} else {
88-
console.log('cli-config.json is not changed, skipping download verification');
76+
console.log('tools.json is not changed, skipping download verification');
8977
}
9078
});

test/ui-test/extensionUITest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { cleanUpNotifications, findNotification, safeNotificationExists } from '
2424
function execShellCommand(cmd) {
2525
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
2626
const { exec } = require('child_process');
27-
return new Promise((resolve, reject) => {
27+
return new Promise((resolve) => {
2828
exec(cmd, (error, stdout, stderr) => {
2929
resolve(stdout || stderr);
3030
});

0 commit comments

Comments
 (0)