Skip to content

Commit f0934ea

Browse files
authored
Merge branch 'master' into Initializers1
2 parents 9229789 + abd98f0 commit f0934ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+884
-342
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ on:
33
push:
44
branches:
55
- master
6+
- r[0-9]+.*
67
pull_request:
78
branches:
89
- master
910
types: [opened, reopened, synchronize, labeled, unlabeled]
11+
env:
12+
STAGING_PROFILE_ID: 46f80d0729c92d
13+
NATIVE_BUILD_PROJECTS: tensorflow-core/tensorflow-core-generator,tensorflow-core/tensorflow-core-api
1014
jobs:
1115
quick-build:
1216
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'CI build')
@@ -19,10 +23,27 @@ jobs:
1923
git --version
2024
mvn -version
2125
mvn clean install -Pdev -B -U -e
26+
prepare:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
stagingRepositoryId: ${{ steps.staging.outputs.stagingRepositoryId }}
30+
steps:
31+
- name: Create staging repository
32+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/r')
33+
id: staging
34+
run: |
35+
echo "Creating staging repository with profile $STAGING_PROFILE_ID"
36+
echo "<promoteRequest><data><description>Releasing TF Java - created by CI build</description></data></promoteRequest>" > request.xml
37+
curl -X POST -d @request.xml -s -o response.xml -u ${{ secrets.CI_DEPLOY_USERNAME }}:${{ secrets.CI_DEPLOY_PASSWORD }} -H "Content-Type:application/xml" \
38+
https://oss.sonatype.org/service/local/staging/profiles/$STAGING_PROFILE_ID/start
39+
STAGING_REPOSITORY_ID=`awk -F'[<>]' '/stagedRepositoryId/{print $3}' response.xml`
40+
echo "Staging repository created: $STAGING_REPOSITORY_ID"
41+
echo "::set-output name=stagingRepositoryId::$STAGING_REPOSITORY_ID"
2242
linux-x86_64:
2343
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
2444
runs-on: ubuntu-latest
2545
container: centos:7
46+
needs: prepare
2647
strategy:
2748
matrix:
2849
ext: ["", -mkl, -gpu, -mkl-gpu]
@@ -66,11 +87,12 @@ jobs:
6687
[[ "${{ github.event_name }}" == "push" ]] && MAVEN_PHASE=deploy || MAVEN_PHASE=install
6788
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
6889
echo Executing Maven $MAVEN_PHASE
69-
mvn clean $MAVEN_PHASE -Possrh -B -U -e -Djavacpp.platform=linux-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }}
90+
mvn clean $MAVEN_PHASE -B -U -e -Djavacpp.platform=linux-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl $NATIVE_BUILD_PROJECTS -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
7091
df -h
7192
macosx-x86_64:
7293
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
7394
runs-on: macos-latest
95+
needs: prepare
7496
strategy:
7597
matrix:
7698
ext: ["", -mkl]
@@ -95,11 +117,12 @@ jobs:
95117
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
96118
df -h
97119
echo Executing Maven $MAVEN_PHASE
98-
mvn clean $MAVEN_PHASE -Possrh -B -U -e -Djavacpp.platform=macosx-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }}
120+
mvn clean $MAVEN_PHASE -B -U -e -Djavacpp.platform=macosx-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl $NATIVE_BUILD_PROJECTS -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
99121
df -h
100122
windows-x86_64:
101123
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
102124
runs-on: windows-latest
125+
needs: prepare
103126
# strategy:
104127
# matrix:
105128
# ext: ["", -mkl, -gpu, -mkl-gpu]
@@ -153,29 +176,18 @@ jobs:
153176
df -h
154177
wmic pagefile list /format:list
155178
echo Executing Maven %MAVEN_PHASE%
156-
call mvn clean %MAVEN_PHASE% -Possrh -B -U -e -Djavacpp.platform=windows-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }}
179+
call mvn clean %MAVEN_PHASE% -B -U -e -Djavacpp.platform=windows-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl %NATIVE_BUILD_PROJECTS% -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
157180
if ERRORLEVEL 1 exit /b
158181
df -h
159182
wmic pagefile list /format:list
160-
redeploy:
161-
if: github.event_name == 'push'
183+
deploy:
184+
if: github.event_name == 'push' && contains(github.ref, 'master')
162185
needs: [linux-x86_64, macosx-x86_64, windows-x86_64]
163186
runs-on: ubuntu-latest
164187
steps:
165188
- name: Checkout repository
166189
uses: actions/checkout@v1
167-
- name: Redeploy snapshot artifacts
190+
- name: Deploy snapshot artifacts
168191
run: |
169-
cd tensorflow-core
170-
mvn dependency:resolve -Possrh -Predeploy -N -B -U -e
171-
cp $HOME/.m2/repository/org/tensorflow/tensorflow-core-api/*-SNAPSHOT/tensorflow-core-api-*-SNAPSHOT*.jar .
172-
for f in *.jar; do
173-
if [[ $f =~ tensorflow-core-api-.*SNAPSHOT-(.*).jar ]]; then
174-
[[ -n $FILES ]] && FILES=$FILES,$f || FILES=$f
175-
[[ -n $TYPES ]] && TYPES=$TYPES,jar || TYPES=jar
176-
[[ -n $CLASSIFIERS ]] && CLASSIFIERS=$CLASSIFIERS,${BASH_REMATCH[1]} || CLASSIFIERS=${BASH_REMATCH[1]}
177-
fi
178-
done
179-
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
180-
unzip -o tensorflow-core-api-*-SNAPSHOT.jar META-INF/maven/org.tensorflow/tensorflow-core-api/pom.xml
181-
mvn clean deploy -Possrh -Predeploy -N -B -U -e -Dfiles=$FILES -Dtypes=$TYPES -Dclassifiers=$CLASSIFIERS
192+
echo "<settings><servers><server><id>ossrh</id><username>${{ secrets.CI_DEPLOY_USERNAME }}</username><password>${{ secrets.CI_DEPLOY_PASSWORD }}</password></server></servers></settings>" > settings.xml
193+
bash deploy.sh

RELEASE.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Releasing TensorFlow Java
2+
3+
The
4+
[TensorFlow Java API](https://github.com/tensorflow/java) is available on Maven Central and JCenter
5+
through artifacts uploaded to
6+
[OSS Sonatype](https://oss.sonatype.org/content/repositories/releases/org/tensorflow/). This
7+
document describes the process of updating the release artifacts. It does _not_ describe how to use
8+
the artifacts, for which the reader is referred to the
9+
[TensorFlow for Java installation instructions](https://github.com/tensorflow/java/blob/master/README.md).
10+
11+
## Background
12+
13+
TensorFlow source (which is primarily in C++) is built using
14+
[bazel](https://bazel.build) and not [maven](https://maven.apache.org/). TensorFlow Java
15+
wraps over this native code and thus depends on platform (OS, architecture) specific native code.
16+
17+
Hence, the process for building and uploading release artifacts is not a single
18+
`mvn deploy` command.
19+
20+
## Release process overview
21+
22+
The process of releasing TensorFlow Java is split in two major steps:
23+
* Building and deploying the native artifacts
24+
* Building and deploying all artifacts consolidated
25+
26+
The first step is executed on different build servers, each responsible to build the native
27+
artifact for a specific architecture and platform. The second step is conducted locally in
28+
a [Docker](https://www.docker.com) container for a hermetic release process.
29+
30+
It is important to note that any change pushed to a release branch (i.e. a branch prefixed
31+
by `r`) will start a new release workflow. Therefore, these changes should always increment the
32+
version number.
33+
34+
### Pre-requisites
35+
36+
- `docker`
37+
- An account at [oss.sonatype.org](https://oss.sonatype.org/), that has
38+
permissions to update artifacts in the `org.tensorflow` group. If your
39+
account does not have permissions, then you'll need to ask someone who does
40+
to [file a ticket](https://issues.sonatype.org/) to add to the permissions
41+
([sample ticket](https://issues.sonatype.org/browse/MVNCENTRAL-1637)).
42+
- A GPG signing key, required
43+
[to sign the release artifacts](http://central.sonatype.org/pages/apache-maven.html#gpg-signed-components).
44+
45+
### Preparing a release
46+
47+
#### Major or minor release
48+
49+
1. Get a clean version of the source code by cloning the
50+
[TensorFlow Java GitHub repository](https://github.com/tensorflow/java)
51+
```
52+
git clone https://github.com/tensorflow/java
53+
```
54+
2. Create a new branch for the release named `r<MajorVersion>.<MinorVersion>`
55+
```
56+
git checkout -b r1.0
57+
```
58+
3. Update the version of the Maven artifacts to the full version of the release
59+
```
60+
mvn versions:set -DnewVersion=1.0.0
61+
```
62+
4. Commit the changes and push the new branch to the GitHub repository
63+
```
64+
git add .
65+
git commit -m "Releasing 1.0.0"
66+
git push --set-upstream origin r1.0
67+
```
68+
69+
#### Patch release
70+
71+
1. Get a clean version of the source code by cloning the
72+
[TensorFlow Java GitHub repository](https://github.com/tensorflow/java)
73+
```
74+
git clone https://github.com/tensorflow/java
75+
```
76+
2. Switch to the release branch of the version to patch
77+
```
78+
git checkout r1.0
79+
```
80+
3. Patch the code with your changes. For example, changes could be merged from another branch you
81+
were working on or be applied directly to this branch when the required changes are minimal.
82+
83+
4. Update the version of the Maven artifacts to the full version of the release
84+
```
85+
mvn versions:set -DnewVersion=1.0.1
86+
```
87+
4. Commit the changes and push the branch to the GitHub repository
88+
```
89+
git add .
90+
git commit -m "Releasing 1.0.1"
91+
git push
92+
```
93+
94+
### Building native artifacts
95+
96+
Any change pushed to a release branch will trigger a new release workflow. GitHub Actions builds the native artifacts
97+
for all supported architures/platforms and deploy them temporarily on OSSRH for staging.
98+
99+
There is no user action required for this step other than watching the progress of the GitHub
100+
Actions workflow and making sure that all steps have been completed successfully.
101+
102+
#### Build native artifacts manually
103+
104+
Some platforms cannot be build successfully on GitHub Actions, due to some limits to their resources
105+
(e.g. max 6 hours for a job). For this reasons, we need to build manually some of our artifacts on
106+
private servers.
107+
108+
To do so, follow the same steps as the [CI build](https://github.com/tensorflow/java/blob/master/.github/workflows/ci.yml)
109+
for the same platform and make sure to checkout the release branch and to provide your Sonatype credentials
110+
for temporary staging.
111+
112+
### Building and deploying all artifacts to Sonatype
113+
114+
1. At the root of your TensorFlow Java copy, create a Maven settings.xml file with your OSSRH credentials and
115+
your GPG key passphrase:
116+
```sh
117+
SONATYPE_USERNAME="your_sonatype.org_username_here"
118+
SONATYPE_PASSWORD="your_sonatype.org_password_here"
119+
GPG_PASSPHRASE="your_gpg_passphrase_here"
120+
cat > settings.xml <<EOF
121+
<settings>
122+
<servers>
123+
<server>
124+
<id>ossrh</id>
125+
<username>${SONATYPE_USERNAME}</username>
126+
<password>${SONATYPE_PASSWORD}</password>
127+
</server>
128+
<server>
129+
<id>ossrh-staging</id>
130+
<username>${SONATYPE_USERNAME}</username>
131+
<password>${SONATYPE_PASSWORD}</password>
132+
</server>
133+
</servers>
134+
<profiles>
135+
<profile>
136+
<activation>
137+
<activeByDefault>true</activeByDefault>
138+
</activation>
139+
<properties>
140+
<gpg.executable>gpg2</gpg.executable>
141+
<gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
142+
</properties>
143+
</profile>
144+
<profiles>
145+
</settings>
146+
EOF
147+
```
148+
2. Execute the `release.sh` script. This will deploy artifacts on OSS Sonatype. All native artifacts
149+
previously temporarily staged by GitHub Actions will be fetched, signed and redeployed as well.
150+
151+
The script takes in paramater the sequence number of the staging repository created in OSSRH
152+
by the GitHub Actions workflow. You can retrieve this ID by looking in the staging repositories
153+
in OSSRH console directly, or check at the output of the step `Create Staging Repository` of the
154+
`prepare` job in the workflow execution, where the ID is printed.
155+
```
156+
# Staging repository created: orgtensorflow-1100
157+
sh release.sh 1100
158+
```
159+
3. If the script above succeeds then the artifacts would have been uploaded to
160+
the private staging repository in Sonatype. After verifying the release, you should finalize or
161+
abort the release. Visit https://oss.sonatype.org/#stagingRepositories, find the `orgtensorflow-*`
162+
of your release and click `Close` and `Release` to finalize the release. You always have the option
163+
to `Drop` it to abort and restart if something went wrong.
164+
165+
4. Some things of note:
166+
- For details, look at the [Sonatype guide](http://central.sonatype.org/pages/releasing-the-deployment.html).
167+
- Syncing with [Maven Central](http://repo1.maven.org/maven2/org/tensorflow/)
168+
can take 10 minutes to 2 hours (as per the [OSSRH
169+
guide](http://central.sonatype.org/pages/ossrh-guide.html#releasing-to-central)).
170+
171+
### Finishing a release
172+
173+
Go to GitHub and create a release tag at the release branch with a summary of what the version includes.
174+
175+
#### Major or minor release
176+
177+
1. In your local copy, checkout the master branch and increase the next snapshot version.
178+
```
179+
mvn versions:set -DnewVersion=1.1.0-SNAPSHOT
180+
```
181+
2. Commit your changes and push the master branch to the GitHub repository
182+
```
183+
git add .
184+
git commit -m "Increase version for next iteration"
185+
git push
186+
```
187+
188+
## References
189+
190+
- [Sonatype guide](http://central.sonatype.org/pages/ossrh-guide.html) for
191+
hosting releases.
192+
- [Ticket that created the `org/tensorflow` configuration](https://issues.sonatype.org/browse/OSSRH-28072) on OSSRH.

0 commit comments

Comments
 (0)