Skip to content

Commit 2c1a046

Browse files
authored
Merge pull request #71 from microsoft/release/vNext
v1.8.2
2 parents 19539f7 + e382190 commit 2c1a046

File tree

8 files changed

+306
-5265
lines changed

8 files changed

+306
-5265
lines changed

.github/workflows/on-push-verification.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: MSDO On Push Verification
44
on:
55
push:
66
branches:
7-
- '*'
7+
- '**'
88

99
permissions:
1010
security-events: write

gulpfile.js

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
13
const gulp = require('gulp');
2-
const shell = require('gulp-shell');
4+
const path = require('path');
5+
const process = require('process');
36
const ts = require('gulp-typescript');
47

58
const tsProject = ts.createProject('tsconfig.json');
@@ -10,15 +13,88 @@ function clean(cb) {
1013
.then(() => cb());
1114
}
1215

16+
function sideload(cb) {
17+
if (process.env.SECURITY_DEVOPS_ACTION_BUILD_SIDELOAD === 'true') {
18+
console.log('Sideload mode enabled. Linking @microsoft/security-devops-actions-toolkit');
19+
20+
const toolkitSrcDir = path.resolve(path.join(__dirname, '..', 'security-devops-actions-toolkit'));
21+
22+
if (!fs.existsSync(toolkitSrcDir)) {
23+
throw new Error(`Could not the toolkit repo directory: ${toolkitSrcDir}. Please clone the repo to a parallel directory to this extension repo. Repo homepage: https://github.com/microsoft/security-devops-actions-toolkit`);
24+
}
25+
26+
const toolkitNodeModulesDir = path.join(__dirname, 'node_modules', '@microsoft', 'security-devops-actions-toolkit');
27+
28+
if (!fs.existsSync(toolkitNodeModulesDir)) {
29+
throw new Error(`The node_modules directory for the toolkit does not exist. please run npm install before continuing: ${toolkitNodeModulesDir}`);
30+
}
31+
32+
if (process.env.SECURITY_DEVOPS_ACTION_BUILD_SIDELOAD_BUILD !== 'false') {
33+
console.log('Building sideload project: npm run build');
34+
const output = execSync('npm run build', { cwd: toolkitSrcDir, encoding: 'utf8' });
35+
console.log(output);
36+
}
37+
38+
console.log(`Clearing the existing toolkit directory: ${toolkitNodeModulesDir}`);
39+
clearDir(toolkitNodeModulesDir);
40+
41+
const toolkitDistDir = path.join(toolkitSrcDir, 'dist');
42+
43+
console.log("Copying sideload build...");
44+
copyFiles(toolkitDistDir, toolkitNodeModulesDir);
45+
46+
fs.writeFileSync(
47+
path.join(toolkitNodeModulesDir, '.sideloaded'),
48+
'This package was built and sideloaded by the security-devops-action build process. Do not commit this file to source control.');
49+
}
50+
cb();
51+
}
52+
1353
function compile(cb) {
1454
tsProject
1555
.src()
1656
.pipe(tsProject()).js
17-
.pipe(gulp.dest('lib'));
18-
cb();
57+
.pipe(gulp.dest('lib'))
58+
.on('end', () => cb());
1959
}
2060

61+
function clearDir(dirPath) {
62+
// Get a list of files and subdirectories in the directory
63+
const items = fs.readdirSync(dirPath);
64+
65+
for (const item of items) {
66+
const itemPath = path.join(dirPath, item);
67+
68+
if (fs.statSync(itemPath).isFile()) {
69+
fs.unlinkSync(itemPath);
70+
} else {
71+
clearDir(itemPath);
72+
}
73+
}
74+
75+
// Finally, remove the empty directory
76+
fs.rmdirSync(dirPath);
77+
}
78+
79+
function copyFiles(srcDir, destDir) {
80+
if (!fs.existsSync(destDir)) {
81+
fs.mkdirSync(destDir, { recursive: true });
82+
}
83+
84+
fs.readdirSync(srcDir).forEach((file) => {
85+
const srcFilePath = path.join(srcDir, file);
86+
const destFilePath = path.join(destDir, file);
87+
88+
if (fs.statSync(srcFilePath).isDirectory()) {
89+
copyFiles(srcFilePath, destFilePath);
90+
} else {
91+
fs.copyFileSync(srcFilePath, destFilePath);
92+
console.log(`Copied ${srcFilePath} to ${destFilePath}`);
93+
}
94+
});
95+
}
96+
2197
exports.clean = clean;
2298
exports.compile = compile;
23-
exports.build = gulp.series(clean, compile);
99+
exports.build = gulp.series(clean, sideload, compile);
24100
exports.default = exports.build;

0 commit comments

Comments
 (0)