Difference between revisions of "Travis"

(Remove reference to Jenkins; just describe what Travis is good at)
(Update Travis instructions to match new reality)
Line 17: Line 17:
 
<ol>
 
<ol>
 
<li>Use the following code for your repository's <code>.travis.yml</code>:
 
<li>Use the following code for your repository's <code>.travis.yml</code>:
<br>{{GitHubEmbed|org=scijava|repo=scijava-common|path=.travis.yml}}
+
<br>{{GitHubEmbed|org=imagej|repo=imagej-common|path=.travis.yml}}
 
</li>
 
</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. Then do the same for the <code>TOKEN_NAME</code> of the [[ImageJ Jenkins]] <code>Travis-Success</code> and <code>Travis-Failure</code> jobs.
+
<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">
 
<source lang="bash">
 
$ travis encrypt MAVEN_PASS=travis_maven_password --add env.global
 
$ travis encrypt MAVEN_PASS=travis_maven_password --add env.global
$ travis encrypt TOKEN_NAME=imagej_jenkins_token --add env.global
 
 
</source>
 
</source>
  
 
Note that this will automatically modify your <code>.travis.yml</code> file.
 
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.imagej.net/ ImageJ Forum] asking for a core ImageJ maintainer to file a PR to your repository adding this encrypted variable.
 
</li>
 
</li>
 
<li>Add the following script as <code>.travis/build.sh</code>:
 
<li>Add the following script as <code>.travis/build.sh</code>:
<br>{{GitHubEmbed|org=scijava|repo=scijava-common|path=.travis/build.sh}}
+
<br>{{GitHubEmbed|org=imagej|repo=imagej-common|path=.travis/build.sh}}
</li>
 
<li>Add the following script as <code>.travis/notify.sh</code>:
 
<br>{{GitHubEmbed|org=scijava|repo=scijava-common|path=.travis/notify.sh}}
 
 
</li>
 
</li>
 
<li>Create a <code>settings.xml</code> in your repository with the following contents:
 
<li>Create a <code>settings.xml</code> in your repository with the following contents:
<br>{{GitHubEmbed|org=scijava|repo=scijava-common|path=.travis/settings.xml}}
+
<br>{{GitHubEmbed|org=imagej|repo=imagej-common|path=.travis/settings.xml}}
 
</li>
 
</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>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].

Revision as of 12:21, 27 September 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.

Automatic Deployment of Maven Artifacts

Deploying your library to Maven 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: openjdk8
    branches:
      only:
      - master
      - "/.*-[0-9]+\\..*/"
    install: true
    script: ".travis/build.sh"
    cache:
      directories:
      - "~/.m2/repository"
    env:
      global:
      - secure: QKOpRsJuKoX6HLZjh8/trNaEihUzKNBce77OxbsbmXOmEo2HJHao1ZzxBAgoP1pNutmLorYc9fThjnowHGQLbEi7dgAHR0PJ+5hPbnZeDny4BfXi86nF4aO84NfWgX6yoMak9H4O6uf5Wom5ujqvC3ANWgmohXrS84P/oSyTZec=
      - secure: aT6GsuAT3H2ghwcPJq31aHgqe6p4P/em5Y6fpaC4jDHm3edbtVKdD1U9uaDQpwI4Rj8KG9+8+RDMw6q0UKEIwGszxZTcahqv43iWS8/H99hGDRjDYdvH9U9SH7tmPzhM5Qahg8n3+Xed1mJVYw+UE/OUrgrZHCO78xzi+yr0WfA=
      - secure: ULR9ati7fBln4wh6az6WjsZFrvwybW2cq6XdLNnZ5jrsxvusS3Ui1KZ1LFyeBN2s2F4poi4KYSk6no5vF7LpbV0XXqm2Drg3zR2eaMBA3OBf5WTJdrddmHfy6YbSfr6CR8e5jH9gwM9pyD6WJgRoURK9ugyV/96Y3SKet52NKy0=
      - secure: BaaTlj3aUHqDcxuwS3XUHMWTOws/dhFHP7PERWG6Ed3TZDLcEXQX4Dde9PStDW0EkM4NlBDIxmbSDjScfHZi2RJ7U8rSMcJS88BhIiOIgzcsIn1C0Oo1u+c/B2zL5wDN5LKqKpQ80UG68iAo+pJY1H3VxRCbgA4OuMAR1wCqu44=
    
  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 $encrypted_44f58251b904_key $encrypted_44f58251b904_iv
    
  5. Create a settings.xml in your repository with the following contents:
    .travis/settings.xml
    
    
  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.