SBOM: Ensure 'java-version' is persisted to post-run phase
This commit is contained in:
committed by
Fabio Niephaus
parent
271a696e78
commit
3ca6fc3a8a
29
dist/cleanup/index.js
generated
vendored
29
dist/cleanup/index.js
generated
vendored
@@ -78738,36 +78738,37 @@ const utils_1 = __nccwpck_require__(1798);
|
||||
const INPUT_NI_SBOM = 'native-image-enable-sbom';
|
||||
const SBOM_FILE_SUFFIX = '.sbom.json';
|
||||
const MIN_JAVA_VERSION = '24.0.0';
|
||||
let javaVersionOrLatestEA = null;
|
||||
function setUpSBOMSupport(javaVersionOrDev, distribution) {
|
||||
const javaVersionKey = 'javaVersionKey';
|
||||
function setUpSBOMSupport(javaVersion, distribution) {
|
||||
if (!isFeatureEnabled()) {
|
||||
return;
|
||||
}
|
||||
validateJavaVersionAndDistribution(javaVersionOrDev, distribution);
|
||||
javaVersionOrLatestEA = javaVersionOrDev;
|
||||
(0, utils_1.setNativeImageOption)(javaVersionOrLatestEA, '--enable-sbom=export');
|
||||
validateJavaVersionAndDistribution(javaVersion, distribution);
|
||||
core.saveState(javaVersionKey, javaVersion);
|
||||
(0, utils_1.setNativeImageOption)(javaVersion, '--enable-sbom=export');
|
||||
core.info('Enabled SBOM generation for Native Image build');
|
||||
}
|
||||
function validateJavaVersionAndDistribution(javaVersionOrDev, distribution) {
|
||||
function validateJavaVersionAndDistribution(javaVersion, distribution) {
|
||||
if (distribution !== c.DISTRIBUTION_GRAALVM) {
|
||||
throw new Error(`The '${INPUT_NI_SBOM}' option is only supported for Oracle GraalVM (distribution '${c.DISTRIBUTION_GRAALVM}'), but found distribution '${distribution}'.`);
|
||||
}
|
||||
if (javaVersionOrDev === 'dev') {
|
||||
if (javaVersion === 'dev') {
|
||||
throw new Error(`The '${INPUT_NI_SBOM}' option is not supported for java-version 'dev'.`);
|
||||
}
|
||||
if (javaVersionOrDev === 'latest-ea') {
|
||||
if (javaVersion === 'latest-ea') {
|
||||
return;
|
||||
}
|
||||
const coercedJavaVersion = semver.coerce(javaVersionOrDev);
|
||||
const coercedJavaVersion = semver.coerce(javaVersion);
|
||||
if (!coercedJavaVersion || semver.gt(MIN_JAVA_VERSION, coercedJavaVersion)) {
|
||||
throw new Error(`The '${INPUT_NI_SBOM}' option is only supported for GraalVM for JDK ${MIN_JAVA_VERSION} or later, but found java-version '${javaVersionOrDev}'.`);
|
||||
throw new Error(`The '${INPUT_NI_SBOM}' option is only supported for GraalVM for JDK ${MIN_JAVA_VERSION} or later, but found java-version '${javaVersion}'.`);
|
||||
}
|
||||
}
|
||||
async function processSBOM() {
|
||||
if (!isFeatureEnabled()) {
|
||||
return;
|
||||
}
|
||||
if (javaVersionOrLatestEA === null) {
|
||||
const javaVersion = core.getState(javaVersionKey);
|
||||
if (!javaVersion) {
|
||||
throw new Error('setUpSBOMSupport must be called before processSBOM');
|
||||
}
|
||||
const sbomPath = await findSBOMFilePath();
|
||||
@@ -78776,7 +78777,7 @@ async function processSBOM() {
|
||||
const sbomData = parseSBOM(sbomContent);
|
||||
const components = mapToComponentsWithDependencies(sbomData);
|
||||
printSBOMContent(components);
|
||||
const snapshot = convertSBOMToSnapshot(sbomPath, components);
|
||||
const snapshot = convertSBOMToSnapshot(javaVersion, sbomPath, components);
|
||||
await submitDependencySnapshot(snapshot);
|
||||
}
|
||||
catch (error) {
|
||||
@@ -78833,7 +78834,7 @@ function printSBOMContent(components) {
|
||||
}
|
||||
core.info('==================');
|
||||
}
|
||||
function convertSBOMToSnapshot(sbomPath, components) {
|
||||
function convertSBOMToSnapshot(javaVersion, sbomPath, components) {
|
||||
const context = github.context;
|
||||
const sbomFileName = (0, path_1.basename)(sbomPath);
|
||||
if (!sbomFileName.endsWith(SBOM_FILE_SUFFIX)) {
|
||||
@@ -78850,7 +78851,7 @@ function convertSBOMToSnapshot(sbomPath, components) {
|
||||
},
|
||||
detector: {
|
||||
name: 'Oracle GraalVM',
|
||||
version: javaVersionOrLatestEA ?? '',
|
||||
version: javaVersion,
|
||||
url: 'https://www.graalvm.org/'
|
||||
},
|
||||
scanned: new Date().toISOString(),
|
||||
|
||||
Reference in New Issue
Block a user