Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic deployment of snapshots to Sonatype by Travis-CI #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
language: java
language: java

# Snapshot deployment to Sonatype Maven repository
# The password is encrypted using "travis encrypt -r echo3/echo3extras SONATYPE_PASSWORD=password"
# and only decrypted and set as environment variable by travis-ci if the build runs in the context of
# the echo3/echo3extras github repository.

env:
global:
- SONATYPE_USERNAME=bschmid
- secure: "WkgVn7wbMe7C1KKAFZrvy2BR2eZZ6Bnv1/BPJFHOI+u172wnFPX5FDyjZQiU9xipocnWfa5MZCCpyKBJrNDnWEVlM75bZG6Xpq+yu3tbZgxyNZ3JLxU6a7m5OJo4XjhBiVbX7b+BmD5qHCO5CTgxZIJbKIz0ToUU+ALLcdVlsS8="

after_success:
- python resource/travis-ci/addServer.py
- ant travis.mvn.snapshot
18 changes: 17 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,24 @@
</artifact:install>
</target>

<target name="mvn.snapshot" depends="dist, doc.jars, -mvn.generate.pom, -mvn.inittasks"
<!-- Deploy snapshot to Sonatype Maven repository. Called by Travis-CI -->
<target name="travis.mvn.snapshot">
<property environment="env"/>
<condition property="secure_env">
<not>
<equals arg1="${env.TRAVIS_SECURE_ENV_VARS}" arg2="false"/>
</not>
</condition>
<fail unless="secure_env" message="No secure environment variables available, skipping snapshot deployment" />
<antcall target="-mvn.snapshot" />
</target>

<target name="mvn.snapshot" depends="dist, doc.jars, -mvn.snapshot"
description="Deploy snapshot version to configured Maven snapshot repository">
</target>

<!-- Synthetic Implementation target for code reuse -->
<target name="-mvn.snapshot" depends="-mvn.generate.pom, -mvn.inittasks">
<!-- The artifact:deploy tasks do not repesct settings.xml for proxy/auth, so we use the mvn task -->
<!-- Deploy Echo API module. -->
<artifact:mvn>
Expand Down
50 changes: 50 additions & 0 deletions resource/travis-ci/addServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python
"""
Add sonatype snapshot server and credentials to ~/.m2/settings.xml
Username and password are passed in by travis-ci as environment
variables.
"""
import sys
import os
import os.path
import xml.dom.minidom

if os.environ["TRAVIS_SECURE_ENV_VARS"] == "false":
print "no secure env vars available, skipping deployment"
sys.exit()

homedir = os.path.expanduser("~")

m2 = xml.dom.minidom.parse(homedir + '/.m2/settings.xml')
settings = m2.getElementsByTagName("settings")[0]

serversNodes = settings.getElementsByTagName("servers")
if not serversNodes:
serversNode = m2.createElement("servers")
settings.appendChild(serversNode)
else:
serversNode = serversNodes[0]

sonatypeServerNode = m2.createElement("server")
sonatypeServerId = m2.createElement("id")
sonatypeServerUser = m2.createElement("username")
sonatypeServerPass = m2.createElement("password")

idNode = m2.createTextNode("sonatype-nexus-snapshots")
userNode = m2.createTextNode(os.environ["SONATYPE_USERNAME"])
passNode = m2.createTextNode(os.environ["SONATYPE_PASSWORD"])

sonatypeServerId.appendChild(idNode)
sonatypeServerUser.appendChild(userNode)
sonatypeServerPass.appendChild(passNode)

sonatypeServerNode.appendChild(sonatypeServerId)
sonatypeServerNode.appendChild(sonatypeServerUser)
sonatypeServerNode.appendChild(sonatypeServerPass)

serversNode.appendChild(sonatypeServerNode)

m2Str = m2.toxml()
f = open(homedir + '/.m2/settings.xml', 'w')
f.write(m2Str + '\n')
f.close()