Skip to content

Commit

Permalink
chore(ci): better snyk error COMPASS-7693 (#5543)
Browse files Browse the repository at this point in the history
* chore(ci): better snyk error

* skip snyk test for deleted packages

* use 50 mb and clarify the output
  • Loading branch information
mcasimir authored Mar 7, 2024
1 parent 18d819f commit 463afb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ functions:
return_code=$?
set -e
echo
# Runs for all the commits on main, including nightly builds:
if [[ "$EVERGREEN_IS_PATCH" != "true" ]] && [[ "${project}" == "10gen-compass-main" ]]; then
export JIRA_BASE_URL="https://jira.mongodb.org"
Expand All @@ -816,6 +818,8 @@ functions:
cat .sbom/vulnerability-report.md
fi
echo
# Fails if the report failed and is not a patch, including release branches:
if [[ "$EVERGREEN_IS_PATCH" != "true" ]]; then
exit $return_code
Expand Down
23 changes: 19 additions & 4 deletions scripts/snyk-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ const { glob } = require('glob');
const { promisify } = require('util');
const execFile = promisify(childProcess.execFile);

async function fileExists(filePath) {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}

async function snykTest(cwd) {
const tmpPath = path.join(os.tmpdir(), 'tempfile-' + Date.now());

let execErr;

try {
if (!(await fileExists(path.join(cwd, `package.json`)))) {
return;
}

console.info(`testing ${cwd} ...`);
await fs.mkdir(path.join(cwd, `node_modules`), { recursive: true });

Expand All @@ -26,7 +39,10 @@ async function snykTest(cwd) {
'--dev',
`--json-file-output=${tmpPath}`,
],
{ cwd }
{
cwd,
maxBuffer: 50 /* MB */ * 1024 * 1024, // default is 1 MB
}
);
} catch (err) {
execErr = err;
Expand All @@ -36,9 +52,8 @@ async function snykTest(cwd) {
console.info(`testing ${cwd} done.`);
return res;
} catch (err) {
console.error(
`testing ${cwd} failed. ${err.message}. Exec error: ${execErr}`
);
console.error(`Snyk failed to create a json report for ${cwd}:`, execErr);
throw new Error(`Testing ${cwd} failed.`);
} finally {
try {
await fs.rm(tmpPath);
Expand Down

0 comments on commit 463afb9

Please sign in to comment.