Skip to content

Commit 07b00a9

Browse files
authored
Enabled automated, sequenced releases from Travis CI (#1387)
The goal is to release automatically from Travis and enable convenient merging of PRs, even if many PRs are merged concurrently (bug in Shipkit Gradle plugin: mockito/shipkit#395). - instead of using Shipkit Gradle plugin we keep most CI/CD automation inside Ambry project. This way, it is easier to configure, debug and understand. - we're using a new Gradle plugin "shipkit-auto-version". This plugin automatically deducts the version based on the most recent tag and the "version.properties" file. It is a very simple plugin, keeps the build logic simple, and keeps the Ambry build easy to maintain in the future. This PR removes following features (acceptable trade-offs, we can implement it in the future): - automated release notes generation
1 parent 64b257e commit 07b00a9

File tree

8 files changed

+162
-30
lines changed

8 files changed

+162
-30
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ addons:
1515
packages:
1616
- oracle-java8-installer
1717
- oracle-java8-unlimited-jce-policy
18-
#don't build tags
1918
branches:
20-
except:
19+
except: # don't build tags
2120
- /^v\d/
21+
install: skip # skips unnecessary ./gradlew assemble (https://docs.travis-ci.com/user/job-lifecycle/#skipping-the-installation-phase)
2222
script:
23-
- ./gradlew -s --scan build codeCoverageReport && ./gradlew -s -i --scan ciPerformRelease
23+
- ./travis-build.sh
2424
after_success:
2525
- bash <(curl -s https://codecov.io/bash)

build.gradle

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@
1111
buildscript {
1212
repositories {
1313
mavenCentral()
14+
mavenLocal()
1415
}
1516
apply from: file('gradle/buildscript.gradle'), to: buildscript
1617
}
1718

18-
plugins {
19-
id 'org.shipkit.java' version '2.2.5' apply false
20-
}
21-
if (!project.hasProperty('disableShipkit')) {
22-
apply plugin: 'org.shipkit.java'
23-
}
19+
apply plugin: 'org.shipkit.shipkit-auto-version'
20+
println "Building version $version"
2421

2522
apply from: file('gradle/license.gradle')
2623
apply from: file('gradle/environment.gradle')
2724
apply from: file("gradle/dependency-versions.gradle")
25+
apply from: file("gradle/ci-release.gradle")
2826

2927
allprojects {
3028
group = "com.github.ambry"
29+
version = rootProject.version //TODO: fix in https://github.com/shipkit/org.shipkit.shipkit-auto-version
3130

3231
apply plugin: 'eclipse'
3332
apply plugin: 'idea'
@@ -42,6 +41,8 @@ allprojects {
4241

4342
subprojects {
4443
apply plugin: 'java'
44+
apply from: "$rootDir/gradle/java-publishing.gradle"
45+
4546
sourceCompatibility = 1.8
4647
targetCompatibility = 1.8
4748

@@ -109,22 +110,7 @@ subprojects {
109110
group = 'verification'
110111
}
111112
allTest.dependsOn test
112-
allTest.dependsOn intTest
113-
114-
task testJar(type: Jar, dependsOn: testClasses) {
115-
from sourceSets.test.output
116-
classifier = 'test'
117-
}
118-
119-
artifacts {
120-
archives testJar
121-
}
122-
123-
if (!project.hasProperty('disableShipkit')) {
124-
// add test jars to maven publication if using shipkit
125-
publishing.publications.javaLibrary.artifact testJar
126-
}
127-
113+
allTest.dependsOn intTest
128114
javadoc {
129115
// TODO audit and fix our javadocs so that we don't need this setting
130116
// This is mainly for cases where param/throws tags don't have descriptions

gradle/buildscript.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ repositories {
1717
}
1818

1919
dependencies {
20-
classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.0"
20+
classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.0"
21+
classpath "org.shipkit:shipkit-auto-version:0.0.22"
22+
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
2123
}

gradle/ci-release.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
task bintrayUploadAll {
2+
description = "Runs 'bintrayUpload' tasks from all projects"
3+
mustRunAfter "gitPush" //git push is easier to rollback so we run it first
4+
}
5+
6+
allprojects {
7+
tasks.matching { it.name == "bintrayUpload" }.all {
8+
bintrayUploadAll.dependsOn it
9+
}
10+
}
11+
12+
task ciPerformRelease {
13+
description = "Performs the release, intended to be ran on CI"
14+
dependsOn "gitTag", "gitPush", "bintrayUploadAll"
15+
}
16+
17+
task gitTag {
18+
description = "Creates annotated tag 'v$version'"
19+
20+
doLast {
21+
println "Setting Git user and email to Travis CI"
22+
exec { commandLine "git", "config", "user.email", "travis@travis-ci.org" }
23+
exec { commandLine "git", "config", "user.name", "Travis CI" }
24+
println "Creating tag v$version"
25+
exec { commandLine "git", "tag", "-a", "-m", "Release $version", "v$version" }
26+
println "Created tag v$version"
27+
}
28+
}
29+
30+
task gitPush(type: Exec) {
31+
description = "Pushes tags by running 'git push --tags'. Hides secret key from git push output."
32+
mustRunAfter "gitTag" //tag first, push later
33+
34+
doFirst { println "Pushing tag v$version" }
35+
commandLine "./gradle/git-push.sh", "v$version"
36+
doLast { println "Pushed tag v$version" }
37+
}

gradle/git-push.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
#Git push is implemented in the script to make sure we are not leaking GH key to the output
4+
#Expects 'GIT_SECRET' env variable to be in format: user:github_access_token,
5+
#for example: mockitoguy:qq43234xc23x23d24d
6+
7+
echo "Running git push without output for security. If it fails make sure that GIT_SECRET env variable is set."
8+
git push --quiet https://$GIT_SECRET@github.com/linkedin/ambry.git --tags > /dev/null 2>&1
9+
EXIT_CODE=$?
10+
echo "'git push --quiet' exit code: $EXIT_CODE"
11+
exit $EXIT_CODE

gradle/java-publishing.gradle

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
assert plugins.hasPlugin("java")
2+
3+
apply plugin: 'maven-publish'
4+
apply plugin: 'com.jfrog.bintray'
5+
6+
tasks.withType(Jar) {
7+
from "$rootDir/LICENSE"
8+
from "$rootDir/NOTICE"
9+
}
10+
11+
task sourcesJar(type: Jar, dependsOn: classes) {
12+
classifier = 'sources'
13+
from sourceSets.main.allSource
14+
}
15+
16+
task javadocJar(type: Jar, dependsOn: javadoc) {
17+
classifier = 'javadoc'
18+
from javadoc.destinationDir
19+
}
20+
21+
task testJar(type: Jar, dependsOn: testClasses) {
22+
from sourceSets.test.output
23+
classifier = 'test'
24+
}
25+
26+
artifacts {
27+
archives sourcesJar
28+
archives javadocJar
29+
archives testJar
30+
}
31+
32+
publishing {
33+
publications {
34+
maven(MavenPublication) {
35+
from components.java
36+
37+
artifact javadocJar
38+
artifact sourcesJar
39+
artifact testJar
40+
}
41+
}
42+
}
43+
44+
bintray { //docs: https://github.com/bintray/gradle-bintray-plugin
45+
user = System.getenv("BINTRAY_USER")
46+
key = System.getenv("BINTRAY_API_KEY")
47+
48+
publish = true
49+
dryRun = project.hasProperty("bintray.dryRun")? true : false //useful for testing
50+
51+
publications = ['maven']
52+
53+
pkg {
54+
repo = 'test-repo'
55+
userOrg = 'linkedin'
56+
name = 'ambry'
57+
58+
licenses = ['Apache-2.0']
59+
labels = ['blob storage']
60+
version {
61+
// disable gpg signing to speed up publishing
62+
gpg {
63+
sign = false
64+
}
65+
// disable upload to maven central
66+
mavenCentralSync {
67+
sync = false
68+
}
69+
}
70+
}
71+
}
72+
73+
bintrayUpload {
74+
doFirst {
75+
println "Publishing $jar.baseName to Bintray (dryRun: $dryRun, repo: $repoName, publish: $publish)"
76+
}
77+
}

travis-build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# exit when any command fails
4+
set -e
5+
6+
echo "Building and testing artifacts, and creating pom files"
7+
./gradlew -s --scan build publishToMavenLocal codeCoverageReport
8+
9+
echo "Testing Bintray publication by uploading in dry run mode"
10+
./gradlew -s -i --scan bintrayUploadAll -Pbintray.dryRun
11+
12+
echo "Pull request: [$TRAVIS_PULL_REQUEST], Travis branch: [$TRAVIS_BRANCH]"
13+
# release only from master when no pull request build
14+
if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]
15+
then
16+
echo "Releasing (tagging, uploading to Bintray)"
17+
./gradlew -s -i --scan ciPerformRelease
18+
fi

version.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#Version of the produced binaries. This file is intended to be checked-in.
2-
#It will be automatically bumped by release automation.
3-
version=0.3.110
4-
previousVersion=0.3.109
1+
# shipkit-auto-version Gradle plugin uses this version spec to deduct the version to build
2+
# it increments patch version based on most recent tag.
3+
# You can put explicit version here if needed, e.g. "1.0.0"
4+
# More information: https://github.com/shipkit/shipkit-auto-version/blob/master/README.md
5+
version=0.3.*

0 commit comments

Comments
 (0)