Skip to content

Commit

Permalink
fix dependencies check
Browse files Browse the repository at this point in the history
  • Loading branch information
whitelisab committed Aug 7, 2024
1 parent 07aa636 commit d78ee5d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/app-review-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const handleValidationSuccess = async (github, context, prNumber) => {

const handleValidationWarnings = async (github, context, prNumber, warnings) => {
const commentBody =
'Please acknowledge the following warnings: ' +
'Please acknowledge the following warnings:\n' +
Object.values(warnings)
.map((warning) => `- [ ] ${warning}`)
.join('\n');
Expand Down
79 changes: 35 additions & 44 deletions .github/workflows/new-app-review/validators/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,46 @@ const { spawn } = require('child_process');

module.exports = {
validate: async ({ github, context, core }, newAppDir, files) => {
let warning = '';
let result = true;
let message = 'Dependency check finished';
return new Promise((resolve, reject) => {
const command = `npm outdated --json`;
const child = spawn(command, { shell: true, cwd: newAppDir });

try {
const stdout = await new Promise((resolve, reject) => {
const command = `npm outdated --json`;
const child = spawn(command, { shell: true, cwd: newAppDir });
let output = '';
let errorOutput = '';

let output = '';
let errorOutput = '';

child.stdout.on('data', (data) => {
output += data.toString();
});
child.stdout.on('data', (data) => {
output += data.toString();
});

child.stderr.on('data', (data) => {
errorOutput += data.toString();
});
child.stderr.on('data', (data) => {
errorOutput += data.toString();
});

child.on('close', (code) => {
if (code !== 0) {
console.log({ output, errorOutput });
reject(new Error(`Child process exited with code ${code}`));
} else if (errorOutput) {
reject(new Error(errorOutput));
} else {
resolve(output);
child.on('close', (code) => {
if (code === 0) {
resolve({
result: true,
message: 'Dependency check finished',
});
} else if (output) {
let warning = '';
const outdatedDependencies = JSON.parse(output);
if (Object.keys(outdatedDependencies).length > 0) {
warning += 'The following dependencies are outdated:\n';
warning += JSON.stringify(outdatedDependencies, null, 2);
}
});
resolve({
result: true,
warning,
message: 'Dependency check finished',
});
} else {
resolve({
result: false,
message: 'Failed to check for outdated dependencies',
});
}
});

const outdatedDependencies = JSON.parse(stdout);

if (Object.keys(outdatedDependencies).length > 0) {
warning += 'The following dependencies are outdated:\n';
warning += JSON.stringify(outdatedDependencies, null, 2);
console.log(warning);
}
} catch (error) {
message = 'Failed to check for outdated dependencies';
console.error(`exec error: ${error.message}`);
result = false;
}

return {
result,
message,
warning,
};
});
},
};

0 comments on commit d78ee5d

Please sign in to comment.