Stub component detection download and execution

This commit is contained in:
Justin Hutchings
2023-01-21 21:56:51 +00:00
parent 2e4172a352
commit e2c79b684b
9 changed files with 2956 additions and 3047 deletions
BIN
View File
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
import {downloadLatestRelease, runComponentDetection} from './componentDetection';
test('Downloads CLI', async () => {
downloadLatestRelease();
});
test('Runs CLI', async () => {
runComponentDetection('./test');
});
+49 -33
View File
@@ -1,43 +1,59 @@
import * as github from '@actions/github'
import * as core from '@actions/core'
import fetch from 'node-fetch'
import fetch from 'cross-fetch'
import tar from 'tar'
import fs from 'fs'
import dotenv from 'dotenv'
dotenv.config();
// Get the latest release from the component-detection repo, download the tarball, and extract it
export async function downloadLatestRelease() {
const githubToken = core.getInput('token') || (await core.getIDToken());
const octokit = github.getOctokit(githubToken);
const owner = "microsoft";
const repo = "component-detection";
import * as exec from '@actions/exec';
try {
octokit.rest.repos.getLatestRelease({
owner, repo
}).then((response) => {
fetch(response.data.assets[0].browser_download_url).then((response) => {
response.json().then((data) => {
// Write the tarball to a file
fs.writeFile('component-detection.tar.gz', data, (err: any) => {
if (err) {
core.error(err);
}
});
// Extract the tarball
tar.x({
file: 'component-detection.tar.gz',
C: './'
}).then(() => {
core.info('Extracted tarball');
}
})
})
});
} catch (error: any) {
core.error(error);
}
export const componentDetectionPath = './component-detection';
// Get the latest release from the component-detection repo, download the tarball, and extract it
export async function downloadLatestRelease() {
try {
const downloadURL = await getLatestReleaseURL();
const blob = await (await fetch(new URL(downloadURL))).blob();
const arrayBuffer = await blob.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
// Write the blob to a file
await fs.writeFile(componentDetectionPath, buffer, {mode: 0o777, flag: 'w'},
(err: any) => {
if (err) {
core.error(err);
}
});
} catch (error: any) {
core.error(error);
}
}
// Run the component-detection CLI on the path specified
export async function runComponentDetection(path: string) {
try {
await exec.exec(`${componentDetectionPath} ${path}`);
} catch (error: any) {
core.error(error);
}
}
async function getLatestReleaseURL(): Promise<string> {
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN2 || "";
const octokit = github.getOctokit(githubToken);
const owner = "microsoft";
const repo = "component-detection";
const latestRelease = await octokit.rest.repos.getLatestRelease({
owner, repo
});
var downloadURL: string = "";
latestRelease.data.assets.forEach((asset: any) => {
if (asset.name === "component-detection-linux-x64") {
downloadURL = asset.browser_download_url;
}
});
return downloadURL;
}
-139
View File
@@ -1,139 +0,0 @@
import conda from './condaParser';
test('Gets files', async () => {
var files = conda.searchFiles("test", "environment.yaml");
expect(files.length).toEqual(1);
});
function roundTripJSON(obj: any): object {
return JSON.parse(JSON.stringify(obj))
}
test('Parses manifests', async () => {
var files = conda.searchFiles("test", "environment.yaml");
var manifests = conda.getManifestsFromEnvironmentFiles(files);
expect(manifests.length).toEqual(1);
expect(roundTripJSON(manifests[0])).toEqual(
{
"resolved": {
"pkg:conda/python@3.8": {
"package_url": "pkg:conda/python@3.8",
"relationship": "direct",
"dependencies": []
},
"pkg:conda/pytorch@1.10": {
"package_url": "pkg:conda/pytorch@1.10",
"relationship": "direct",
"dependencies": []
},
"pkg:conda/torchvision": {
"package_url": "pkg:conda/torchvision",
"relationship": "direct",
"dependencies": []
},
"pkg:conda/cudatoolkit@11.0": {
"package_url": "pkg:conda/cudatoolkit@11.0",
"relationship": "direct",
"dependencies": []
},
"pkg:conda/pip": {
"package_url": "pkg:conda/pip",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/pytorch-lightning@1.5.2": {
"package_url": "pkg:pypi/pytorch-lightning@1.5.2",
"relationship": "direct",
"dependencies": []
}, "pkg:pypi/einops@0.3.2": {
"package_url": "pkg:pypi/einops@0.3.2",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/kornia@0.6.1": {
"package_url": "pkg:pypi/kornia@0.6.1",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/opencv-python@4.5.4.58": {
"package_url": "pkg:pypi/opencv-python@4.5.4.58",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/matplotlib@3.5.0": {
"package_url": "pkg:pypi/matplotlib@3.5.0",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/imageio@2.10.4": {
"package_url": "pkg:pypi/imageio@2.10.4",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/imageio-ffmpeg@0.4.5": {
"package_url": "pkg:pypi/imageio-ffmpeg@0.4.5",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/torch-optimizer@0.3.0": {
"package_url": "pkg:pypi/torch-optimizer@0.3.0",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/setuptools@58.2.0": {
"package_url": "pkg:pypi/setuptools@58.2.0",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/pymcubes@0.1.2": {
"package_url": "pkg:pypi/pymcubes@0.1.2",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/pycollada@0.7.1": {
"package_url": "pkg:pypi/pycollada@0.7.1",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/trimesh@3.9.1": {
"package_url": "pkg:pypi/trimesh@3.9.1",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/pyglet@1.5.10": {
"package_url": "pkg:pypi/pyglet@1.5.10"
, "relationship": "direct",
"dependencies": []
},
"pkg:pypi/networkx@2.5": {
"package_url": "pkg:pypi/networkx@2.5",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/plyfile@0.7.2": {
"package_url": "pkg:pypi/plyfile@0.7.2",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/open3d@0.13.0": {
"package_url": "pkg:pypi/open3d@0.13.0",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/configargparse@1.5.3": {
"package_url": "pkg:pypi/configargparse@1.5.3",
"relationship": "direct",
"dependencies": []
},
"pkg:pypi/ninja": {
"package_url": "pkg:pypi/ninja",
"relationship": "direct",
"dependencies": []
}
},
"name": "test",
"file": {
"source_location": "test/environment.yaml"
}
})
});
+1
View File
@@ -0,0 +1 @@
export declare function downloadLatestRelease(): Promise<void>;
Generated Vendored
+2834 -2746
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+60 -127
View File
@@ -12,8 +12,9 @@
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@github/dependency-submission-toolkit": "^1.2.7",
"cross-fetch": "^3.1.5",
"dotenv": "^16.0.3",
"fs": "^0.0.1-security",
"node-fetch": "^3.3.0",
"tar": "^6.1.13",
"yaml": "^2.2.1"
},
@@ -1884,6 +1885,33 @@
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
"dev": true
},
"node_modules/cross-fetch": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
"integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==",
"dependencies": {
"node-fetch": "2.6.7"
}
},
"node_modules/cross-fetch/node_modules/node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -1898,14 +1926,6 @@
"node": ">= 8"
}
},
"node_modules/data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
"engines": {
"node": ">= 12"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@@ -1979,6 +1999,14 @@
"node": ">=6.0.0"
}
},
"node_modules/dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
"engines": {
"node": ">=12"
}
},
"node_modules/electron-to-chromium": {
"version": "1.4.284",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz",
@@ -2367,28 +2395,6 @@
"bser": "2.1.1"
}
},
"node_modules/fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "paypal",
"url": "https://paypal.me/jimmywarting"
}
],
"dependencies": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
},
"engines": {
"node": "^12.20 || >= 14.13"
}
},
"node_modules/file-entry-cache": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
@@ -2445,17 +2451,6 @@
"integrity": "sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==",
"dev": true
},
"node_modules/formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"dependencies": {
"fetch-blob": "^3.1.2"
},
"engines": {
"node": ">=12.20.0"
}
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
@@ -3752,41 +3747,6 @@
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
"dev": true
},
"node_modules/node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "github",
"url": "https://paypal.me/jimmywarting"
}
],
"engines": {
"node": ">=10.5.0"
}
},
"node_modules/node-fetch": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.0.tgz",
"integrity": "sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==",
"dependencies": {
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-fetch"
}
},
"node_modules/node-int64": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
@@ -4719,14 +4679,6 @@
"makeerror": "1.0.12"
}
},
"node_modules/web-streams-polyfill": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==",
"engines": {
"node": ">= 8"
}
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@@ -6372,6 +6324,24 @@
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
"dev": true
},
"cross-fetch": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
"integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==",
"requires": {
"node-fetch": "2.6.7"
},
"dependencies": {
"node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"requires": {
"whatwg-url": "^5.0.0"
}
}
}
},
"cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -6383,11 +6353,6 @@
"which": "^2.0.1"
}
},
"data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A=="
},
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@@ -6441,6 +6406,11 @@
"esutils": "^2.0.2"
}
},
"dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
},
"electron-to-chromium": {
"version": "1.4.284",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz",
@@ -6730,15 +6700,6 @@
"bser": "2.1.1"
}
},
"fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"requires": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
}
},
"file-entry-cache": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
@@ -6783,14 +6744,6 @@
"integrity": "sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==",
"dev": true
},
"formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"requires": {
"fetch-blob": "^3.1.2"
}
},
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
@@ -7770,21 +7723,6 @@
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
"dev": true
},
"node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="
},
"node-fetch": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.0.tgz",
"integrity": "sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==",
"requires": {
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
}
},
"node-int64": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
@@ -8429,11 +8367,6 @@
"makeerror": "1.0.12"
}
},
"web-streams-polyfill": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q=="
},
"webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+2 -1
View File
@@ -28,8 +28,9 @@
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@github/dependency-submission-toolkit": "^1.2.7",
"cross-fetch": "^3.1.5",
"dotenv": "^16.0.3",
"fs": "^0.0.1-security",
"node-fetch": "^3.3.0",
"tar": "^6.1.13",
"yaml": "^2.2.1"
},