Difference between revisions of "Travis"

(Update Travis instructions to match new reality)
(Add Development category)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
{{DevelopMenu | tools}}{{Minibox | logo=Travis.png | blurb='''Travis CI:''' Build your code in the cloud!}}[https://travis-ci.org/ Travis] is a tool for [[Project_management#Continuous_integration|continuous integration]]. It has excellent integration with [[GitHub]], and is very useful for automating builds, deployment and other tasks.
 
{{DevelopMenu | tools}}{{Minibox | logo=Travis.png | blurb='''Travis CI:''' Build your code in the cloud!}}[https://travis-ci.org/ Travis] is a tool for [[Project_management#Continuous_integration|continuous integration]]. It has excellent integration with [[GitHub]], and is very useful for automating builds, deployment and other tasks.
 
{{TOC}}
 
{{TOC}}
 +
= Services =
 +
 +
[[ImageJ]] and [[SciJava]] projects use Travis in a variety of ways:
 +
 +
* Perform builds of SciJava projects. Travis deploys <code>SNAPSHOT</code> builds to the [http://maven.imagej.net/ ImageJ Maven repository] in response to pushes to each code repository's <code>master</code> branch. So any downstream projects depending on a version of <code>LATEST</code> for a given component will match the last successful Travis build—i.e., the latest code on <code>master</code>.
 +
* Run each project's associated [[wikipedia:Unit testing|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 [https://oss.sonatype.org/ OSS Sonatype].
 +
* Keep the [[javadoc]] site updated.
 +
* Keep other web resources updated.
 +
 
= Automatic Deployment of Maven Artifacts =
 
= Automatic Deployment of Maven Artifacts =
  
Deploying your library to [[Maven]] makes it available for other developers. It is also a [[Fiji/Contribution_requirements|contribution requirement for the Fiji project]].
+
Deploying your library to a [[Maven]] repository makes it available for other developers. It is also a [[Fiji/Contribution_requirements|contribution requirement for the Fiji project]].
  
 
== Requirements ==
 
== Requirements ==
Line 11: Line 21:
  
 
== Instructions ==
 
== Instructions ==
{{Notice | These instructions describe much of the technical process of adding Travis metadata to your repository. Normally, an ImageJ admin—not the plugin developer—will follow these instructions.}}
 
 
<div style="overflow: hidden">
 
<div style="overflow: hidden">
 
<tabs>
 
<tabs>
Line 113: Line 122:
 
</source>
 
</source>
 
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.
 
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.
 +
 +
[[Category:Development]]

Latest revision as of 09:42, 5 October 2017

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 ImageJ forum and request that they file a PR which adds Travis support to your repository.

Instructions

  1. Use the following code for your repository's .travis.yml:
    .travis.yml
    language: java
    jdk: oraclejdk8
    branches:
      only:
      - master
      - "/.*-[0-9]+\\..*/"
    install: true
    script: ".travis/build.sh"
    env:
      global:
        secure: Igyr6NuuHuVHGKK44tdLSsSlW9pdT9fd4tJURQ5o3+KkNqmu82GrOqiarxe0xPrUj9ClbSHIPEF1tzB0kl8RS3SZErJD+ejrzTuUf1NfhpSjLgKwtEFqI7Xwq4S494alhqt9ZsXg8seDy/6kq1gq3H/Cwz8Zrli1d0u2DKJ83gs=
    
  2. Delete the entire env section, since we will be replacing it shortly.
  3. From the command line in your repository, create an encrypted environment variable for MAVEN_PASS which defines the Maven password of the ImageJ Maven repository's travis account.
    $ travis encrypt MAVEN_PASS=travis_maven_password --add env.global
    

    Note that this will automatically modify your .travis.yml 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 ImageJ Forum asking for a core ImageJ maintainer to file a PR to your repository adding this encrypted variable.

  4. Add the following script as .travis/build.sh:
    .travis/build.sh
    #!/bin/sh
    curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh
    sh travis-build.sh
    
  5. Create a settings.xml in your repository with the following contents:
    .travis/settings.xml
    <settings>
      <servers>
        <server>
          <id>imagej.releases</id>
          <username>travis</username>
          <password>${env.MAVEN_PASS}</password>
        </server>
        <server>
          <id>imagej.snapshots</id>
          <username>travis</username>
          <password>${env.MAVEN_PASS}</password>
        </server>
      </servers>
    </settings>
    
  6. 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 Travis dashboard with each new commit, with corresponding SNAPSHOT artifacts automatically deployed to maven.imagej.net.
  1. Add the following code to your build.gradle file:
    // 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")
                }
            }
        }
    }
    

    If you also want your Javadoc JAR to be published, also add the following:

    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" }
                    }
            }
    }
    
  2. From the command line in your repository, create an encrypted environment variable for your maven.imagej.net username and password—be careful with escaping special characters correctly:
    $ travis encrypt MAVEN_USER=my_maven_username --add env.matrix
    $ travis encrypt MAVEN_PASS=my_maven_password --add env.matrix
    

    Note that this will automatically modify your .travis.yml file.

  3. 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 Travis dashboard with each new commit, with corresponding SNAPSHOT and release artifacts immediately deployed automatically to maven.imagej.net.

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.