-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Contrast-Security-Inc/NODE-1972
[NODE-1972] NODE_MODULE to NODE_MODULE_INIT
- Loading branch information
Showing
4 changed files
with
56 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,5 +64,8 @@ | |
"dependencies": { | ||
"@octokit/rest": "^18.3.5", | ||
"xml-js": "^1.6.11" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters