Skip to content

Commit

Permalink
Deploy maven files to a test repository.
Browse files Browse the repository at this point in the history
1. Shell script that creates Maven artifacts from locally
   created BUILD artifacts.
2. Configuration set to upload to a test Maven repository.
3. Documentation on release.

See tensorflow#5
  • Loading branch information
kbsriram committed Dec 30, 2018
1 parent 425e0d1 commit 980519d
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tensorflow_metadata/java/maven/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

licenses(["notice"]) # Apache 2.0

package(default_visibility = ["//visibility:public"])

# run as bazel tensorflow_metadata/java/maven:release -- <new_version_name>
sh_binary(
name = "release",
srcs = ["release.sh"],
data = [
"pom.xml",
"//tensorflow_metadata/proto/v0:metadata_v0_proto_java_pb2",
"//tensorflow_metadata/proto/v0:metadata_v0_proto_srcs",
],
)
111 changes: 111 additions & 0 deletions tensorflow_metadata/java/maven/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# TensorFlow Metadata Protos for Java using Maven

The
[TensorFlow Metadata Protos](https://github.com/tensorflow/metadata)
is available on Maven Central and JCenter through artifacts uploaded to
[OSS Sonatype](https://oss.sonatype.org/content/repositories/releases/org/tensorflow/) and
[Bintray](https://bintray.com/google/tensorflow/tensorflow) respectively. This
document describes the process of updating the release artifacts. It does _not_
describe how to use the protos.

## Updating the release

The Maven artifacts are created from files built as part of the
TensorFlow release process (which uses `bazel`). A `BUILD` rule builds
the proto jars before calling a shell script `release.sh` (only tested
on linux) which builds and uploads Maven artifacts.

### Pre-requisites

- An account at [oss.sonatype.org](https://oss.sonatype.org/), that has
permissions to update artifacts in the `org.tensorflow.metadata` group. If your
account does not have permissions, then you'll need to ask someone who does
to [file a ticket](https://issues.sonatype.org/) to add to the permissions
([sample ticket](https://issues.sonatype.org/browse/MVNCENTRAL-1637)).
- An account at [bintray.com](https://bintray.com) that has permissions to
update the [tensorflow repository](https://bintray.com/google/tensorflow).
If your account does not have permissions, then you'll need to ask one of
the [organization administrators](https://bintray.com/google) to give you
permissions to update the `tensorflow` repository. Please keep the
[repository option](https://bintray.com/google/tensorflow/edit?tab=general)
to *"GPG sign uploaded files using Bintray's public/private key pair"*
**unchecked**, otherwise it will conflict with locally signed artifacts.
- A GPG signing key, required
[to sign the release artifacts](http://central.sonatype.org/pages/apache-maven.html#gpg-signed-components).

### Deploying to Sonatype and Bintray

1. Create a file with your OSSRH credentials and
[Bintray API key](https://bintray.com/docs/usermanual/interacting/interacting_interacting.html#anchorAPIKEY)
(or perhaps you use `mvn` and have it in `~/.m2/settings.xml`):

```sh
SONATYPE_USERNAME="your_sonatype.org_username_here"
SONATYPE_PASSWORD="your_sonatype.org_password_here"
BINTRAY_USERNAME="your_bintray_username_here"
BINTRAY_API_KEY="your_bintray_api_key_here"
GPG_PASSPHRASE="your_gpg_passphrase_here"
cat >/tmp/settings.xml <<EOF
<settings>
<servers>
<server>
<id>ossrh</id>
<username>${SONATYPE_USERNAME}</username>
<password>${SONATYPE_PASSWORD}</password>
</server>
<server>
<id>bintray</id>
<username>${BINTRAY_USERNAME}</username>
<password>${BINTRAY_API_KEY}</password>
</server>
</servers>
<properties>
<gpg.executable>gpg2</gpg.executable>
<gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
</properties>
</settings>
EOF
```
2. Ensure you have a clean repository with no unsubmitted changes, and
run the `bazel` command to release artifacts to the bintray or the
OSSRH repositories:
```sh
$ DEPLOY_BINTRAY=true bazel run tensorflow_metadata/java/maven:release -- 0.9.0
```
Note that you must provide a target version number to the
command. The previous command will release artifacts just to the
bintray repository. Setting the environment variable
`DEPLOY_OSSRH` will release to the Sonatype repository as well.
3. If the script succeeds then artifacts should have been uploaded to
the private staging repository in Sonatype, and as unpublished artifacts in
Bintray. After verifying the release, you should finalize or abort the
release on both sites.
4. If you released to Sonatype, Visit
https://oss.sonatype.org/#stagingRepositories, find the
`org.tensorflow.metadata` release and click on either `Release` to finalize
the release, or `Drop` to abort.
5. Visit https://bintray.com/google/tensorflow-metadata, and select the
version you just uploaded. Notice there's a message about unpublished
artifacts. Click on either `Publish` to finalize the release, or `Discard`
to abort.
6. Some things of note:
- For details, look at the [Sonatype guide](http://central.sonatype.org/pages/releasing-the-deployment.html).
- Syncing with [Maven Central](http://repo1.maven.org/maven2/org/tensorflow/)
can take 10 minutes to 2 hours (as per the [OSSRH
guide](http://central.sonatype.org/pages/ossrh-guide.html#releasing-to-central)).
- For Bintray details, refer to their guide on
[managing uploaded content](https://bintray.com/docs/usermanual/uploads/uploads_managinguploadedcontent.html#_publishing).
## References
- [Sonatype guide](http://central.sonatype.org/pages/ossrh-guide.html) for
hosting releases.
- [Ticket that created the `org/tensorflow` configuration](https://issues.sonatype.org/browse/OSSRH-28072) on OSSRH.
- The [Bintray User Manual](https://bintray.com/docs/usermanual/index.html)
109 changes: 109 additions & 0 deletions tensorflow_metadata/java/maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<name>TensorFlow Metadata protocol buffers.</name>
<description>Java API for TensorFlow Metadata protocol buffers.</description>
<modelVersion>4.0.0</modelVersion>
<groupId>org.kbsriram.tensorflow.metadata</groupId>
<artifactId>proto</artifactId>
<version>0.9.0</version>
<packaging>jar</packaging>

<url>https://github.com/tensorflow/metadata</url>
<inceptionYear>2018</inceptionYear>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/tensorflow/metadata</url>
<connection>[email protected]:tensorflow/metadata.git</connection>
<developerConnection>scm:git:https://github.com/tensorflow/metadata.git</developerConnection>
</scm>

<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.6.0</version>
</dependency>
</dependencies>

<!-- Two profiles are used:
ossrh - deploys to ossrh/maven central
bintray - deploys to bintray/jcenter. -->
<profiles>
<profile>
<id>ossrh</id>
<distributionManagement>
<!-- Sonatype requirements from http://central.sonatype.org/pages/apache-maven.html -->
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
<profile>
<id>bintray</id>
<distributionManagement>
<!-- https://blog.bintray.com/2015/09/17/publishing-your-maven-project-to-bintray/ -->
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/kbsriram/tensorflow-test/kbsriram-tensorflow-metadata/;publish=0</url>
</repository>
</distributionManagement>
</profile>
</profiles>
<!-- http://central.sonatype.org/pages/requirements.html#developer-information -->
<developers>
<developer>
<name>TensorFlowers</name>
<organization>TensorFlow</organization>
<organizationUrl>http://www.tensorflow.org</organizationUrl>
</developer>
</developers>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG signed components: http://central.sonatype.org/pages/apache-maven.html#gpg-signed-components -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

65 changes: 65 additions & 0 deletions tensorflow_metadata/java/maven/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#

set -o errexit
set -o pipefail
set -o nounset

METADATA_VERSION="$1"
shift

if [[ -z "${METADATA_VERSION}" ]]
then
echo "Usage: $0 <version to release>"
exit 1
fi

# By default we don't deploy to any repository. These two environment
# variables can be set to push to one or both repositories.
DEPLOY_BINTRAY="${DEPLOY_BINTRAY:-false}"
DEPLOY_OSSRH="${DEPLOY_OSSRH:-false}"

WORKDIR=`mktemp -d`

function cleanup {
echo "Deleting ${WORKDIR}"
echo rm -rf ${WORKDIR}
}

echo "Building Maven artifacts under ${WORKDIR}"

echo "Copying built jars..."
TARGET_CLASSES=${WORKDIR}/target/classes
PROTO_RESOURCES=${WORKDIR}/src/main/resources/tensorflow_metadata/proto/v0
mkdir -p ${TARGET_CLASSES}
mkdir -p ${PROTO_RESOURCES}
cp -f tensorflow_metadata/java/maven/pom.xml ${WORKDIR}
find tensorflow_metadata/proto/v0 -name '*.jar' -exec unzip -q -d ${TARGET_CLASSES} '{}' '*class' ';'
find tensorflow_metadata/proto/v0 -name '*.proto' -exec cp '{}' ${PROTO_RESOURCES} ';'

echo "Verifying and signing Maven artifacts..."
cd ${WORKDIR}
mvn -q versions:set -DnewVersion="${METADATA_VERSION}"
mvn -q verify
if [[ "${DEPLOY_OSSRH}" == "true" ]]; then
mvn deploy -Possrh
fi
if [[ "${DEPLOY_BINTRAY}" == "true" ]]; then
mvn deploy -Pbintray
fi

cleanup
5 changes: 5 additions & 0 deletions tensorflow_metadata/proto/v0/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ METADATA_PROTO_SRCS = [
"statistics.proto",
]

filegroup(
name = "metadata_v0_proto_srcs",
srcs = METADATA_PROTO_SRCS,
)

proto_library(
name = "metadata_v0_proto",
srcs = METADATA_PROTO_SRCS,
Expand Down

0 comments on commit 980519d

Please sign in to comment.