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

[NODE-1972] NODE_MODULE to NODE_MODULE_INIT #33

Merged
merged 1 commit into from
Jan 14, 2022
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
"dependencies": {
"@octokit/rest": "^18.3.5",
"xml-js": "^1.6.11"
},
"engines": {
"node": ">=10.0.0"
}
}
81 changes: 47 additions & 34 deletions scripts/download-artifact.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
const fs = require('fs');
const https = require('https');
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({auth: process.env.AUTH_TOKEN});
const repo = {
owner: 'Contrast-Security-Inc',
repo: 'node-fn-inspect'
}
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({ auth: process.env.AUTH_TOKEN });
const repo = {
owner: 'Contrast-Security-Inc',
repo: 'node-fn-inspect'
};

const getLatestRunID = async function(args) {
const workflowsRuns = (await octokit.actions.listWorkflowRunsForRepo({
...args,
branch: 'main',
conclusion: 'success'
})).data.workflow_runs;
const latestRun = workflowsRuns.reduce((max, run) => max.run_number > run.run_number ? max : run);
return latestRun.id;
}
const workflowsRuns = (
await octokit.actions.listWorkflowRunsForRepo({
...args,
branch: 'main',
conclusion: 'success'
})
).data.workflow_runs;
const latestRun = workflowsRuns.reduce((max, run) =>
max.run_number > run.run_number ? max : run
);
return latestRun.id;
};

const getLatestArtifactID = async function(args) {
const latestArtifacts = (await octokit.actions.listWorkflowRunArtifacts({
...args,
run_id: await getLatestRunID(args)
})).data.artifacts;
const funcinfoTar = latestArtifacts.find(artifact => artifact.name === 'funcinfo.tgz');
return funcinfoTar.id;
}
const latestArtifacts = (
await octokit.actions.listWorkflowRunArtifacts({
...args,
run_id: await getLatestRunID(args)
})
).data.artifacts;
const funcinfoTar = latestArtifacts.find(
(artifact) => artifact.name === 'funcinfo.tgz'
);
return funcinfoTar.id;
};

const downloadLatestArtifact = async function(args) {
const latestArtifactURL = (await octokit.actions.downloadArtifact({
...args,
artifact_id: await getLatestArtifactID(args),
archive_format: 'zip'
})).url;
const artifactFile = fs.createWriteStream("funcinfo.tgz.zip");
https.get(latestArtifactURL, function(res) {
res.pipe(artifactFile);
});
}
const latestArtifactURL = (
await octokit.actions.downloadArtifact({
...args,
artifact_id: await getLatestArtifactID(args),
archive_format: 'zip'
})
).url;
const artifactFile = fs.createWriteStream('funcinfo.tgz.zip');
https.get(latestArtifactURL, function(res) {
res.pipe(artifactFile);
});
};

downloadLatestArtifact(repo).then(() => {
downloadLatestArtifact(repo)
.then(() => {
console.log('Successfully downloaded latest artifact');
}).catch((err) => {
})
.catch((err) => {
console.log(`Failed to download latest artifact\n${err.stack}`);
// eslint-disable-next-line no-process-exit
process.exit(-1);
})
});
4 changes: 3 additions & 1 deletion src/code-events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "getNext", GetNext);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
NODE_MODULE_INIT() {
Initialize(exports);
}

} // namespace codeevents
4 changes: 3 additions & 1 deletion src/funcinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "funcinfo", Method);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
NODE_MODULE_INIT() {
Initialize(exports);
}

}