Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit context #57

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ inputs:
type: string
default: ${{ github.token }}

snapshot-sha:
description: The SHA that the results will be linked to in the dependency snapshot
type: string
required: false
default: ''

snapshot-ref:
description: The ref that the results will be linked to in the dependency snapshot
type: string
required: false
default: ''


runs:
using: node16
main: dist/index.js
27 changes: 24 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ function run() {
settingsFile: core.getInput('settings-file'),
mavenArgs: core.getInput('maven-args') || '',
};
const includeFilename = core.getBooleanInput('snapshot-include-file-name');
const manifestFilename = core.getInput('snapshot-dependency-file-name');
snapshot = yield (0, snapshot_generator_1.generateSnapshot)(directory, mavenConfig, { includeManifestFile: includeFilename, manifestFile: manifestFilename });
const snapshotConfig = {
includeManifestFile: core.getBooleanInput('snapshot-include-file-name'),
manifestFile: core.getInput('snapshot-dependency-file-name'),
sha: core.getInput('snapshot-sha'),
ref: core.getInput('snapshot-ref'),
};
snapshot = yield (0, snapshot_generator_1.generateSnapshot)(directory, mavenConfig, snapshotConfig);
}
catch (err) {
core.error(err);
Expand Down Expand Up @@ -491,6 +495,14 @@ function generateSnapshot(directory, mvnConfig, snapshotConfig) {
}
const snapshot = new dependency_submission_toolkit_1.Snapshot(getDetector(), snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.context, snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.job);
snapshot.addManifest(manifest);
const specifiedRef = getNonEmtptyValue(snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.ref);
if (specifiedRef) {
snapshot.ref = specifiedRef;
}
const specifiedSha = getNonEmtptyValue(snapshot === null || snapshot === void 0 ? void 0 : snapshot.sha);
if (specifiedSha) {
snapshot.sha = specifiedSha;
}
return snapshot;
}
catch (err) {
Expand Down Expand Up @@ -587,6 +599,15 @@ function getRepositoryRelativePath(file) {
core.debug(`Snapshot relative file = ${result}`);
return result;
}
function getNonEmtptyValue(str) {
if (str) {
const trimmed = str.trim();
if (trimmed.length > 0) {
return trimmed;
}
}
return undefined;
}
//# sourceMappingURL=snapshot-generator.js.map

/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/executable/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ process.env['GITHUB_API_URL'] = opts.githubApiUrl;

// The above injection of environment variables is required before the submission APIs are imported
import { Snapshot, submitSnapshot } from '@github/dependency-submission-toolkit';
import { generateSnapshot } from '../snapshot-generator';
import { SnapshotConfig, generateSnapshot } from '../snapshot-generator';

async function execute() {
let snapshot: Snapshot | undefined;
Expand Down Expand Up @@ -60,7 +60,7 @@ async function execute() {
mavenArgs: opts.mavenArgs
};

const snapshotConfig = {
const snapshotConfig: SnapshotConfig = {
context,
job,
}
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import {Snapshot, submitSnapshot} from '@github/dependency-submission-toolkit';
import { generateSnapshot } from './snapshot-generator';
import { SnapshotConfig, generateSnapshot } from './snapshot-generator';

async function run() {
let snapshot: Snapshot | undefined;
Expand All @@ -12,10 +12,14 @@ async function run() {
settingsFile: core.getInput('settings-file'),
mavenArgs: core.getInput('maven-args') || '',
}
const includeFilename = core.getBooleanInput('snapshot-include-file-name');
const manifestFilename = core.getInput('snapshot-dependency-file-name');
const snapshotConfig: SnapshotConfig = {
includeManifestFile: core.getBooleanInput('snapshot-include-file-name'),
manifestFile: core.getInput('snapshot-dependency-file-name'),
sha: core.getInput('snapshot-sha'),
ref: core.getInput('snapshot-ref'),
}

snapshot = await generateSnapshot(directory, mavenConfig, {includeManifestFile: includeFilename, manifestFile: manifestFilename});
snapshot = await generateSnapshot(directory, mavenConfig, snapshotConfig);
} catch (err: any) {
core.error(err);
core.setFailed(`Failed to generate a dependency snapshot, check logs for more details, ${err}`);
Expand Down
24 changes: 23 additions & 1 deletion src/snapshot-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export type SnapshotConfig = {
includeManifestFile?: boolean;
manifestFile?: string;
context?: any;
job?: any
job?: any;
sha?: any;
ref?: any;
};

export async function generateSnapshot(directory: string, mvnConfig?: MavenConfiguration, snapshotConfig?: SnapshotConfig) {
Expand All @@ -46,6 +48,16 @@ export async function generateSnapshot(directory: string, mvnConfig?: MavenConfi
const snapshot = new Snapshot(getDetector(), snapshotConfig?.context, snapshotConfig?.job);
snapshot.addManifest(manifest);

const specifiedRef = getNonEmtptyValue(snapshotConfig?.ref);
if (specifiedRef) {
snapshot.ref = specifiedRef;
}

const specifiedSha = getNonEmtptyValue(snapshot?.sha);
if (specifiedSha) {
snapshot.sha = specifiedSha;
}

return snapshot;
} catch (err: any) {
core.error(err);
Expand Down Expand Up @@ -149,4 +161,14 @@ function getRepositoryRelativePath(file) {

core.debug(`Snapshot relative file = ${result}`);
return result;
}

function getNonEmtptyValue(str?: string) {
if (str) {
const trimmed = str.trim();
if (trimmed.length > 0) {
return trimmed;
}
}
return undefined;
}
Loading