|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +die () { |
| 4 | + echo "$*" >&2 |
| 5 | + exit 1 |
| 6 | +} |
| 7 | + |
| 8 | +simulate= |
| 9 | +while test $# -gt 0 |
| 10 | +do |
| 11 | + case "$1" in |
| 12 | + --simulate) |
| 13 | + simulate=t |
| 14 | + ;; |
| 15 | + *) |
| 16 | + die "Unhandled option: $1" |
| 17 | + ;; |
| 18 | + esac |
| 19 | + shift |
| 20 | +done |
| 21 | + |
| 22 | +url="$(git config remote.origin.url)" || |
| 23 | +die "Could not obtain the current URL" |
| 24 | + |
| 25 | +case "$url" in |
| 26 | +http://github.com/*|https://github.com/*|git://github.com/*|ssh://github.com/*|ssh://git@github.com/*) |
| 27 | + repo=${url#*://*github.com/} |
| 28 | + ;; |
| 29 | +git@github.com:*|github.com:*|github:*) |
| 30 | + repo=${url#*:} |
| 31 | + ;; |
| 32 | +*) |
| 33 | + die "Not a GitHub URL: $url" |
| 34 | + ;; |
| 35 | +esac |
| 36 | +repo=${repo%/} |
| 37 | +repository_url=${repo##*/}-github:$repo |
| 38 | + |
| 39 | +test refs/heads/master = "$(git rev-parse --symbolic-full-name HEAD)" || |
| 40 | +die "Not on master branch!" |
| 41 | + |
| 42 | +git update-index -q --refresh && |
| 43 | +git diff-files --quiet --ignore-submodules && |
| 44 | +git diff-index --cached --quiet --ignore-submodules HEAD -- || |
| 45 | +die "There are uncommitted changes!" |
| 46 | + |
| 47 | +git fetch --tags || |
| 48 | +die "Could not fetch" |
| 49 | + |
| 50 | +commit="$(git rev-parse HEAD)" && |
| 51 | +upstream="$(git rev-parse origin/master)" || |
| 52 | +die "Could not obtain current revision" |
| 53 | + |
| 54 | +test $commit = $upstream || |
| 55 | +die "Not up-to-date: $(printf '\n%s' "$(git log --graph --oneline \ |
| 56 | + --left-right --boundary ...$upstream)")" |
| 57 | + |
| 58 | +pom="$(cat pom.xml)" && |
| 59 | +snapshot="$(echo "$pom" | |
| 60 | + sed -n 's|^ <version>\(.*\)</version>|\1|p')" || |
| 61 | +die "Could not obtain version" |
| 62 | + |
| 63 | +version=${snapshot%-SNAPSHOT} |
| 64 | +test "$version" != "$snapshot" || |
| 65 | +die "Not a -SNAPSHOT version: $snapshot" |
| 66 | + |
| 67 | +jenkins_url=http://jenkins.imagej.net/job/Release-Version/buildWithParameters |
| 68 | +params="REPOSITORY_URL=$repository_url&COMMIT=$commit&VERSION_STRING=$version" |
| 69 | +if test -z "$simulate" |
| 70 | +then |
| 71 | + curl --netrc -X POST "$jenkins_url?$params" |
| 72 | +else |
| 73 | + echo curl --netrc -X POST "$jenkins_url?$params" |
| 74 | +fi |
0 commit comments