Skip to content

Commit 228713f

Browse files
authored
adding publishing stage to publish java CUDA 12 pkg to ado (#20834)
1 parent 5bfca1d commit 228713f

File tree

4 files changed

+125
-19
lines changed

4 files changed

+125
-19
lines changed

java/build.gradle

+46-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id 'signing'
55
id 'jacoco'
66
id "com.diffplug.spotless" version "6.25.0"
7+
id "net.linguica.maven-settings" version "0.5"
78
}
89

910
allprojects {
@@ -19,6 +20,12 @@ version = rootProject.file('../VERSION_NUMBER').text.trim()
1920
def cmakeBuildDir = System.properties['cmakeBuildDir']
2021
def useCUDA = System.properties['USE_CUDA']
2122
def useROCM = System.properties['USE_ROCM']
23+
24+
def adoArtifact = project.findProperty('adoArtifact')
25+
def adoAccessToken = project.findProperty('adoAccessToken')
26+
// Only publish to ADO feed if all two properties are set
27+
def publishToAdo = adoArtifact != null && adoAccessToken != null
28+
2229
boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1"
2330
def cmakeJavaDir = "${cmakeBuildDir}/java"
2431
def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
@@ -37,6 +44,11 @@ def trainingDescription = 'ONNX Runtime Training is a training and inference pac
3744
'(Open Neural Network Exchange) models. This package is targeted for Learning on The Edge aka On-Device Training ' +
3845
'See https://github.com/microsoft/onnxruntime-training-examples/tree/master/on_device_training for more details.'
3946

47+
// We need to have a custom settings.xml so codeql can bypass the need for settings.security.xml
48+
mavenSettings {
49+
userSettingsFileName = "${projectDir}/settings.xml"
50+
}
51+
4052
java {
4153
sourceCompatibility = JavaVersion.VERSION_1_8
4254
targetCompatibility = JavaVersion.VERSION_1_8
@@ -206,9 +218,13 @@ publishing {
206218
publications {
207219
maven(MavenPublication) {
208220
groupId = project.group
209-
artifactId = mavenArtifactId
210-
211-
from components.java
221+
if(publishToAdo) {
222+
artifactId = 'onnxruntime_gpu'
223+
artifact (adoArtifact)
224+
} else {
225+
artifactId = mavenArtifactId
226+
from components.java
227+
}
212228
pom {
213229
name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
214230
description = enableTrainingApis ? trainingDescription : defaultDescription
@@ -239,24 +255,41 @@ publishing {
239255
}
240256
}
241257
repositories {
242-
maven {
243-
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
244-
credentials {
245-
username mavenUser
246-
password mavenPwd
258+
if (publishToAdo) {
259+
maven {
260+
url "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/${System.getenv('ADOFeedName')}/maven/v1"
261+
name System.getenv('ADOFeedName')
262+
authentication {
263+
basic(BasicAuthentication)
264+
}
265+
credentials {
266+
username 'aiinfra'
267+
password "${project.findProperty('adoAccessToken')}"
268+
}
269+
}
270+
} else {
271+
maven {
272+
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
273+
credentials {
274+
username mavenUser
275+
password mavenPwd
276+
}
247277
}
248278
}
249279
}
250280
}
251-
252281
// Generates a task signMavenPublication that will
253282
// build all artifacts.
254283
signing {
255284
// Queries env vars:
256285
// ORG_GRADLE_PROJECT_signingKey
257286
// ORG_GRADLE_PROJECT_signingPassword but can be changed to properties
258-
def signingKey = findProperty("signingKey")
259-
def signingPassword = findProperty("signingPassword")
260-
useInMemoryPgpKeys(signingKey, signingPassword)
261-
sign publishing.publications.maven
287+
def signingKey = findProperty("signingKey")
288+
def signingPassword = findProperty("signingPassword")
289+
// Skip signing if no key is provided
290+
if (signingKey != null && signingPassword != null) {
291+
useInMemoryPgpKeys(signingKey, signingPassword)
292+
sign publishing.publications.maven
293+
sign publishing.publications.mavenAdo
294+
}
262295
}

java/settings.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--The only purpose of this file is to let codeql bypass the need for settings.security.xml-->
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
5+
https://maven.apache.org/xsd/settings-1.0.0.xsd">
6+
<servers>
7+
<!-- password is coming from cli -PadoAccessToken -->
8+
</servers>
9+
</settings>

tools/ci_build/github/azure-pipelines/nuget-cuda-publishing-pipeline.yml

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ resources:
99
branch: main
1010

1111
parameters:
12-
- name: nightly
12+
- name: isReleaseBuild
1313
type: boolean
14-
default: true
14+
default: false
15+
16+
variables:
17+
- name: ArtifactFeed
18+
${{ if eq(parameters.isReleaseBuild, false) }}:
19+
value: ort-cuda-12-nightly
20+
${{ else }}:
21+
value: onnxruntime-cuda-12
1522

1623
stages:
1724
- template: stages/nuget-cuda-publishing-stage.yml
1825
parameters:
19-
${{ if ne(parameters.nightly, true) }}:
20-
artifact_feed: onnxruntime-cuda-12
21-
${{ else }}:
22-
artifact_feed: ort-cuda-12-nightly
26+
artifact_feed: $(ArtifactFeed)
27+
28+
- template: stages/java-cuda-publishing-stage.yml
29+
parameters:
30+
artifact_feed: $(ArtifactFeed)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
parameters:
2+
- name: artifact_feed
3+
type: string
4+
5+
stages:
6+
- stage: JAR_Publishing_GPU
7+
dependsOn: []
8+
jobs:
9+
- job: JAR_Publishing_GPU
10+
#TD-DO: figure out a way to package nightly jar. Currently Java version are set from VERSION_NUMBER file
11+
condition: ${{ eq(parameters.artifact_feed, 'onnxruntime-cuda-12') }}
12+
workspace:
13+
clean: all
14+
pool: 'onnxruntime-Win-CPU-2022'
15+
variables:
16+
- name: SYSTEM_ACCESSTOKEN
17+
value: $(System.AccessToken)
18+
- name: ADOFeedName
19+
value: ${{ parameters.artifact_feed }}
20+
- name: GDN_CODESIGN_TARGETDIRECTORY
21+
value: '$(Build.BinariesDirectory)/final-package'
22+
- name: artifactName
23+
value: onnxruntime-java-gpu
24+
25+
steps:
26+
- script: mkdir "$(GDN_CODESIGN_TARGETDIRECTORY)"
27+
28+
- download: build
29+
displayName: 'Download Pipeline Artifact - $(artifactName)'
30+
artifact: '$(artifactName)'
31+
32+
- task: CopyFiles@2
33+
inputs:
34+
SourceFolder: '$(Pipeline.Workspace)/build/$(artifactName)'
35+
Contents: |
36+
onnxruntime_gpu*.jar
37+
onnxruntime_gpu*.pom
38+
TargetFolder: '$(GDN_CODESIGN_TARGETDIRECTORY)'
39+
CleanTargetFolder: true
40+
41+
- task: PowerShell@2
42+
displayName: 'Bundle Jar and POM files into a single jar file'
43+
inputs:
44+
targetType: 'inline'
45+
script: |
46+
jar cvf bundle.jar `
47+
onnxruntime_gpu-*.pom `
48+
onnxruntime_gpu-*.jar
49+
workingDirectory: '$(GDN_CODESIGN_TARGETDIRECTORY)'
50+
51+
- task: Gradle@3
52+
inputs:
53+
gradleWrapperFile: '$(Build.SourcesDirectory)/java/gradlew.bat'
54+
workingDirectory: '$(Build.SourcesDirectory)/java'
55+
tasks: 'publish'
56+
options: '-PadoAccessToken=$(SYSTEM_ACCESSTOKEN) -PadoArtifact=$(GDN_CODESIGN_TARGETDIRECTORY)/bundle.jar'

0 commit comments

Comments
 (0)