@@ -2,10 +2,10 @@ import * as c from '../constants'
22import * as core from '@actions/core'
33import * as fs from 'fs'
44import * as github from '@actions/github'
5+ import * as semver from 'semver'
56import { join } from 'path'
67import { tmpdir } from 'os'
78import { createPRComment , isPREvent , toSemVer } from '../utils'
8- import { gte } from 'semver'
99
1010const BUILD_OUTPUT_JSON_PATH = join ( tmpdir ( ) , 'native-image-build-output.json' )
1111const BYTES_TO_KiB = 1024
@@ -19,6 +19,7 @@ const NATIVE_IMAGE_CONFIG_FILE = join(
1919 tmpdir ( ) ,
2020 'native-image-options.properties'
2121)
22+ const NATIVE_IMAGE_OPTIONS_ENV = 'NATIVE_IMAGE_OPTIONS'
2223const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'
2324
2425interface AnalysisResult {
@@ -91,6 +92,7 @@ interface BuildOutput {
9192
9293export async function setUpNativeImageBuildReports (
9394 isGraalVMforJDK17OrLater : boolean ,
95+ javaVersionOrDev : string ,
9496 graalVMVersion : string
9597) : Promise < void > {
9698 const isRequired = areJobReportsEnabled ( ) || arePRReportsEnabled ( )
@@ -102,14 +104,15 @@ export async function setUpNativeImageBuildReports(
102104 graalVMVersion === c . VERSION_LATEST ||
103105 graalVMVersion === c . VERSION_DEV ||
104106 ( ! graalVMVersion . startsWith ( c . MANDREL_NAMESPACE ) &&
105- gte ( toSemVer ( graalVMVersion ) , '22.2.0' ) )
107+ semver . gte ( toSemVer ( graalVMVersion ) , '22.2.0' ) )
106108 if ( ! isSupported ) {
107109 core . warning (
108110 `Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${ graalVMVersion } .`
109111 )
110112 return
111113 }
112114 setNativeImageOption (
115+ javaVersionOrDev ,
113116 `-H:BuildOutputJSONFile=${ BUILD_OUTPUT_JSON_PATH . replace ( / \\ / g, '\\\\' ) } `
114117 ) // Escape backslashes for Windows
115118}
@@ -144,6 +147,34 @@ function arePRReportsEnabled(): boolean {
144147 return isPREvent ( ) && core . getInput ( INPUT_NI_PR_REPORTS ) === 'true'
145148}
146149
150+ function setNativeImageOption (
151+ javaVersionOrDev : string ,
152+ optionValue : string
153+ ) : void {
154+ const coercedJavaVersionOrDev = semver . coerce ( javaVersionOrDev )
155+ if (
156+ ( coercedJavaVersionOrDev &&
157+ semver . gte ( coercedJavaVersionOrDev , '22.0.0' ) ) ||
158+ javaVersionOrDev === c . VERSION_DEV ||
159+ javaVersionOrDev . endsWith ( '-ea' )
160+ ) {
161+ /* NATIVE_IMAGE_OPTIONS was introduced in GraalVM for JDK 22 (so were EA builds). */
162+ let newOptionValue = optionValue
163+ const existingOptions = process . env [ NATIVE_IMAGE_OPTIONS_ENV ]
164+ if ( existingOptions ) {
165+ newOptionValue = `${ existingOptions } ${ newOptionValue } `
166+ }
167+ core . exportVariable ( NATIVE_IMAGE_OPTIONS_ENV , newOptionValue )
168+ } else {
169+ const optionsFile = getNativeImageOptionsFile ( )
170+ if ( fs . existsSync ( optionsFile ) ) {
171+ fs . appendFileSync ( optionsFile , ` ${ optionValue } ` )
172+ } else {
173+ fs . writeFileSync ( optionsFile , `NativeImageArgs = ${ optionValue } ` )
174+ }
175+ }
176+ }
177+
147178function getNativeImageOptionsFile ( ) : string {
148179 let optionsFile = process . env [ NATIVE_IMAGE_CONFIG_FILE_ENV ]
149180 if ( optionsFile === undefined ) {
@@ -153,15 +184,6 @@ function getNativeImageOptionsFile(): string {
153184 return optionsFile
154185}
155186
156- function setNativeImageOption ( value : string ) : void {
157- const optionsFile = getNativeImageOptionsFile ( )
158- if ( fs . existsSync ( optionsFile ) ) {
159- fs . appendFileSync ( optionsFile , ` ${ value } ` )
160- } else {
161- fs . writeFileSync ( optionsFile , `NativeImageArgs = ${ value } ` )
162- }
163- }
164-
165187function createReport ( data : BuildOutput ) : string {
166188 const context = github . context
167189 const info = data . general_info
0 commit comments