Difference between revisions of "Automatic Update Site Uploads"

(Caveats: Fix "Reproducible builds" link)
(Automatic Uploads via Travis CI)
Line 22: Line 22:
 
# Upload the local update site state to your Wiki update site
 
# Upload the local update site state to your Wiki update site
  
As a starting point you can copy the following <code>.travis.yml</code>:
+
As a starting point you can copy the following <code>.travis.yml</code> :
  
 
<source lang="yaml">
 
<source lang="yaml">
 
language: java
 
language: java
 +
sudo: false
 +
 +
cache:
 +
  directories:
 +
    - $HOME/.m2/
 +
 +
install:
 +
  - mvn package
 +
 
script:
 
script:
# These first two commands download the bootstrap.js script
+
   - ./.travis-deploy.sh
# This makes the current directory into a fresh ImageJ.app
+
 
# The status of this ImageJ.app will determine what is uploaded to
+
branches:
# your update site.
+
   only:
   - curl -O http://update.imagej.net/bootstrap.js
+
    - master
  - jrunscript bootstrap.js update-force-pristine
 
# For a Maven-based project inheriting from pom-imagej, this will
 
# build the project and install it (and its dependencies) into the
 
# current ImageJ.app
 
# WARNING: if you would like any files not built by maven to be on your
 
#          update site, you must explicitly move them to the appropriate ImageJ.app
 
#          subdirectory.
 
  - mvn clean install -Dimagej.app.directory="$(pwd)" -Ddelete.other.versions=true
 
# Finally, we download and execute script that uploads to the update site
 
  - curl -O https://raw.githubusercontent.com/fiji/fiji/7f13f66968a9d4622e519c8aae04786db6601314/bin/upload-site-simple.sh
 
  - chmod a+x upload-site-simple.sh
 
# TODO: set your update site and upload account as appropriate
 
   - ./upload-site-simple.sh <UPDATE_SITE> <WIKI_ACCOUNT>
 
# For example, if your wiki account is IJUser and you're uploading to your personal update site (sites.imagej.net/IJUser) you would use:
 
# - ./upload-site-simple.sh IJUser IJUser
 
 
</source>
 
</source>
  
For the update site and wiki account,
+
and this script <code>.travis-deploy.sh</code> :
 +
 
 +
<source lang="bash">
 +
#!/usr/bin/env sh
 +
set -e
 +
 
 +
# Define some variables
 +
export USER="Username"
 +
export UPDATE_SITE="Update_Site"
  
== Encrypting your password ==
+
export IJ_PATH="$HOME/Fiji.app"
 +
export URL="http://sites.imagej.net/$UPDATE_SITE/"
 +
export IJ_LAUNCHER="$IJ_PATH/ImageJ-linux64"
 +
export PATH="$IJ_PATH:$PATH"
  
To upload to your wiki update site, you will need to provide Travis CI with a <code>WIKI_UPLOAD_PASS</code> environment variable, which should evaluate to the [[Special:ChangeUploadPassword|upload password]] of the Wiki account performing the upload. To do so securely, follow the instructions on the [https://docs.travis-ci.com/user/environment-variables/#Encrypting-Variables-Using-a-Public-Key encrypting environment variables].
+
# Install ImageJ
 +
mkdir -p $IJ_PATH/
 +
cd $HOME/
 +
wget --no-check-certificate https://downloads.imagej.net/fiji/latest/fiji-linux64.zip
 +
unzip fiji-linux64.zip
  
Note that when you run:
+
# Install the package
 +
cd $TRAVIS_BUILD_DIR/
 +
mvn clean install -Dimagej.app.directory=$IJ_PATH -Ddelete.other.versions=true
  
<source lang="bash">
+
# Deploy the package
$ travis encrypt WIKI_UPLOAD_PASS=super_secret --add env.matrix
+
$IJ_LAUNCHER --update edit-update-site $UPDATE_SITE $URL "webdav:$USER:$WIKI_UPLOAD_PASS" .
 +
$IJ_LAUNCHER --update upload-complete-site --force --force-shadow $UPDATE_SITE
 
</source>
 
</source>
  
in your repository, the <code>.travis.yml</code> will automatically be updated appropriately. You can simply commit and push the changes.
+
Don't forget to replace
 +
 
 +
<source>
 +
export USER="Username"
 +
export UPDATE_SITE="Update_Site"
 +
</source>
  
== Add additional update sites ==
+
by your informations.
  
By default, only the ImageJ and Fiji update sites will be enabled in the local ImageJ.app. It's possible to enable additional [[List_of_update_sites|update sites]] as needed for your project (for example, if you depend on other 3rd party update sites). To do so, remove the following lines of your <code>.travis.yml</code>:
+
== Encrypting your password ==
  
<source lang="yaml">
+
To upload to your wiki update site, you will need to provide Travis CI with a <code>WIKI_UPLOAD_PASS</code> environment variable, which should evaluate to the [[Special:ChangeUploadPassword|upload password]] of the Wiki account performing the upload. To do so securely, follow the instructions on the [https://docs.travis-ci.com/user/environment-variables/#Encrypting-Variables-Using-a-Public-Key encrypting environment variables].
  - curl -O http://update.imagej.net/bootstrap.js
 
</source>
 
  
Instead, you will need to keep a custom copy of <code>bootstrap.js</code> (e.g. in your repository). In this script, find the following line:
+
Note that when you run:
  
<source lang="javascript">
+
<source lang="bash">
files.addUpdateSite("Fiji", "http://update.fiji.sc/", null, null, -1);
+
$ travis encrypt WIKI_UPLOAD_PASS=super_secret --add env.matrix
 
</source>
 
</source>
  
and add additional calls to <code>addUpdateSite</code> as needed.
+
in your repository, the <code>.travis.yml</code> will automatically be updated appropriately. You can simply commit and push the changes.
  
 
== Non-Mavenized Files ==
 
== Non-Mavenized Files ==

Revision as of 07:23, 14 December 2016


Template:UpdateSites

Requirements

Additional resources

Automatic Uploads via Travis CI

Travis CI can be used to automatically build a repository in response to code changes. To ease the maintenance of ImageJ update sites, we can use Travis to automatically upload the latest version of a site. This is done by creating a .travis.yml file in your update site's GitHub repository that does the following:

  1. Create a fresh ImageJ.app
  2. Build the update site's repository and move the required artifacts (e.g. .jars) to their intended locations in the ImageJ.app
  3. Upload the local update site state to your Wiki update site

As a starting point you can copy the following .travis.yml :

language: java
sudo: false

cache:
  directories:
    - $HOME/.m2/

install:
  - mvn package

script:
  - ./.travis-deploy.sh

branches:
  only:
    - master

and this script .travis-deploy.sh :

#!/usr/bin/env sh
set -e

# Define some variables
export USER="Username"
export UPDATE_SITE="Update_Site"

export IJ_PATH="$HOME/Fiji.app"
export URL="http://sites.imagej.net/$UPDATE_SITE/"
export IJ_LAUNCHER="$IJ_PATH/ImageJ-linux64"
export PATH="$IJ_PATH:$PATH"

# Install ImageJ
mkdir -p $IJ_PATH/
cd $HOME/
wget --no-check-certificate https://downloads.imagej.net/fiji/latest/fiji-linux64.zip
unzip fiji-linux64.zip

# Install the package
cd $TRAVIS_BUILD_DIR/
mvn clean install -Dimagej.app.directory=$IJ_PATH -Ddelete.other.versions=true

# Deploy the package
$IJ_LAUNCHER --update edit-update-site $UPDATE_SITE $URL "webdav:$USER:$WIKI_UPLOAD_PASS" .
$IJ_LAUNCHER --update upload-complete-site --force --force-shadow $UPDATE_SITE

Don't forget to replace

export USER="Username"
export UPDATE_SITE="Update_Site"

by your informations.

Encrypting your password

To upload to your wiki update site, you will need to provide Travis CI with a WIKI_UPLOAD_PASS environment variable, which should evaluate to the upload password of the Wiki account performing the upload. To do so securely, follow the instructions on the encrypting environment variables.

Note that when you run:

$ travis encrypt WIKI_UPLOAD_PASS=super_secret --add env.matrix

in your repository, the .travis.yml will automatically be updated appropriately. You can simply commit and push the changes.

Non-Mavenized Files

Travis CI is capable of building many languages besides Java. If you cannot use Maven with an imagej.app.directory then you need to replace the following line of your .travis.yml:

  - mvn clean install -Dimagej.app.directory="$(pwd)" -Ddelete.other.versions=true

with a sequence of commands that will move your build artifacts to the appropriate /jars or /plugins directory, as appropriate for your update site.

This is also true if you have custom scripts, macros, etc... if these files are not present in the correct locations of the local ImageJ.app, they will appear to have been deleted.

Caveats



See Also