Skip to content

Commit

Permalink
Adding ability to specify the SHA and Ref for snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-murray authored Oct 31, 2023
1 parent 645590b commit ff23df9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
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 tha tthe 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'),
targetSHA: core.getInput('snapshot-sha'),
targetRef: 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.

10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
includeManifestFile: core.getBooleanInput('snapshot-include-file-name'),
manifestFile: core.getInput('snapshot-dependency-file-name'),
targetSHA: core.getInput('snapshot-sha'),
targetRef: 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;

This comment has been minimized.

Copy link
@jmservera

jmservera Oct 31, 2023

can you rename them to targetSHA and targetRef to match the names in index.ts (lines 18 and 19)? Or the other way around, I think that as the names do not match it is not replacing the values.

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;
}

0 comments on commit ff23df9

Please sign in to comment.