Skip to content

Commit

Permalink
SONARAZDO-400 Drop obsolete gulp dependencies & Fix vulnerabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
7PH committed Aug 13, 2024
1 parent d84dc0f commit 4d5e244
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 663 deletions.
12 changes: 0 additions & 12 deletions config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ const exec = require("gulp-exec");
const dateformat = require("dateformat");
const orderedStreams = require("ordered-read-streams");
const gulpRename = require("gulp-rename");
const gulpDownload = require("gulp-download");
const map = require("map-stream");
const { globSync: glob } = require("glob");
const sonarqubeScanner = require("sonarqube-scanner").default;
const collect = require("gulp-collect");
const Vinyl = require("vinyl");
const { resolveRelativePath, SOURCE_DIR, DIST_DIR, BUILD_DIR } = require("./paths");

Expand Down Expand Up @@ -41,16 +39,6 @@ function run(cl, options = {}) {
}
exports.run = run;

// Return a stream that downloads the file if urlOrPath is a link, or copies it otherwise (if it is a relaitve path)
function downloadOrCopy(urlOrPath) {
if (urlOrPath.startsWith("http")) {
return gulpDownload(urlOrPath);
} else {
return gulp.src(urlOrPath);
}
}
exports.downloadOrCopy = downloadOrCopy;

function npmInstall(packagePath) {
const cwd = process.cwd();
run(`cd ${path.dirname(packagePath)} && npm install && cd ${cwd}`);
Expand Down
78 changes: 36 additions & 42 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { rimraf } = require("rimraf");
const path = require("path");
const gulp = require("gulp");
const log = require("fancy-log");
const gulpFile = require("gulp-file");
const fs = require("fs-extra");
const yargs = require("yargs");
const gulpJsonEditor = require("gulp-json-editor");
const gulpRename = require("gulp-rename");
const gulpArtifactoryUpload = require("gulp-artifactory-upload");
const ts = require("gulp-typescript");
const gulpUtil = require("gulp-util");
const { globSync: glob } = require("glob");
const { Readable } = require("stream");
const { finished } = require("stream/promises");
const orderedStreams = require("ordered-read-streams");
const typescript = require("typescript");
const decompress = require("gulp-decompress");
const decompress = require("decompress");
const needle = require("needle");
const esbuild = require("esbuild");
const {
Expand All @@ -31,7 +33,6 @@ const {
getBuildInfo,
npmInstallTask,
cycloneDxPipe,
downloadOrCopy,
getVersionWithCirrusBuildNumber,
run,
runSonarQubeScanner,
Expand Down Expand Up @@ -123,44 +124,37 @@ gulp.task("build:bundle", async () => {
/**
* Build all scanners needed by tasks
*/
gulp.task("build:download-scanners", () => {
gulp.task("build:download-scanners", async () => {
async function downloadScanner(url, outDir) {
await fs.mkdirp(outDir);
const outPath = path.join(outDir, url.match(/[^/]+$/)[0]);
const stream = fs.createWriteStream(outPath);
const { body } = await fetch(url);
await finished(Readable.fromWeb(body).pipe(stream));
await decompress(outPath, outDir);
}

const configJss = glob([path.join(BUILD_TS_DIR, "common", "*", "config.js")]);
const streams = [];
for (const configJs of configJss) {
// eslint-disable-next-line import/no-dynamic-require
const { scanner } = require(configJs);
streams.push(
downloadOrCopy(scanner.classicUrl)
.pipe(decompress())
.pipe(
gulp.dest(
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_FRAMEWORK_DIRNAME, scanner.cliVersion),
),
),
await downloadScanner(
scanner.cliUrl,
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_FRAMEWORK_DIRNAME, scanner.cliVersion),
);

streams.push(
downloadOrCopy(scanner.dotnetUrl)
.pipe(decompress())
.pipe(
gulp.dest(
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_DOTNET_DIRNAME, scanner.msBuildVersion),
),
),
await downloadScanner(
scanner.dotnetUrl,
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_DOTNET_DIRNAME, scanner.msBuildVersion),
);

if (scanner.cliUrl) {
streams.push(
downloadOrCopy(scanner.cliUrl)
.pipe(decompress())
.pipe(
gulp.dest(path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_CLI_DIRNAME, scanner.cliVersion)),
),
await downloadScanner(
scanner.cliUrl,
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_CLI_DIRNAME, scanner.cliVersion),
);
}
}

return orderedStreams(streams);
});

/**
Expand Down Expand Up @@ -502,12 +496,12 @@ gulp.task("upload:cyclonedx", () => {

gulp.task("upload:vsix:sonarqube", () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip upload:vsix");
return gulpUtil.noop;
log("Not on master nor PR, skip upload:vsix");
return Promise.resolve();
}
if (process.env.CIRRUS_PR && process.env.DEPLOY_PULL_REQUEST === "false") {
gulpUtil.log("On PR, but artifacts should not be deployed, skip upload:vsix");
return gulpUtil.noop;
log("On PR, but artifacts should not be deployed, skip upload:vsix");
return Promise.resolve();
}
const name = `${packageJSON.name}-sq`;

Expand Down Expand Up @@ -554,19 +548,19 @@ gulp.task("upload:vsix:sonarqube", () => {
},
}),
)
.on("error", gulpUtil.log);
.on("error", log);
}),
);
});

gulp.task("upload:vsix:sonarcloud", () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip upload:vsix");
return gulpUtil.noop;
log("Not on master nor PR, skip upload:vsix");
return Promise.resolve();
}
if (process.env.CIRRUS_PR && process.env.DEPLOY_PULL_REQUEST === "false") {
gulpUtil.log("On PR, but artifacts should not be deployed, skip upload:vsix");
return gulpUtil.noop;
log("On PR, but artifacts should not be deployed, skip upload:vsix");
return Promise.resolve();
}
const name = `${packageJSON.name}-sc`;

Expand Down Expand Up @@ -613,18 +607,18 @@ gulp.task("upload:vsix:sonarcloud", () => {
},
}),
)
.on("error", gulpUtil.log);
.on("error", log);
}),
);
});

gulp.task("upload:buildinfo", async () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip upload:buildinfo");
log("Not on master nor PR, skip upload:buildinfo");
return;
}
if (process.env.CIRRUS_PR && process.env.DEPLOY_PULL_REQUEST === "false") {
gulpUtil.log("On PR, but artifacts should not be deployed, skip upload:buildinfo");
log("On PR, but artifacts should not be deployed, skip upload:buildinfo");
return;
}

Expand Down Expand Up @@ -662,7 +656,7 @@ gulp.task(

gulp.task("promote", async () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip promote");
log("Not on master nor PR, skip promote");
return;
}

Expand Down
Loading

0 comments on commit 4d5e244

Please sign in to comment.