commit files generated during build

This commit is contained in:
E. Lynette Rayle
2025-05-28 20:45:18 +00:00
parent 50fef6cb9b
commit 4d284b90be
3 changed files with 83 additions and 43 deletions
Generated Vendored
+46 -5
View File
@@ -94,18 +94,59 @@ function main() {
}
manifest.addIndirectDependency(dep);
});
const snapshot = new dependency_submission_toolkit_1.Snapshot({
name: 'actions/go-dependency-submission',
url: 'https://github.com/actions/go-dependency-submission',
version: '0.0.1'
}, github.context, {
let snapshotDetector;
const detectorName = core.getInput('detector-name');
const detectorUrl = core.getInput('detector-url');
const detectorVersion = core.getInput('detector-version');
if (detectorName === '' && detectorUrl === '' && detectorVersion === '') {
// use defaults if none are specified
snapshotDetector = {
name: 'actions/go-dependency-submission',
url: 'https://github.com/actions/go-dependency-submission',
version: '0.0.1'
};
}
else if (detectorName === '' || detectorUrl === '' || detectorVersion === '') {
// if any of detectorName, detectorUrl, or detectorVersion have value, then they are all required
throw new Error("Invalid input: if any of 'detector-name', 'detector-url', or 'detector-version' have value, then thay are all required.");
}
else {
// use inputs since all are specified
snapshotDetector = {
name: detectorName,
url: core.getInput('detector-url', { required: true }),
version: core.getInput('detector-version', { required: true })
};
}
const snapshot = new dependency_submission_toolkit_1.Snapshot(snapshotDetector, github.context, {
correlator: `${github.context.job}-${goBuildTarget}`,
id: github.context.runId.toString()
});
snapshot.addManifest(manifest);
snapshot.sha = core.getInput('snapshot-sha') && getShaFromContext();
snapshot.ref = core.getInput('snapshot-ref') && github.context.ref;
(0, dependency_submission_toolkit_1.submitSnapshot)(snapshot);
});
}
function getShaFromContext() {
const context = github.context;
const pullRequestEvents = [
'pull_request',
'pull_request_comment',
'pull_request_review',
'pull_request_review_comment'
// Note that pull_request_target is omitted here.
// That event runs in the context of the base commit of the PR,
// so the snapshot should not be associated with the head commit.
];
if (pullRequestEvents.includes(context.eventName)) {
const pr = context.payload.pull_request;
return pr.head.sha;
}
else {
return context.sha;
}
}
main();
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+36 -37
View File
@@ -7,7 +7,7 @@ import {
Manifest,
submitSnapshot
} from '@github/dependency-submission-toolkit'
import type {PullRequestEvent} from '@octokit/webhooks-types'
import type { PullRequestEvent } from '@octokit/webhooks-types'
import {
processGoGraph,
@@ -79,16 +79,15 @@ async function main () {
})
type SnapshotDetector = {
name: string;
url: string;
version: string;
};
let snapshotDetector: SnapshotDetector;
name: string
url: string
version: string
}
let snapshotDetector: SnapshotDetector
const detectorName = core.getInput('detector-name');
const detectorUrl = core.getInput('detector-url');
const detectorVersion = core.getInput('detector-version');
const detectorName = core.getInput('detector-name')
const detectorUrl = core.getInput('detector-url')
const detectorVersion = core.getInput('detector-version')
if (detectorName === '' && detectorUrl === '' && detectorVersion === '') {
// use defaults if none are specified
@@ -97,11 +96,15 @@ async function main () {
url: 'https://github.com/actions/go-dependency-submission',
version: '0.0.1'
}
} else if (detectorName === '' || detectorUrl === '' || detectorVersion === '') {
} else if (
detectorName === '' ||
detectorUrl === '' ||
detectorVersion === ''
) {
// if any of detectorName, detectorUrl, or detectorVersion have value, then they are all required
throw new Error(
"Invalid input: if any of 'detector-name', 'detector-url', or 'detector-version' have value, then thay are all required."
);
)
} else {
// use inputs since all are specified
snapshotDetector = {
@@ -111,14 +114,10 @@ async function main () {
}
}
const snapshot = new Snapshot(
snapshotDetector,
github.context,
{
correlator: `${github.context.job}-${goBuildTarget}`,
id: github.context.runId.toString()
}
)
const snapshot = new Snapshot(snapshotDetector, github.context, {
correlator: `${github.context.job}-${goBuildTarget}`,
id: github.context.runId.toString()
})
snapshot.addManifest(manifest)
snapshot.sha = core.getInput('snapshot-sha') && getShaFromContext()
snapshot.ref = core.getInput('snapshot-ref') && github.context.ref
@@ -126,23 +125,23 @@ async function main () {
submitSnapshot(snapshot)
}
function getShaFromContext(): string {
const context = github.context
const pullRequestEvents = [
'pull_request',
'pull_request_comment',
'pull_request_review',
'pull_request_review_comment'
// Note that pull_request_target is omitted here.
// That event runs in the context of the base commit of the PR,
// so the snapshot should not be associated with the head commit.
]
if (pullRequestEvents.includes(context.eventName)) {
const pr = (context.payload as PullRequestEvent).pull_request
return pr.head.sha
} else {
return context.sha
}
function getShaFromContext (): string {
const context = github.context
const pullRequestEvents = [
'pull_request',
'pull_request_comment',
'pull_request_review',
'pull_request_review_comment'
// Note that pull_request_target is omitted here.
// That event runs in the context of the base commit of the PR,
// so the snapshot should not be associated with the head commit.
]
if (pullRequestEvents.includes(context.eventName)) {
const pr = (context.payload as PullRequestEvent).pull_request
return pr.head.sha
} else {
return context.sha
}
}
main()