Skip to content

Commit 0146d70

Browse files
sudhirvermadgolovin
authored andcommitted
Verify during the build that tools download info is correct. (#836)
1 parent 52b9701 commit 0146d70

File tree

13 files changed

+174
-89
lines changed

13 files changed

+174
-89
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
.vscode-test/
44
*.vsix
55
coverage/
6-
toFile
6+
toFile
7+
cache

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"out": true // set this to false to include "out" folder in search results
88
},
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10-
"typescript.tsc.autoDetect": "off"
10+
"typescript.tsc.autoDetect": "off",
11+
"debug.node.autoAttach": "off"
1112
}

build/check-copyright.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ walker('.').filterDir((dir: string) => dir !== 'node_modules' && dir !== '.vscod
1212
if (file.endsWith('.ts')) {
1313
const result = await WatchUtil.grep(file, /Copyright \(c\)/);
1414
if (!result) {
15-
if(!failed) {
15+
if (!failed) {
1616
failed = true;
1717
console.log('Files without copyright comment:');
1818
}

build/verify-tools.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import hasha = require('hasha');
9+
import mkdirp = require('mkdirp');
10+
import fs = require('fs-extra');
11+
import path = require("path");
12+
import cp = require('child_process');
13+
import configData = require('../src/tools.json');
14+
import os = require('os');
15+
import { DownloadUtil } from '../src/util/download';
16+
17+
async function verifyTools() {
18+
for (const key in configData) {
19+
for (const OS in configData[key].platform) {
20+
const targetFolder = path.resolve(os.tmpdir(), OS);
21+
await downloadFileAndCreateSha256(targetFolder, configData[key].platform[OS].dlFileName, configData[key].platform[OS].url, configData[key].platform[OS].sha256sum);
22+
}
23+
}
24+
}
25+
26+
async function downloadFileAndCreateSha256(targetFolder: string, fileName: string, reqURL: string, sha256sum: string) {
27+
if (!fs.existsSync(targetFolder)) {
28+
await mkdirp.sync(targetFolder);
29+
}
30+
const currentFile = path.join(targetFolder, fileName);
31+
console.log(`${currentFile} download started from ${reqURL}`)
32+
await DownloadUtil.downloadFile(reqURL, currentFile, (current) => console.log(current + '%'));
33+
const currentSHA256 = await hasha.fromFile(currentFile, {algorithm: 'sha256'});;
34+
if (currentSHA256 === sha256sum) {
35+
console.log( `[INFO] ${currentFile} is downloaded and sha256 is correct`);
36+
} else {
37+
throw Error(`${currentFile} is downloaded and sha256 is not correct`);
38+
}
39+
}
40+
41+
const fileCheckRegex = /\w*tools.json/;
42+
cp.exec('git diff --name-only master..HEAD', async (error, stdout, stderr) => {
43+
if (error) {
44+
throw error;
45+
}
46+
console.log('The changed files:');
47+
console.log(stdout);
48+
if (fileCheckRegex.test(stdout)) {
49+
console.log('tools.json is changed, starting download verification')
50+
await verifyTools();
51+
} else {
52+
console.log('tools.json is not changed, skipping download verification')
53+
}
54+
});

package-lock.json

Lines changed: 47 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,13 @@
632632
},
633633
"extensionDependencies": [],
634634
"scripts": {
635+
"verify": "node ./out/build/verify-tools.js",
635636
"vscode:prepublish": "npm run compile",
636637
"compile": "tsc -p ./",
637638
"watch": "tsc -watch -p ./",
638639
"postinstall": "node ./node_modules/vscode/bin/install",
639640
"clean": "rm -rf out || rmdir out /s /q",
640-
"test": "npm run clean && npm run compile && node ./node_modules/vscode/bin/test",
641+
"test": "npm run clean && npm run compile && npm run verify && node ./node_modules/vscode/bin/test",
641642
"update-deps": "node_modules/.bin/ncu --upgrade --loglevel verbose --packageFile package.json && npm update",
642643
"coverage:upload": "codecov -f coverage/coverage-final.json",
643644
"build": "npm run clean && tslint -p tslint.json && npm run compile"
@@ -685,6 +686,7 @@
685686
"git-transport-protocol": "^0.1.0",
686687
"hasha": "^5.0.0",
687688
"js-yaml": "^3.13.1",
689+
"mkdirp": "^0.5.1",
688690
"open": "^6.2.0",
689691
"request": "^2.88.0",
690692
"request-progress": "^3.0.0",

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ async function initNamespaceName(node: ClusterExplorerV1.ClusterExplorerResource
113113
if (kubectl.available) {
114114
const result = await kubectl.api.invokeCommand('config view -o json');
115115
const config = JSON.parse(result.stdout);
116-
const ctxName = config["current-context"];
117116
const currentContext = (config.contexts || []).find((ctx) => ctx.name === node.name);
118117
if (!currentContext) {
119118
return "";
@@ -125,7 +124,7 @@ async function initNamespaceName(node: ClusterExplorerV1.ClusterExplorerResource
125124
async function customizeAsync(node: ClusterExplorerV1.ClusterExplorerResourceNode, treeItem: vscode.TreeItem): Promise<void> {
126125
if ((node as any).nodeType === 'context') {
127126
lastNamespace = await initNamespaceName(node);
128-
if(isOpenShift()) {
127+
if (isOpenShift()) {
129128
treeItem.iconPath = vscode.Uri.file(path.join(__dirname, "../../images/context/cluster-node.png"));
130129
}
131130
}

src/openshift/application.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class Application extends OpenShiftItem {
3636
"Select Application to delete");
3737
if (application) {
3838
const appName = application.getName();
39-
const projName = application.getParent().getName();
4039
const value = await window.showWarningMessage(`Do you want to delete Application '${appName}?'`, 'Yes', 'Cancel');
4140
if (value === 'Yes') {
4241
return Progress.execFunctionWithProgress(`Deleting the Application '${appName}'`, () => Application.odo.deleteApplication(application))

src/openshift/url.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Component } from '../openshift/component';
99
import { V1ServicePort } from '@kubernetes/client-node';
1010
import { OpenShiftItem } from './openshiftItem';
1111
import { Progress } from "../util/progress";
12-
import { URL } from 'url';
1312
import open = require('open');
1413
import { ChildProcess } from 'child_process';
1514

0 commit comments

Comments
 (0)