Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.
Marcin Zajączkowski edited this page Jun 15, 2017 · 18 revisions

Welcome to the micro-common-release wiki!

Introduction

micro-common-release is a set of release related Gradle build scripts which simplify the process of releasing the new version of a project. The key idea was to allow releasing project automatically from CI server (Travis is officially supported), but when needed the mechanism can be also used to release the new version manually from the workstation.

There is also a short presentation about micro-common-release.

Getting started

micro-common-release covers 4 steps in the release process.

1. Local release of the new version - release task.

That step include:

  • bumping the project version number
  • making a release commit
  • creating a version tag on created commit

The implementation internally uses Axion release plugin for Gradle.

2a. Upload artifacts to Bintray - finalizeRelease task

The built artifacts are uploaded to the artifacts repository. Currently only Bintray is supported.

2b. Push changes back to Github - finalizeRelase task

The release commit and tag are pushed to GitHub repository.

3. Publish artifacts previously uploaded to Bintray - publishUploadedArtifacts task

Uploaded artifacts are published (accepted) in Bintray and become available for others in Bintray and jcenter (if previously linked).

Trigger the release process

To trigger the release process just put somewhere into the commit message magic command [#DO_RELEASE]. It doesn't have to be in the first line, e.g.

git commit -m "Trigger release" -m "[#DO_RELEASE]" --allow-empty

New project configuration

For testing purposes there was created releasing-sandbox project which can be freely modified and published to test new ideas which require CI server to run. Pay attention that all projects by default use the latest available version of micro-common-release, so it is safer to test risky changes with SNAPSHOT versions.

Elements to configure

  1. Add buildscript dependency to com.ofg:micro-common-release.
  2. Add buildscript dependency to Gradle configuration files available in the package.
  3. Apply version.gradle and configure Axion plugin (scmVersion configuration closure).
  4. Apply publish.gradle and release.gradle.
  5. (Optional) Override default bintray task configuration (e.g. repo name).
  6. (Optional) Override default publishUploadedArtifacts configuration.
  7. Update Travis configuration (.travis.yml).

Note. By default 4financeBot is used to commit (and push) changes. It's group Bots has to have write access to given repository.

Encrypting variables in Travis configuration

Sensitive variables (such as GH_TOKEN or BINTRAY_API_KEY) have to be encrypted before putting into .travis.yml. Travis provides open source command line tool to achieve that. See Travis documentation (the last paragraph) for more details.

Note. Variables are encrypted in the project context. Therefore, they will not work when copied from the another project.

Sample build.gradle configuration

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.ofg:micro-common-release:+"
    }
    dependencies {
        ant.unjar src: configurations.classpath.find { it.name.startsWith("micro-common-release") }, dest: 'build/release'
    }
}

apply from: "${rootProject.buildDir}/release/gradle/version.gradle"

scmVersion {
    tag { prefix='custom-tag-prefix-if-wanted' }
}

project.group = 'com.ofg'
project.version = scmVersion.version

apply plugin: 'groovy'    //or 'java'
apply from: "${rootProject.buildDir}/release/gradle/publish.gradle"
apply from: "${rootProject.buildDir}/release/gradle/release.gradle"

bintray {
    pkg { repo = 'fancy-new-one' }
}

Sample .travis.yml configuration

install:
- true

script:
- set -e
- ./gradlew check --info --stacktrace --continue -Pcoverage -Pcompatibility
- source build/release/gradle/setGitVariables.sh
- ./gradlew release -Prelease.disableRemoteCheck -Prelease.localOnly --info --stacktrace
- ./gradlew finalizeRelease publishUploadedArtifacts -PbintrayUser=${BINTRAY_USER} -PbintrayKey=${BINTRAY_API_KEY} --info --stacktrace

after_success:
- ./gradlew jacocoTestReport coveralls -Pcoverage


language: groovy

jdk:
- oraclejdk8

matrix:
  include:
    # Release not skipped only in Java 7 build
    - jdk: oraclejdk7
      env: SKIP_RELEASE=false

env:
  global:
  - TERM=dumb
  - SKIP_RELEASE=true
  - secure: <<encrypted GH_TOKEN>>
  - secure: <<encrypted BINTRAY_USER>>
  - secure: <<encrypted BINTRAY_API_KEY>>

Manual release

To perform manual release -PlocalRelease flag has to be used. It disables using CI specific variables and configuration. The process can be performed in a few separate steps.

Sample commands:

  1. ./gradlew release -Prelease.localOnly -PlocalRelease
  2. ./gradlew finalizeRelease -PlocalRelease
  3. ./gradlew publishUploadedArtifacts -PlocalRelease

Note. In case of problems with password protected SSH key in step 2 it could be done manually with:

  1. ./gradlew bintrayUpload -PlocalRelease
  2. git push --follow-tags

Limitations

  1. Currently only Travis is supported. Although it should be easy to add support for other CI servers.

Acknowledge

Some parts of build scripts are based on release mechanism created by Szczepan Faber for Mockito.