tagged: travis-ci

HockeyApp: Generating release notes from git

The problem with uploading to HockeyApp is the release notes are not automatically created.
And we can create them by looking at all the git commit logs since the last build.
For this to happen we need to know what the last commit was.
Although we can specify this in our upload, when we query the builds we can't get this information back. Instead, we'll add the commit SHA to the release notess.
Our plan will be
  1. Look at the app versions via HockeyApp's API
  2. Find the lastest version
  3. Look at the release notes that and retrieve our added commit SHA
  4. Make git output all our commit logs since then
  5. Make release notes out of that (including the current git commit)
Here's the entire commented shell script:

# We need an initial bullet point for our list of commit logs
echo -n "* "
# Get the latest app uploads
curl -H "X-HockeyAppToken: $HOCKEYAPP_TOKEN" \
"https://rink.hockeyapp.net/api/2/apps/YOUR_HOCKEYAPP_APP_ID/app_versions?page=1" | \
# Put every property on a separate line
sed 's/,/\n/g' | \
# Remove all the quotation marks
sed 's/"//g' | \
# Look at only the notes properties
grep notes | \
# Look at the first one, i.e. the latest app upload
head -n 1 | \
# Find the commit information at the bottom of the notes
sed -n 's/.*(commit:\([^)]*\)).*/\1/p' | \
# Let's find all the logs since that commit
xargs -I '{}' git log {}..HEAD --pretty=format:'%s' --no-merges | \
# Add a star to each newline to make the list
awk '$0="* "$0'
# The end of the revision log must have the latest commit
# This is so later we can do the above again
echo -n "* (commit:" 
git rev-parse HEAD | xargs echo -n
echo -n ')'

And when we upload to HockeyApp, via travis-ci, we can include it like so:

- bash release_notes_for_hockeyapp.sh > release_notes
- >
  -F "status=2"
  -F "notify=1"
  -F "notes=<release_notes"
  -F "notes_type=0"
  -F "ipa=@app/build/outputs/apk/YOUR_APK.apk"
  -H "X-HockeyAppToken: $HOCKEYAPP_TOKEN"

hockeyapp git travis-ci

Android: Upload to HockeyApp on every Travis-CI build

I assume you have setup [HockeyApp](https://newfivefour.com/android-hockeyapp-continuous-deployment.html), that you have setup [Travis-CI](https://newfivefour.com/android-setup-travis-ci.html) and that you have a build which is signed with a [constant keystore signature](https://newfivefour.com/android-debug-build-constant-signed-keystore.html).
If our build is created by the above link, we will need the CI_KEYSTORE_PASSWORD environmental variable to sign the build. Go to your application settings in Travis-CI and create the environmental variable. (Ensure you have not toggled "display value in build log" for privacy)
Now go to account settings on the HockeyApp site, and then click API Tokens and create one with upload access to your application. With that, go to your application on Travis-CI and add another environmental variable, HOCKEYAPP_TOKEN.
Now we have HOCKEYAPP_TOKEN available in our Travis-CI environment, we can add a curl command to our .travis.yml script section to upload our signed build to HockeyApp:

  - >
    -F "status=2"
    -F "notify=1"
    -F "notes=Some new features and fixed bugs."
    -F "notes_type=0"
    -F "ipa=@app/build/outputs/apk/YOUR_SIGNED_BUILD.apk"
    -H "X-HockeyAppToken: $HOCKEYAPP_TOKEN"

Now on every build, we'll upload the APK to HockeyApp, using our HOCKEYAPP_TOKEN, for distribution to our testers.
Note: We are not automatically updating the android versionCode, although putting versionCode System.getenv("TRAVIS_BUILD_NUMBER") as Integer ?: 999 will do that, and the version notes are static, which we can approach in another tutorial.

travis-ci hockeyapp android

Android: Setup Travis-CI

Travis CI is a free continuous integration environment--i.e a container that download everything it needs to build your android project and then builds (and opitionally tests) it--for open source projects.
  1. Create a new Android project using a basic template in Android Studio. I'm using Android Studio 2.1.1.
  2. Optionally add this to your app/build.gradle file so travis-ci doesn't fail on lint errors that may not appear locally if your environment is differnt
     android {
       lintOptions {
           abortOnError false

0. Create a new github project for that and upload your project there, including the gradle wrapper.
0. Now goto https://travis-ci.org and login by pressing the login with your github account button.
0. Click add new repository on travis-ci. Press the sync account button at the top. Now you should be able to enable travis-ci for your new repo by pressing the toggle swich.
0. In your app/build.gradle file note the BuildToolsVersion you're using and the targetSdkVersion
0. Create a file called .travis.yml in your repo and upload it to github
       language: android
       java: oraclejdk8 # We need this if your sdk version is 24
           # Uncomment the lines below if you want to
           # use the latest revision of Android SDK Tools
           - platform-tools
           - tools
           # The BuildTools version used by your project
           - build-tools-YOUR_NOTED_BUILD_TOOLS_VERSION
           # The SDK version used to compile your project
           - android-YOUR_NOTED_TARGET_SDK_VERSION
           # Additional components
           #- extra-google-google_play_services
           - extra-google-m2repository
           - extra-android-m2repository
           - addon-google_apis-google-19
         - ./gradlew build

Now refresh https://travis-ci.org/ and you should see your project building eventually. Click on the #YOURBUILDNUMBER started or #YOURBUILDNUMBER text and you'll be able to follow the console, watching your project build.
You can now add a fun button to your README.md showing your project has built via:

  [![Build Status](https://travis-ci.org/YOURGHUSERNAMEr/YOURPROJECTNAME.svg?branch=master)](https://travis-ci.org/YOURGHUSERNAMEr/YOURPROJECTNAME)

Optionally, if you want to see the lint XML file in travis's console, add this after the - ./gradle build line:

 - cat /home/travis/build/YOURTRAVISUSERNAME/YOURPROJECTNAME/app/build/outputs/lint-results-debug.xml

android travis-ci

Page 1 of 1