Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARAZDO-400 Dependency upgrade #400

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ const mergeStream = require("merge-stream");
const gulpRename = require("gulp-rename");
const gulpDownload = require("gulp-download");
const map = require("map-stream");
const gulpDel = require("del");
const globby = require("globby");
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 @@ -105,8 +103,8 @@ exports.getBuildInfo = function (type, vssData) {
const name = `sonar-scanner-azdo-${productAccronym}`;

const packageVersion = getVersionWithCirrusBuildNumber(vssData.version);
const vsixPaths = globby.sync(path.join(DIST_DIR, `*-${type}.vsix`));
const additionalPaths = globby.sync(
const vsixPaths = glob(path.join(DIST_DIR, `*-${type}.vsix`));
const additionalPaths = glob(
path.join(DIST_DIR, `*{cyclonedx-${type}-*.json,cyclonedx-latest.json,-${type}*.asc}`),
);
const qualifierMatch = new RegExp(`${packageVersion}-(.+).vsix$`);
Expand Down Expand Up @@ -196,9 +194,9 @@ exports.runSonarQubeScanner = function (extension, customOptions, callback) {
"sonar.analysis.pipeline": process.env.CIRRUS_BUILD_ID,
"sonar.analysis.repository": process.env.CIRRUS_REPO_FULL_NAME,
"sonar.eslint.reportPaths": "eslint-report.json",
"sonar.javascript.lcov.reportPaths": globby
.sync([path.join("src", "common", "*", "coverage", "lcov.info")])
.join(","),
"sonar.javascript.lcov.reportPaths": glob([
path.join("src", "common", "*", "coverage", "lcov.info"),
]).join(","),
...customOptions,
};

Expand All @@ -223,7 +221,7 @@ function cycloneDxPipe(...commonPaths) {
.pipe(
exec((file) => {
const flavour = file.dirname.split(path.sep).pop();
return `npm run cyclonedx-run -- --output ${DIST_DIR}/cyclonedx-${flavour}.json ${file.dirname}`;
return `npm run cyclonedx-run -- --output-file ${DIST_DIR}/cyclonedx-${flavour}.json ${file.dirname}/package.json`;
}),
)
.pipe(exec.reporter());
Expand Down
222 changes: 107 additions & 115 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const { rimraf } = require("rimraf");
const path = require("path");
const gulp = require("gulp");
const gulpFile = require("gulp-file");
const fs = require("fs-extra");
const log = require("fancy-log");
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 globby = require("globby");
const mergeStream = require("merge-stream");
const { globSync: glob } = require("glob");
const typescript = require("typescript");
const decompress = require("gulp-decompress");
const needle = require("needle");
const del = require("del");
const esbuild = require("esbuild");
const {
SOURCE_DIR,
Expand Down Expand Up @@ -51,15 +51,15 @@ const isProd = process.env.BUILD_MODE === "production";
/**
* Delete all files in the build directory
*/
gulp.task("clean", () => del([path.join(BUILD_DIR, "**"), path.join(DIST_DIR, "**")]));
gulp.task("clean", () => rimraf([path.join(BUILD_DIR, "**"), path.join(DIST_DIR, "**")]));

/** BUILD *****************************************************************************************/

/**
* Run npm install for all common folders
*/
gulp.task("build:install-dependencies", async () => {
const commonFolders = globby.sync(["src/common/*/index.ts"]);
const commonFolders = glob(["src/common/*/index.ts"]);

for (const commonFolder of commonFolders) {
const folder = path.dirname(commonFolder);
Expand All @@ -86,7 +86,7 @@ gulp.task("build:copy-extension", () => {
*/
gulp.task("build:typescript", () => {
// Get all tsconfig files in src
const tscPaths = globby.sync(["src/tsconfig*.json"]);
const tscPaths = glob(["src/tsconfig*.json"]);

// Build each tsconfig
return mergeStream(
Expand All @@ -108,7 +108,7 @@ gulp.task("build:typescript", () => {
* Bundle tasks
*/
gulp.task("build:bundle", async () => {
const tasks = globby.sync(path.join(SOURCE_DIR, "extensions", "*", "tasks", "*", "v*", "*.ts"));
const tasks = glob(path.join(SOURCE_DIR, "extensions", "*", "tasks", "*", "v*", "*.ts"));
for (const task of tasks) {
const [extension, , taskName, version] = task.split(path.sep).slice(-5);
const commonFolder = getTaskCommonFolder(taskName, version);
Expand All @@ -131,7 +131,7 @@ gulp.task("build:bundle", async () => {
* Build all scanners needed by tasks
*/
gulp.task("build:download-scanners", () => {
const configJss = globby.sync([path.join(BUILD_TS_DIR, "common", "*", "config.js")]);
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
Expand Down Expand Up @@ -174,7 +174,7 @@ gulp.task("build:download-scanners", () => {
* Copy all task files to the build directory
*/
gulp.task("build:copy", () => {
const tasks = globby.sync(["build/ts/extensions/*/tasks/*/v*/*.js"]);
const tasks = glob(["build/ts/extensions/*/tasks/*/v*/*.js"]);

const streams = [];

Expand Down Expand Up @@ -336,11 +336,9 @@ gulp.task(
/** EXTENSION *************************************************************************************/

gulp.task("extension:build", (done) => {
const publisher = isProd ? "sonarsource" : yargs.argv.publisher ?? "foo";
const publisher = isProd ? "sonarsource" : (yargs.argv.publisher ?? "foo");

const vssExtensions = globby.sync([
path.join(SOURCE_DIR, "extensions", "*", "vss-extension.json"),
]);
const vssExtensions = glob([path.join(SOURCE_DIR, "extensions", "*", "vss-extension.json")]);

for (const vssExtension of vssExtensions) {
// eslint-disable-next-line import/no-dynamic-require
Expand Down Expand Up @@ -408,9 +406,7 @@ gulp.task("ci:azure:hotfix-extensions-version", () => {
throw new Error("Missing build number");
}

const vssExtensions = globby.sync([
path.join(SOURCE_DIR, "extensions", "*", "vss-extension.json"),
]);
const vssExtensions = glob([path.join(SOURCE_DIR, "extensions", "*", "vss-extension.json")]);

return mergeStream(
vssExtensions.map((vssExtension) =>
Expand All @@ -434,7 +430,7 @@ gulp.task("ci:azure:hotfix-tasks-version", () => {
throw new Error("Missing build number");
}

const tasks = globby.sync(["src/extensions/*/tasks/*/v*/*.json"]);
const tasks = glob(["src/extensions/*/tasks/*/v*/*.json"]);

return mergeStream(
tasks.map((task) =>
Expand Down Expand Up @@ -503,136 +499,132 @@ gulp.task("upload:sign", () => {
});

gulp.task("upload:cyclonedx", () => {
const commonPaths = globby.sync([path.join(SOURCE_DIR, "common", "*", "package.json")]);
const commonPaths = glob([path.join(SOURCE_DIR, "common", "*", "package.json")]);

return cycloneDxPipe(...commonPaths.map((commonPath) => path.dirname(commonPath)));
});

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`;

return mergeStream(
globby
.sync(
path.join(
DIST_DIR,
"*{-sonarqube.vsix,cyclonedx-sonarqube-*.json,cyclonedx-latest.json,-sonarqube*.asc}",
),
)
.map((filePath) => {
const [sha1, md5] = fileHashsum(filePath);
const extensionPath = path.join(BUILD_EXTENSION_DIR, "sonarqube");
const vssExtension = fs.readJsonSync(path.join(extensionPath, "vss-extension.json"));
const packageVersion = getVersionWithCirrusBuildNumber(vssExtension.version);
return gulp
.src(filePath)
.pipe(
gulpArtifactoryUpload({
url:
process.env.ARTIFACTORY_URL +
"/" +
process.env.ARTIFACTORY_DEPLOY_REPO +
"/org/sonarsource/scanner/azdo/" +
name +
"/" +
"sonarqube" +
"/" +
packageVersion,
username: process.env.ARTIFACTORY_DEPLOY_USERNAME,
password: process.env.ARTIFACTORY_DEPLOY_PASSWORD,
properties: {
"vcs.revision": process.env.CIRRUS_CHANGE_IN_REPO,
"vcs.branch": process.env.CIRRUS_BRANCH,
"build.name": name,
"build.number": process.env.BUILD_NUMBER,
},
request: {
headers: {
"X-Checksum-MD5": md5,
"X-Checksum-Sha1": sha1,
},
glob(
path.join(
DIST_DIR,
"*{-sonarqube.vsix,cyclonedx-sonarqube-*.json,cyclonedx-latest.json,-sonarqube*.asc}",
),
).map((filePath) => {
const [sha1, md5] = fileHashsum(filePath);
const extensionPath = path.join(BUILD_EXTENSION_DIR, "sonarqube");
const vssExtension = fs.readJsonSync(path.join(extensionPath, "vss-extension.json"));
const packageVersion = getVersionWithCirrusBuildNumber(vssExtension.version);
return gulp
.src(filePath)
.pipe(
gulpArtifactoryUpload({
url:
process.env.ARTIFACTORY_URL +
"/" +
process.env.ARTIFACTORY_DEPLOY_REPO +
"/org/sonarsource/scanner/azdo/" +
name +
"/" +
"sonarqube" +
"/" +
packageVersion,
username: process.env.ARTIFACTORY_DEPLOY_USERNAME,
password: process.env.ARTIFACTORY_DEPLOY_PASSWORD,
properties: {
"vcs.revision": process.env.CIRRUS_CHANGE_IN_REPO,
"vcs.branch": process.env.CIRRUS_BRANCH,
"build.name": name,
"build.number": process.env.BUILD_NUMBER,
},
request: {
headers: {
"X-Checksum-MD5": md5,
"X-Checksum-Sha1": sha1,
},
}),
)
.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`;

return mergeStream(
globby
.sync(
path.join(
DIST_DIR,
"*{-sonarcloud.vsix,cyclonedx-sonarcloud-*.json,cyclonedx-latest.json,-sonarcloud*.asc}",
),
)
.map((filePath) => {
const extensionPath = path.join(BUILD_EXTENSION_DIR, "sonarcloud");
const vssExtension = fs.readJsonSync(path.join(extensionPath, "vss-extension.json"));
const packageVersion = getVersionWithCirrusBuildNumber(vssExtension.version);
const [sha1, md5] = fileHashsum(filePath);
return gulp
.src(filePath)
.pipe(
gulpArtifactoryUpload({
url:
process.env.ARTIFACTORY_URL +
"/" +
process.env.ARTIFACTORY_DEPLOY_REPO +
"/org/sonarsource/scanner/azdo/" +
name +
"/" +
"sonarcloud" +
"/" +
packageVersion,
username: process.env.ARTIFACTORY_DEPLOY_USERNAME,
password: process.env.ARTIFACTORY_DEPLOY_PASSWORD,
properties: {
"vcs.revision": process.env.CIRRUS_CHANGE_IN_REPO,
"vcs.branch": process.env.CIRRUS_BRANCH,
"build.name": name,
"build.number": process.env.BUILD_NUMBER,
},
request: {
headers: {
"X-Checksum-MD5": md5,
"X-Checksum-Sha1": sha1,
},
glob(
path.join(
DIST_DIR,
"*{-sonarcloud.vsix,cyclonedx-sonarcloud-*.json,cyclonedx-latest.json,-sonarcloud*.asc}",
),
).map((filePath) => {
const extensionPath = path.join(BUILD_EXTENSION_DIR, "sonarcloud");
const vssExtension = fs.readJsonSync(path.join(extensionPath, "vss-extension.json"));
const packageVersion = getVersionWithCirrusBuildNumber(vssExtension.version);
const [sha1, md5] = fileHashsum(filePath);
return gulp
.src(filePath)
.pipe(
gulpArtifactoryUpload({
url:
process.env.ARTIFACTORY_URL +
"/" +
process.env.ARTIFACTORY_DEPLOY_REPO +
"/org/sonarsource/scanner/azdo/" +
name +
"/" +
"sonarcloud" +
"/" +
packageVersion,
username: process.env.ARTIFACTORY_DEPLOY_USERNAME,
password: process.env.ARTIFACTORY_DEPLOY_PASSWORD,
properties: {
"vcs.revision": process.env.CIRRUS_CHANGE_IN_REPO,
"vcs.branch": process.env.CIRRUS_BRANCH,
"build.name": name,
"build.number": process.env.BUILD_NUMBER,
},
request: {
headers: {
"X-Checksum-MD5": md5,
"X-Checksum-Sha1": sha1,
},
}),
)
.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 @@ -670,7 +662,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
Loading