Use go.mod path instead of containing dir

This commit is contained in:
Lane Seppala
2022-06-28 11:16:56 -06:00
parent 931fb377fd
commit d5d64a591f
3 changed files with 14 additions and 15 deletions
+11 -11
View File
@@ -75,9 +75,9 @@ function main() {
const directDeps = yield (0, process_1.processGoDirectDependencies)(goModDir, goBuildTarget); const directDeps = yield (0, process_1.processGoDirectDependencies)(goModDir, goBuildTarget);
const indirectDeps = yield (0, process_1.processGoIndirectDependencies)(goModDir, goBuildTarget); const indirectDeps = yield (0, process_1.processGoIndirectDependencies)(goModDir, goBuildTarget);
const packageCache = yield (0, process_1.processGoGraph)(goModDir, directDeps, indirectDeps); const packageCache = yield (0, process_1.processGoGraph)(goModDir, directDeps, indirectDeps);
// if using the pseudotargets "all" or "./...", use the goModDir as filepath // if using the pseudotargets "all" or "./...", use the path to go.mod as filepath
const filepath = goBuildTarget === 'all' || goBuildTarget === './...' const filepath = goBuildTarget === 'all' || goBuildTarget === './...'
? goModDir ? goModPath
: path_1.default.join(goModDir, goBuildTarget); : path_1.default.join(goModDir, goBuildTarget);
const manifest = new dependency_submission_toolkit_1.Manifest(goBuildTarget, filepath); const manifest = new dependency_submission_toolkit_1.Manifest(goBuildTarget, filepath);
directDeps.forEach((pkgUrl) => { directDeps.forEach((pkgUrl) => {
@@ -3491,7 +3491,7 @@ class Dependency {
this.scope = scope; this.scope = scope;
} }
/** /**
* toJSON is a custom JSON-serializer. It will be called when JSON.stringfy() * toJSON is a custom JSON-serializer. It will be called when JSON.stringify()
* is called with this class or any object containing this class. * is called with this class or any object containing this class.
* *
* @returns {object} with keys package_url, relationship, scope, and * @returns {object} with keys package_url, relationship, scope, and
@@ -3519,14 +3519,14 @@ class Manifest {
} }
/** /**
* addIndirectDependency adds a package as an indirect dependency to the * addIndirectDependency adds a package as an indirect dependency to the
* manifest. Direct dependencies take precendence over indirect dependencies * manifest. Direct dependencies take precedence over indirect dependencies
* if a package is added as both. * if a package is added as both.
* *
* @param {Package} pkg * @param {Package} pkg
* @param {DependencyScope} scope * @param {DependencyScope} scope
*/ */
addDirectDependency(pkg, scope) { addDirectDependency(pkg, scope) {
// will overwrite any previous indirect assigments // will overwrite any previous indirect assignments
this.resolved[pkg.packageID()] = new Dependency(pkg, 'direct', scope); this.resolved[pkg.packageID()] = new Dependency(pkg, 'direct', scope);
} }
/** /**
@@ -3540,7 +3540,7 @@ class Manifest {
addIndirectDependency(pkg, scope) { addIndirectDependency(pkg, scope) {
var _a; var _a;
var _b, _c; var _b, _c;
// nullish assigment to keep any previous assignments, including direct assigments // nullish assignment to keep any previous assignments, including direct assignments
(_a = (_b = this.resolved)[_c = pkg.packageID()]) !== null && _a !== void 0 ? _a : (_b[_c] = new Dependency(pkg, 'indirect', scope)); (_a = (_b = this.resolved)[_c = pkg.packageID()]) !== null && _a !== void 0 ? _a : (_b[_c] = new Dependency(pkg, 'indirect', scope));
} }
hasDependency(pkg) { hasDependency(pkg) {
@@ -3632,7 +3632,7 @@ class PackageCache {
/** /**
* 'cache.package()' will be the most commonly used method of PackageCache. * 'cache.package()' will be the most commonly used method of PackageCache.
* package(identifier) will create and add a new Package to the PackageCache if no * package(identifier) will create and add a new Package to the PackageCache if no
* Packaging with a matching identifer exists in PackageCache, or return an existing * Packaging with a matching identifier exists in PackageCache, or return an existing
* Package if a match is found. The mutation in this case is expected; do not * Package if a match is found. The mutation in this case is expected; do not
* use package(identifier) to determine if a package is already added. * use package(identifier) to determine if a package is already added.
* Instead, use hasPackage or lookupPackage. * Instead, use hasPackage or lookupPackage.
@@ -3884,11 +3884,11 @@ function jobFromContext(context) {
} }
exports.jobFromContext = jobFromContext; exports.jobFromContext = jobFromContext;
/** /**
* Snapshot is the top-level container for Dependency Submisison * Snapshot is the top-level container for Dependency Submission
*/ */
class Snapshot { class Snapshot {
/** /**
* All construor parameters of a Snapshot are optional, but can be specified for specific overrides * All constructor parameters of a Snapshot are optional, but can be specified for specific overrides
* *
* @param {Detector} detector * @param {Detector} detector
* @param {Context} context * @param {Context} context
@@ -3935,7 +3935,7 @@ function submitSnapshot(snapshot, context = github.context) {
core.notice('Submitting snapshot...'); core.notice('Submitting snapshot...');
core.notice(snapshot.prettyJSON()); core.notice(snapshot.prettyJSON());
const repo = context.repo; const repo = context.repo;
const githubToken = core.getInput('token') || core.getIDToken; const githubToken = core.getInput('token') || (yield core.getIDToken());
const octokit = new rest_1.Octokit({ const octokit = new rest_1.Octokit({
auth: githubToken auth: githubToken
}); });
@@ -3948,7 +3948,7 @@ function submitSnapshot(snapshot, context = github.context) {
repo: repo.repo, repo: repo.repo,
data: JSON.stringify(snapshot) data: JSON.stringify(snapshot)
}); });
core.notice('Snapshot sucessfully created at ' + response.data.created_at.toString()); core.notice('Snapshot successfully created at ' + response.data.created_at.toString());
} }
catch (error) { catch (error) {
if (error instanceof request_error_1.RequestError) { if (error instanceof request_error_1.RequestError) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -3
View File
@@ -1,6 +1,5 @@
import path from 'path' import path from 'path'
import fs from 'fs' import fs from 'fs'
import * as core from '@actions/core' import * as core from '@actions/core'
import * as github from '@actions/github' import * as github from '@actions/github'
import { import {
@@ -51,10 +50,10 @@ async function main () {
goBuildTarget goBuildTarget
) )
const packageCache = await processGoGraph(goModDir, directDeps, indirectDeps) const packageCache = await processGoGraph(goModDir, directDeps, indirectDeps)
// if using the pseudotargets "all" or "./...", use the goModDir as filepath // if using the pseudotargets "all" or "./...", use the path to go.mod as filepath
const filepath = const filepath =
goBuildTarget === 'all' || goBuildTarget === './...' goBuildTarget === 'all' || goBuildTarget === './...'
? goModDir ? goModPath
: path.join(goModDir, goBuildTarget) : path.join(goModDir, goBuildTarget)
const manifest = new Manifest(goBuildTarget, filepath) const manifest = new Manifest(goBuildTarget, filepath)