Skip to content

Commit

Permalink
build: travis commits the snapshot updates (#142)
Browse files Browse the repository at this point in the history
* build: travis commits the snapshot updates

* build: add echos

* build: remove echo

* build: Upgrade to next snapshot (Build )

* build: update script

* revert pom change
  • Loading branch information
smyrick authored and dariuszkuc committed Jan 14, 2019
1 parent 62b2f96 commit 9e1329c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.iml
.idea
.DS_Store
target
target
pom.xml.versionsBackup
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ deploy:
tags: true
jdk: oraclejdk8

after_deploy:
- .travis/update-version.sh

after_success:
- bash <(curl -s https://codecov.io/bash)

Expand Down
4 changes: 2 additions & 2 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash -x
cd `dirname $0`/..
cd `dirname $0`/..

if [[ -z "$SONATYPE_USERNAME" ]]
then
Expand All @@ -17,7 +17,7 @@ if [[ ! -z "$TRAVIS_TAG" ]]
then
SKIP_GPG_SIGN=false
echo "travis tag is set -> updating pom.xml <version> attribute to $TRAVIS_TAG"
mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=$TRAVIS_TAG 1>/dev/null 2>/dev/null
mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=$TRAVIS_TAG 1>/dev/null 2>/dev/null
else
SKIP_GPG_SIGN=true
echo "no travis tag is set, hence keeping the snapshot version in pom.xml"
Expand Down
84 changes: 84 additions & 0 deletions .travis/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash

cd `dirname $0`/..

setup_git() {
git config --global user.email "[email protected]"
git config --global user.name "Travis CI"
}

update_version() {

exampleProperty="graphql-kotlin.version"

# Push the new tag with `-SNAPSHOT` as the current version
mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion="${TRAVIS_TAG}-SNAPSHOT"

# Increment the patch version
mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set -DnextSnapshot=true

# Pull the value from the pom
NEW_VERSION=$(mvn --settings .travis/settings.xml help:evaluate -Dexpression=project.version -q -DforceStdout)

# Update the example version
cd example/
mvn --settings ../.travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set-property -Dproperty=${exampleProperty} -DnewVersion=${NEW_VERSION}
cd ../
}

commit_files() {

# Use the version as the branch name
git checkout -b ${NEW_VERSION}

# Stage the modified files
git add pom.xml example/pom.xml

# Create a new commit with a custom build message and Travis build number for reference
git commit -m "travis: Upgrade to next snapshot (Build $TRAVIS_BUILD_NUMBER)"
}

upload_files() {

tokenLink="https://${GITHUB_TOKEN}@github.com/ExpediaDotCom/graphql-kotlin.git"

# Add new "origin" with access token in the git URL for authentication
git remote add token-origin ${tokenLink} > /dev/null 2>&1

# Push changes to the new branch
git push --quiet --set-upstream token-origin ${NEW_VERSION}

# Remove the origin to hide the token
git remote rm token-origin > /dev/null 2>&1
}

if [[ -z "$TRAVIS_TAG" ]]
then
echo "ERROR! Please set TRAVIS_TAG environment variable"
exit 1
fi

if [[ -z "$GITHUB_TOKEN" ]]
then
echo "ERROR! Please set GITHUB_TOKEN environment variable"
exit 1
fi

NEW_VERSION=""

setup_git

update_version

commit_files

# Attempt to push to git only if "git commit" succeeded
if [[ $? -eq 0 ]]; then
echo "Uploading to GitHub"
upload_files
else
echo "Nothing to do"
fi



0 comments on commit 9e1329c

Please sign in to comment.