Adding ability to specify the SHA and Ref for snapshot

This commit is contained in:
Peter Murray
2023-10-31 13:20:48 +00:00
committed by GitHub
parent 645590b347
commit ff23df96ce
5 changed files with 68 additions and 8 deletions
+7 -3
View File
@@ -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}`);
+23 -1
View File
@@ -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) {
@@ -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);
@@ -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;
}