Skip to content

Commit 6de9c73

Browse files
committed
Convert from spdx parser to yaml - boilerplate
1 parent 18b183b commit 6de9c73

17 files changed

+5808
-81651
lines changed

action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
name: 'SPDX to dependency graph action'
2-
description: 'Upload SPDX SBOM files to the dependency graph''s dependency submission API'
1+
name: 'Conda dependency submission action'
2+
description: 'Upload information about your Anaconda environment to the GitHub dependency graph'
33
inputs:
44
token:
55
description: "GitHub Personal Access Token (PAT). Defaults to PAT provided by Actions runner."
66
required: false
77
default: ${{ github.token }}
88
filePath:
9-
description: 'The path to the directory containing the SPDX files to upload. Defaults to Actions working directory.'
9+
description: 'The path to the directory containing the environment files to upload. Defaults to Actions working directory.'
1010
required: false
1111
default: '.'
1212
filePattern:
13-
description: 'The file name pattern for SPDX files to upload'
13+
description: 'The file name pattern for environment files to upload'
1414
required: false
15-
default: '*.spdx.json'
15+
default: '*environment.yaml'
1616
runs:
1717
using: 'node16'
1818
main: 'dist/index.js'

condaParser.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import conda from './condaParser';
2+
3+
test('Gets files', async () => {
4+
var files = conda.searchFiles("test", "environment.yaml");
5+
expect(files.length).toEqual(1);
6+
});
7+
8+
test('Parses manifests', async() => {
9+
var files = conda.searchFiles("test", "environment.yaml");
10+
var manifests = conda.getManifestsFromEnvironmentFiles(files);
11+
expect(manifests.length).toEqual(1);
12+
})

condaParser.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
const fs = require('fs');
4+
const glob = require('glob');
5+
const yaml = require('yaml');
6+
7+
import {
8+
PackageCache,
9+
BuildTarget,
10+
Package,
11+
Snapshot,
12+
Manifest,
13+
submitSnapshot
14+
} from '@github/dependency-submission-toolkit'
15+
import { YAMLMap } from 'yaml';
16+
17+
/**getManifestFromEnvironmentFile(document, fileName) {
18+
core.debug(`getManifestFromEnvironmentFile processing ${fileName}`);
19+
20+
let manifest = new Manifest("Environment", fileName);
21+
22+
23+
/**
24+
let manifest = new Manifest(document.name, fileName);
25+
26+
core.debug(`Processing ${document.packages?.length} packages`);
27+
28+
document.packages?.forEach(pkg => {
29+
let packageName = pkg.name;
30+
let packageVersion = pkg.packageVersion;
31+
let referenceLocator = pkg.externalRefs?.find(ref => ref.referenceCategory === "PACKAGE-MANAGER" && ref.referenceType === "purl")?.referenceLocator;
32+
let genericPurl = `pkg:generic/${packageName}@${packageVersion}`;
33+
// SPDX 2.3 defines a purl field
34+
let purl;
35+
if (pkg.purl != undefined) {
36+
purl = pkg.purl;
37+
} else if (referenceLocator != undefined) {
38+
purl = referenceLocator;
39+
} else {
40+
purl = genericPurl;
41+
}
42+
43+
// Working around weird encoding issues from an SBOM generator
44+
// Find the last instance of %40 and replace it with @
45+
purl = replaceVersionEscape(purl);
46+
47+
let relationships = document.relationships?.find(rel => rel.relatedSpdxElement == pkg.SPDXID && rel.relationshipType == "DEPENDS_ON" && rel.spdxElementId != "SPDXRef-RootPackage");
48+
if (relationships != null && relationships.length > 0) {
49+
manifest.addIndirectDependency(new Package(purl));
50+
} else {
51+
manifest.addDirectDependency(new Package(purl));
52+
}
53+
});
54+
return manifest;
55+
}*/
56+
57+
/***/
58+
59+
export default class CondaParser {
60+
61+
static searchFiles(filePath = "", filePattern = "") {
62+
if (filePath == "") {
63+
let filePath = core.getInput('filePath');
64+
}
65+
if (filePattern == "") {
66+
let filePattern = core.getInput('filePattern');
67+
}
68+
69+
return glob.sync(`${filePath}/${filePattern}`, {});
70+
}
71+
72+
static getManifestsFromEnvironmentFiles(files:string[]) {
73+
core.debug(`Processing ${files.length} files`);
74+
let manifests: any[] = [];
75+
files?.forEach(filePath => {
76+
core.debug(`Processing ${filePath}`);
77+
const contents = fs.readFileSync(filePath, 'utf8')
78+
manifests.push(yaml.parse(contents));
79+
});
80+
return manifests;
81+
}
82+
83+
static getManifestFromYaml(yaml:any) {
84+
85+
}
86+
}

0 commit comments

Comments
 (0)