Skip to content

Commit 8222c44

Browse files
committed
Deploy native artifacts in GHA runners
1 parent aec5ab7 commit 8222c44

File tree

5 files changed

+75
-28
lines changed

5 files changed

+75
-28
lines changed

.github/workflows/build.yml

+34-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
types: [opened, reopened, synchronize, labeled, unlabeled]
1313
env:
1414
STAGING_PROFILE_ID: 46f80d0729c92d
15+
DEPLOY_SNAPSHOT: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging') }}
16+
DEPLOY_RELEASE: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/heads/r') }}
1517
jobs:
1618
check-format:
1719
if: github.event_name == 'pull_request'
@@ -35,19 +37,30 @@ jobs:
3537
prepare:
3638
runs-on: ubuntu-20.04
3739
outputs:
38-
stagingRepositoryId: ${{ steps.staging.outputs.stagingRepositoryId }}
40+
repositoryUrl: ${{ steps.repository.outputs.repositoryUrl }}
3941
steps:
4042
- name: Create staging repository
41-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/r')
43+
if: env.DEPLOY_RELEASE == 'true'
4244
id: staging
4345
run: |
4446
echo "Creating staging repository with profile $STAGING_PROFILE_ID"
4547
echo "<promoteRequest><data><description>Releasing TF Java - created by CI build</description></data></promoteRequest>" > request.xml
4648
curl -X POST -d @request.xml -s -o response.xml -u ${{ secrets.CI_DEPLOY_USERNAME }}:${{ secrets.CI_DEPLOY_PASSWORD }} -H "Content-Type:application/xml" \
4749
https://oss.sonatype.org/service/local/staging/profiles/$STAGING_PROFILE_ID/start
48-
STAGING_REPOSITORY_ID=`awk -F'[<>]' '/stagedRepositoryId/{print $3}' response.xml`
50+
export STAGING_REPOSITORY_ID=`awk -F'[<>]' '/stagedRepositoryId/{print $3}' response.xml`
4951
echo "Staging repository created: $STAGING_REPOSITORY_ID"
50-
echo "::set-output name=stagingRepositoryId::$STAGING_REPOSITORY_ID"
52+
- name: Checkout repository
53+
uses: actions/checkout@v1
54+
- name: Extract distribution repository URL
55+
id: repository
56+
run: |
57+
if [[ "${{ env.DEPLOY_RELEASE }}" = "true" ]]; then
58+
export REPOSITORY_URL=`mvn exec:exec -q -N -Dexec.executable='echo' -Dexec.args="\\${project.distributionManagement.repository.url}" -DstagingRepositoryId=$STAGING_REPOSITORY_ID`
59+
else
60+
export REPOSITORY_URL=`mvn exec:exec -q -N -Dexec.executable='echo' -Dexec.args="\\${project.distributionManagement.snapshotRepository.url}"`
61+
fi
62+
echo "Repository URL: $REPOSITORY_URL"
63+
echo "::set-output name=repositoryUrl::$REPOSITORY_URL"
5164
linux-x86_64:
5265
runs-on: ubuntu-20.04
5366
needs: prepare
@@ -67,7 +80,10 @@ jobs:
6780
gcc --version
6881
mvn -version
6982
echo "<settings><servers><server><id>ossrh</id><username>${{ secrets.CI_DEPLOY_USERNAME }}</username><password>${{ secrets.CI_DEPLOY_PASSWORD }}</password></server></servers></settings>" > $HOME/.m2/settings.xml
70-
mvn clean install -pl '!tensorflow-framework' -B -U -e -Djavacpp.platform=linux-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
83+
mvn clean install -pl '!tensorflow-framework' -B -U -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }}
84+
- name: Deploy native artifact
85+
if: env.DEPLOY_RELEASE == 'true' || env.DEPLOY_SNAPSHOT == 'true'
86+
run: mvn -f tensorflow-core/tensorflow-core-native/pom.xml deploy:deploy-file@native-only -B -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }} -Durl=${{ needs.prepare.outputs.repositoryUrl }}
7187
macosx-arm64:
7288
runs-on: macos-14
7389
needs: prepare
@@ -88,7 +104,10 @@ jobs:
88104
clang --version
89105
mvn -version
90106
echo "<settings><servers><server><id>ossrh</id><username>${{ secrets.CI_DEPLOY_USERNAME }}</username><password>${{ secrets.CI_DEPLOY_PASSWORD }}</password></server></servers></settings>" > $HOME/.m2/settings.xml
91-
mvn clean install -pl '!tensorflow-framework' -B -U -e -Djavacpp.platform=macosx-arm64 -Djavacpp.platform.extension=${{ matrix.ext }} -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
107+
mvn clean install -pl '!tensorflow-framework' -B -U -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }}
108+
- name: Deploy native artifact
109+
if: env.DEPLOY_RELEASE == 'true' || env.DEPLOY_SNAPSHOT == 'true'
110+
run: mvn -f tensorflow-core/tensorflow-core-native/pom.xml deploy:deploy-file@native-only -B -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }} -Durl=${{ needs.prepare.outputs.repositoryUrl }}
92111
macosx-x86_64:
93112
runs-on: macos-11
94113
needs: prepare
@@ -108,9 +127,11 @@ jobs:
108127
clang --version
109128
mvn -version
110129
echo "<settings><servers><server><id>ossrh</id><username>${{ secrets.CI_DEPLOY_USERNAME }}</username><password>${{ secrets.CI_DEPLOY_PASSWORD }}</password></server></servers></settings>" > $HOME/.m2/settings.xml
111-
mvn clean install -pl '!tensorflow-framework' -B -U -e -Djavacpp.platform=macosx-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
130+
mvn clean install -pl '!tensorflow-framework' -B -U -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }}
131+
- name: Deploy native artifact
132+
if: env.DEPLOY_RELEASE == 'true' || env.DEPLOY_SNAPSHOT == 'true'
133+
run: mvn -f tensorflow-core/tensorflow-core-native/pom.xml deploy:deploy-file@native-only -B -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }} -Durl=${{ needs.prepare.outputs.repositoryUrl }}
112134
windows-x86_64:
113-
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
114135
runs-on: windows-2019
115136
needs: prepare
116137
strategy:
@@ -148,10 +169,13 @@ jobs:
148169
call mvn -version
149170
echo ^<settings^>^<servers^>^<server^>^<id^>ossrh^</id^>^<username^>${{ secrets.CI_DEPLOY_USERNAME }}^</username^>^<password^>${{ secrets.CI_DEPLOY_PASSWORD }}^</password^>^</server^>^</servers^>^</settings^> > %USERPROFILE%\.m2\settings.xml
150171
set "SKIP_EXPORT=true"
151-
call mvn clean install -pl "!tensorflow-framework" -B -U -e -Djavacpp.platform=windows-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
172+
call mvn clean install -pl "!tensorflow-framework" -B -U -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }}
152173
if ERRORLEVEL 1 exit /b
174+
- name: Deploy native artifact
175+
if: env.DEPLOY_RELEASE == 'true' || env.DEPLOY_SNAPSHOT == 'true'
176+
run: call mvn -f tensorflow-core/tensorflow-core-native/pom.xml deploy:deploy-file@native-only -B -e -Djavacpp.platform=${{ github.job }} -Djavacpp.platform.extension=${{ matrix.ext }} -Durl=${{ needs.prepare.outputs.repositoryUrl }}
153177
deploy:
154-
if: github.event_name == 'push' && (contains(github.ref, 'master') || contains(github.ref, 'staging'))
178+
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging') }} # DEPLOY_SNAPSHOT (releases should be signed and deployed manually from local machine)
155179
needs: [linux-x86_64, macosx-x86_64, windows-x86_64, macosx-arm64]
156180
runs-on: ubuntu-20.04
157181
steps:

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<maven.source.skip>false</maven.source.skip>
149149
</properties>
150150
</profile>
151+
151152
<!--
152153
Releasing profile
153154
Activate GPG signing on all built artifacts and fetch native artifacts from staging repository

tensorflow-core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<profile>
6969
<!--
7070
When deploying, the build packages and distributes native binaries for all supported platforms. These native artifacts
71-
must have already been built, tested and published priorly on their respective platform.
71+
must have already been built, tested and deployed priorly from their respective platform.
7272
-->
7373
<id>deploying</id>
7474
<properties>

tensorflow-core/tensorflow-core-api/pom.xml

-12
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,6 @@
177177
</plugins>
178178
</build>
179179
</profile>
180-
181-
<profile>
182-
<!--
183-
Deploying Profile
184-
Avoid deploying snapshots since all artifacts must have the same timestamp to avoid
185-
issues when using Gradle.
186-
-->
187-
<id>deploying</id>
188-
<properties>
189-
<maven.deploy.skip>true</maven.deploy.skip>
190-
</properties>
191-
</profile>
192180
</profiles>
193181

194182
<build>

tensorflow-core/tensorflow-core-native/pom.xml

+39-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
</dependencies>
5959

6060
<profiles>
61+
<!-- Do a full native build using Bazel -->
6162
<profile>
6263
<id>native-build</id>
6364
<activation>
@@ -73,13 +74,18 @@
7374
</properties>
7475
</profile>
7576

77+
<!-- Deploying mode: don't create native artifacts, use ones published by CI build -->
78+
<profile>
79+
<id>deploying</id>
80+
<properties>
81+
<javacpp.build.skip>true</javacpp.build.skip>
82+
<dist.download.skip>true</dist.download.skip>
83+
</properties>
84+
</profile>
85+
86+
<!-- Generating mode: produce Java files from native resources -->
7687
<profile>
7788
<id>generating</id>
78-
<activation>
79-
<property>
80-
<name>native.generate</name>
81-
</property>
82-
</activation>
8389
<properties>
8490
<bazel.generate.skip>false</bazel.generate.skip>
8591
<bazel.clean.skip>false</bazel.clean.skip>
@@ -467,6 +473,34 @@
467473
</executions>
468474
</plugin>
469475

476+
<plugin>
477+
<artifactId>maven-deploy-plugin</artifactId>
478+
<version>3.1.1</version>
479+
<executions>
480+
<execution>
481+
<!--
482+
Deploy only native artifact
483+
This is used by the CI build to only deploy the native JAR artifact in the platform-specific runners.
484+
Other artifacts will be deployed in a second pass, when activating the `deploying` profile
485+
-->
486+
<id>native-only</id>
487+
<goals>
488+
<goal>deploy-file</goal>
489+
</goals>
490+
<configuration>
491+
<!-- 'url' property must be provided in command line -->
492+
<file>${project.build.directory}/${project.artifactId}-${project.version}-${native.classifier}.jar</file>
493+
<repositoryId>ossrh</repositoryId>
494+
<groupId>${project.groupId}</groupId>
495+
<artifactId>${project.artifactId}</artifactId>
496+
<classifier>${native.classifier}</classifier>
497+
<pomFile>pom.xml</pomFile>
498+
<generatePom>false</generatePom>
499+
</configuration>
500+
</execution>
501+
</executions>
502+
</plugin>
503+
470504
<plugin>
471505
<artifactId>maven-surefire-plugin</artifactId>
472506
<executions>

0 commit comments

Comments
 (0)