Skip to content

Commit

Permalink
Set up release process
Browse files Browse the repository at this point in the history
  • Loading branch information
sigiesec committed Aug 14, 2018
1 parent 7586083 commit 1fd7d73
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 382 deletions.
12 changes: 11 additions & 1 deletion .travis.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
<servers>
<server>
<id>jcenter</id>
<username>sigiesec</username>
<username>sigiesec</username>
<password>${env.JCENTER_TOKEN}</password>
</server>
<server>
<id>jcenter-release</id>
<username>sigiesec</username>
<password>${env.JCENTER_TOKEN}</password>
</server>
<server>
<id>github.com</id>
<username>sigiesec</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
23 changes: 16 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ after_success:

# based on https://blog.travis-ci.com/2017-03-30-deploy-maven-travis-ci-packagecloud/
deploy:
provider: script
script: "cp .travis.settings.xml $HOME/.m2/settings.xml && chmod +x deploy.sh && ./deploy.sh"
skip_cleanup: true
on:
repo: btc-ag/service-idl
all_branches: true
# tags: true
- provider: script
script: "./deploy.sh"
skip_cleanup: true
on:
repo: btc-ag/service-idl
all_branches: true
- provider: releases
api_key:
secure: sBBKOHsfxDuoMzjoqGAh3Ps6BUL0/3YuWYQKofYexzNYGffCiDWNaW2tX49MwIVzNZEbIHgi1m1e7gcqJ66RhfypyATaAA4N8jaT9QYI8l/SH73ZEuCnknf1J4vNyJi3Ml5cUWvFrrIJBBok7WX7HFofGXiOozJ9PcGJ8EknRxeMQXpOSXFztOIRUraDm30oh7nBEvTGjW0Pl0sG3d771Ez9C163hbcatvsihfJt+/7K0pwz77fM4nLRnLQcktrSou1phbeg064zRU4PAPm7iozxHfSKLX+/Ci6+IHiFiSbBVYi4MauP1Xw2nvcXWKUbahTGS3DCjKRTrL53OFOy0Qc1Hk0nGBuZqtPJ/EvV7f4FJJ1Y9Lu769YcFoB20ZnNnwsvtiSkdZO5w5Jwi9VWmInV6QOqc0RuhH7La+f4gD0SoB845tEADYLqYurITif5lnJEE+Q+MgbdcbmyVQU+4smj03gRcL9KIm8WMWuwCODr5IhsvA6EYO9ElGgpNjhTkOTBpaR/LWIz570syYHCEyHw8eqo/78roHy6+5MHoFZZwA0Ok+0Jw8HN6i78s5vQKJQXWEDNqyl/znuQ1dd1D+gh3C5BscsmHNz8iFoxrt2iFYkupRIL6Lnuu+d5ve8T9tDUCA2wZHqPlDagI/H/NvrUDgu8p1Zb4QH5UDo/3eE=
file_glob: true
file:
- "${TRAVIS_BUILD_DIR}/com.btc.serviceidl.plainjava/target/com.btc.serviceidl.plainjava-*.jar"
skip_cleanup: true
on:
repo: btc-ag/service-idl
tags: true
80 changes: 67 additions & 13 deletions deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,79 @@
#!/bin/bash
set -x -e

BASE_VERSION=1.0.0

if [ "$TRAVIS" != "true" ] ; then
echo "Not running on travis, not supported at the moment"
exit 1
fi

if [ "$TRAVIS_PULL_REQUEST" == "false" ] ; then
if [ "$TRAVIS_BRANCH" != "master" ] ; then
BRANCH_FRAGMENT="-${TRAVIS_BRANCH////-}"
else
BRANCH_FRAGMENT=""
cp .travis.settings.xml $HOME/.m2/settings.xml

if [[ "$TRAVIS_BRANCH" =~ ^release/ ]] ; then
RELEASE_VERSION=$(echo "$TRAVIS_BRANCH" | sed -e "s/release[/]//")

if ! [[ "${RELEASE_VERSION}" =~ [0-9]+[.][0-9]+[.][0-9]+ ]] ; then
echo "Invalid branch name: $TRAVIS_BRANCH"
exit 1
fi

POM_VERSION=`mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }'`

if [ "${RELEASE_VERSION}-SNAPSHOT" != "${POM_VERSION}" ] ; then
echo "Branch version ${RELEASE_VERSION} is not a SNAPSHOT or does not match POM version ${POM_VERSION}, assuming release was already done"
exit 0
fi
else
BRANCH_FRAGMENT="-pr${TRAVIS_PULL_REQUEST}"
fi

SNAPSHOT_FRAGMENT="-SNAPSHOT" # TODO suppress on a release tag
# MANIFEST.MF files might have been modified during previous steps, so we need to revert
# these changes before release:prepare
git stash save

cd com.btc.serviceidl.plainjava && mvn versions:set -DnewVersion=${BASE_VERSION}${BRANCH_FRAGMENT}${SNAPSHOT_FRAGMENT}
# Unshallow local repo to allow mvn release to work
git fetch --unshallow
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

mvn deploy -DskipTests
# Checkout branch (travis-ci has checked out the commit hash)
# Note: if the branch has been updated in between, this will use a newer
# revision than before, but for making the release this should not usually
# happen, and should not matter anyway, since the newer revision would be
# used by a subsequent build and overwrite the tag
git checkout $TRAVIS_BRANCH

DEVELOPMENT_VERSION=$(python -c 'version = tuple(map(int, ("'${RELEASE_VERSION}'".split(".")))); print("%i.%i.%i" % (version[0], version[1]+1, 0))')

mvn -B release:prepare -DreleaseVersion=${RELEASE_VERSION} -DdevelopmentVersion=${DEVELOPMENT_VERSION}-SNAPSHOT

git config remote.origin.url https://sigiesec:${GITHUB_TOKEN}@github.com/btc-ag/service-idl.git
git push origin v${RELEASE_VERSION}
git push

curl --fail -u sigiesec:${GITHUB_TOKEN} -X POST -d '{"title":"Start next development iteration after '${RELEASE_VERSION}' release", "base":"master", "head":"'${TRAVIS_BRANCH}'"}' https://api.github.com/repos/btc-ag/service-idl/pulls
elif [ "$TRAVIS_TAG" == "" ] ; then
SNAPSHOT_FRAGMENT="-SNAPSHOT"
BASE_VERSION=`mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }' | sed -e 's/-SNAPSHOT//'`

if [ "$TRAVIS_PULL_REQUEST" == "false" ] ; then
if [ "$TRAVIS_BRANCH" != "master" ] ; then
BRANCH_FRAGMENT="-${TRAVIS_BRANCH////-}"
else
BRANCH_FRAGMENT=""
fi
else
BRANCH_FRAGMENT="-pr${TRAVIS_PULL_REQUEST}"
fi

cd com.btc.serviceidl.plainjava && mvn versions:set -DnewVersion=${BASE_VERSION}${BRANCH_FRAGMENT}${SNAPSHOT_FRAGMENT}

mvn deploy -DskipTests
else
# TODO alternatively, release:perform could be executed, but this would check out the same version that we are building right now;
# or, we could run this in the branch build job, and do nothing in the tag build job; the latter would allow us to only push the branch changes if the release was successful

## write release.properties file, since the tag cannot be specified on the command line
#echo scm.url=scm:git:https://github.com/btc-ag/service-idl.git >release.properties
#echo scm.tag=${TRAVIS_TAG} >>release.properties
#rm .meta/p2-artifacts.properties
#mvn -B release:perform

mvn deploy -DskipTests
fi
Loading

0 comments on commit 1fd7d73

Please sign in to comment.