Difference between revisions of "Travis"

(Remove settings.xml step -- obsolete now)
(Update Travis instructions)
Line 21: Line 21:
  
 
== Instructions ==
 
== Instructions ==
<div style="overflow: hidden">
+
In order to add Travis CI support to a repository, the SciJava credentials are needed: A) for deploying to Maven repositories; and B) in the case of deploying to OSS Sonatype, for GPG signing of artifacts. If you have a copy of these credentials, and admin access to the relevant repository on GitHub, you can use the [https://github.com/scijava/scijava-scripts/blob/master/travisify.sh travisify.sh script] to perform the needed operations. This script requires the [https://github.com/travis-ci/travis.rb travis command line client] to be installed, and you may need to run <code>travis login</code> to authenticate first. If you need help, please ask [https://forum.image.sc/ on the Image.sc Forum] in the Development category, or in the [https://gitter.im/scijava/scijava-common scijava-common channel] on Gitter.
<tabs>
 
<tab name="Maven">
 
<ol>
 
<li>Use the following code for your repository's <code>.travis.yml</code>:
 
<br>{{GitHubEmbed|org=imagej|repo=imagej-common|path=.travis.yml}}
 
</li>
 
<li>Delete the entire <code>env</code> section, since we will be replacing it shortly.</li>
 
<li>From the command line in your repository, create an [https://docs.travis-ci.com/user/environment-variables/#Encrypting-Variables-Using-a-Public-Key encrypted environment variable] for <code>MAVEN_PASS</code> which defines the Maven password of the [[ImageJ Maven repository]]'s <code>travis</code> account.
 
 
 
<source lang="bash">
 
$ travis encrypt MAVEN_PASS=travis_maven_password --add env.global
 
</source>
 
 
 
Note that this will automatically modify your <code>.travis.yml</code> file.
 
 
 
'''If you are not a core ImageJ maintainer, you probably do not have this password.''' Finish the rest of these steps below, then start a topic on the [http://forum.image.sc/ Image.sc Forum] asking for a core ImageJ maintainer to file a PR to your repository adding this encrypted variable.
 
</li>
 
<li>Add the following script as <code>.travis/build.sh</code>:
 
<br>{{GitHubEmbed|org=imagej|repo=imagej-common|path=.travis/build.sh}}
 
</li>
 
<li>Commit all your files with Git and push them back to your repository. If everything works as intended, you should start seeing new builds in your [https://travis-ci.org Travis dashboard] with each new commit, with corresponding SNAPSHOT artifacts automatically deployed to [http://maven.imagej.net/index.html#view-repositories maven.imagej.net].
 
</li>
 
</ol>
 
</tab>
 
<tab name="Gradle">
 
<ol>
 
<li>Add the following code to your <code>build.gradle</code> file:
 
<source lang="Groovy">
 
// this _must_ be at the top, with the other plugins
 
apply plugin: 'maven'
 
apply plugin: 'maven-publish'
 
 
 
// more towards the end
 
uploadArchives {
 
    repositories {
 
        mavenDeployer {
 
            repository(url: "http://maven.imagej.net/content/repositories/releases") {
 
                authentication(userName: "$System.env.MAVEN_USER", password: "$System.env.MAVEN_PASS")
 
            }
 
            snapshotRepository(url: "http://maven.imagej.net/content/repositories/snapshots") {
 
                authentication(userName: "$System.env.MAVEN_USER", password: "$System.env.MAVEN_PASS")
 
            }
 
        }
 
    }
 
}
 
</source>
 
 
 
If you also want your Javadoc JAR to be published, also add the following:
 
<source lang="Groovy">
 
task javadocJar(type: Jar, dependsOn:javadoc) {
 
        classifier = 'javadoc'
 
        from javadoc.destinationDir
 
}
 
 
 
artifacts
 
{
 
        archives sourcesJar
 
        archives javadocJar
 
    archives testsJar
 
}
 
 
 
publishing {
 
        publications {
 
                maven(MavenPublication) {
 
                        from components.java
 
                        artifact sourcesJar { classifier "sources" }
 
                }
 
        }
 
}
 
</source>
 
</li>
 
<li>From the command line in your repository, create an [https://docs.travis-ci.com/user/environment-variables/#Encrypting-Variables-Using-a-Public-Key encrypted environment variable] for your [http://maven.imagej.net maven.imagej.net] username and password—be careful with escaping special characters correctly:
 
 
 
<source lang="bash">
 
$ travis encrypt MAVEN_USER=my_maven_username --add env.matrix
 
$ travis encrypt MAVEN_PASS=my_maven_password --add env.matrix
 
</source>
 
 
 
Note that this will automatically modify your <code>.travis.yml</code> file.
 
</li>
 
<li>Commit all your files with Git and push them back to your repository. If everything works as intended, you should start seeing new builds in your [https://travis-ci.org Travis dashboard] with each new commit, with corresponding SNAPSHOT and release artifacts immediately deployed automatically to [http://maven.imagej.net/index.html#view-repositories maven.imagej.net].
 
</li>
 
</ol>
 
</tab>
 
</tabs>
 
</div>
 
  
 
== Testing things which cannot run headless ==
 
== Testing things which cannot run headless ==

Revision as of 10:21, 13 August 2018

Development
Topics
Overview
Philosophy
Architecture
Source code
Project management
Coding style
Debugging
Tools
GitHub
Git
Maven
IDEs
Travis
AppVeyor
Dotfiles
Guides
Writing plugins
ImageJ Ops
Contributing to a plugin
Distributing your plugins
Development lifecycle
Building a POM
Developing with Eclipse
Hands-on debugging
Adding new ops
Adding new formats
Using native libraries
Tips for developers
Tips for C++ developers
ImageJ 1.x plugins
Versioning
Logging
Uber-JARs
Travis CI: Build your code in the cloud!
Travis is a tool for continuous integration. It has excellent integration with GitHub, and is very useful for automating builds, deployment and other tasks.

Services

ImageJ and SciJava projects use Travis in a variety of ways:

  • Perform builds of SciJava projects. Travis deploys SNAPSHOT builds to the ImageJ Maven repository in response to pushes to each code repository's master branch. So any downstream projects depending on a version of LATEST for a given component will match the last successful Travis build—i.e., the latest code on master.
  • Run each project's associated unit tests. Travis is instrumental in early detection of new bugs introduced to the codebase.
  • Perform releases of SciJava projects. Travis deploys release builds to the appropriate Maven repository—typically either the ImageJ Maven repository or OSS Sonatype.
  • Keep the javadoc site updated.
  • Keep other web resources updated.

Automatic Deployment of Maven Artifacts

Deploying your library to a Maven repository makes it available for other developers. It is also a contribution requirement for the Fiji project.

Requirements

  • Host your open-source project on GitHub.
  • Log in to Travis CI with your corresponding GitHub account and enable your repository.
  • Contact an ImageJ admin in Gitter or the Image.sc Forum and request that they file a PR which adds Travis support to your repository.

Instructions

In order to add Travis CI support to a repository, the SciJava credentials are needed: A) for deploying to Maven repositories; and B) in the case of deploying to OSS Sonatype, for GPG signing of artifacts. If you have a copy of these credentials, and admin access to the relevant repository on GitHub, you can use the travisify.sh script to perform the needed operations. This script requires the travis command line client to be installed, and you may need to run travis login to authenticate first. If you need help, please ask on the Image.sc Forum in the Development category, or in the scijava-common channel on Gitter.

Testing things which cannot run headless

If your tests require a display (i.e.: they do not pass when run headless), you can use Xvfb as follows:

before_script:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3 # give xvfb some time to start

Of course, you should do this only as a last resort, since the best unit tests should not require a display in the first place.