Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Setup automatic publishing to Bintray (jcenter). (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zinnatullin authored Apr 13, 2017
1 parent ca9ab51 commit a9eac90
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 11 deletions.
35 changes: 34 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ buildscript {

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
classpath "org.junit.platform:junit-platform-gradle-plugin:$versions.junitPlatform"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
}

Expand All @@ -23,3 +24,35 @@ allprojects {

apply plugin: 'com.github.ben-manes.versions'
}

def gitTag() {
def tag = 'git tag --list --points-at HEAD'.execute((List) null, rootProject.projectDir).text.trim()

if (tag.split(System.lineSeparator()).length > 1) {
throw new IllegalStateException("gitTag is accessed but commit has multiple tags: $tag")
}

return tag
}

def projectVersion() {
def tag = gitTag()

if (tag.startsWith('v')) {
return tag.substring(1)
} else if (tag.isEmpty()) {
return "development"
}

return tag
}

def validateTagAndVersion() {
if (gitTag().isEmpty()) {
throw new IllegalStateException('Publishing is not allowed because current commit has no tag')
}

if (projectVersion().isEmpty()) {
throw new IllegalStateException('Publishing is not allowed because current projectVersion is empty')
}
}
27 changes: 18 additions & 9 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -xe
set -e

# You can run it from any directory.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Expand All @@ -11,23 +11,32 @@ pushd "$PROJECT_DIR"
USER_ID=`id -u $USER`

BUILD_COMMAND="set -xe && "
BUILD_COMMAND+="apt-get update && apt-get -y install sudo && "
BUILD_COMMAND+="groupadd --gid $USER_ID build_user && "
BUILD_COMMAND+="useradd --shell /bin/bash --uid $USER_ID --gid $USER_ID --create-home build_user && "
BUILD_COMMAND+="sudo --set-home --preserve-env -u build_user "
BUILD_COMMAND+="apt-get update && apt-get --assume-yes install git && "

if [ "$USER_ID" == "0" ]; then
echo "Warning: running as r00t."
else
BUILD_COMMAND+="apt-get --assume-yes install sudo && "
BUILD_COMMAND+="groupadd --gid $USER_ID build_user && "
BUILD_COMMAND+="useradd --shell /bin/bash --uid $USER_ID --gid $USER_ID --create-home build_user && "
BUILD_COMMAND+="sudo --set-home --preserve-env -u build_user "
fi

BUILD_COMMAND+="/opt/project/gradlew "
BUILD_COMMAND+="--no-daemon --info "
BUILD_COMMAND+="--no-daemon --info --stacktrace "
BUILD_COMMAND+="clean build "

if [ "$PUBLISH" = "true" ]; then
BUILD_COMMAND+="artifactoryPublish "
if [ "$PUBLISH" == "true" ]; then
BUILD_COMMAND+="bintrayUpload "
fi

BUILD_COMMAND+="--project-dir /opt/project"

docker run \
-v `"pwd"`:/opt/project \
--env BINTRAY_USER="$BINTRAY_USER" \
--env BINTRAY_API_KEY="$BINTRAY_API_KEY" \
--env BINTRAY_GPG_PASSPHRASE="$BINTRAY_GPG_PASSPHRASE" \
--volume `"pwd"`:/opt/project \
openjdk:8u121-jdk \
bash -c "$BUILD_COMMAND"

Expand Down
88 changes: 87 additions & 1 deletion swarmer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

mainClassName = 'com.gojuno.swarmer.MainKt'

Expand All @@ -19,7 +22,7 @@ dependencies {
}

jar {
// Build "fat" jar.
// Build jar with dependencies.
from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
Expand All @@ -40,3 +43,86 @@ junitPlatform {
}
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

task validatePublishing {
doLast {
validateTagAndVersion()
}
}

bintrayUpload.dependsOn validatePublishing

def pomConfig = {
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'gojuno'
name 'Juno Inc.'
email '[email protected]'
}
}
}

publishing {
publications {
SwarmerPublication(MavenPublication) {
from components.java

artifact sourcesJar
artifact javadocJar

groupId 'com.gojuno.swarmer'
artifactId 'swarmer'
version projectVersion()

pom.withXml {
def root = asNode()
root.appendNode('description', 'Tool to create and start multiple Android Emulators in parallel.')
root.appendNode('name', 'Swarmer')
root.appendNode('url', 'https://github.com/gojuno/swarmer')
root.children().last() + pomConfig
}
}
}
}

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_API_KEY')
publish = true

pkg {
repo = 'maven'
name = 'swarmer'
licenses = ['Apache-2.0']
vcsUrl = 'https://github.com/gojuno/swarmer.git'
issueTrackerUrl = 'https://github.com/gojuno/swarmer/issues'
publications = ['SwarmerPublication']

version {
name = projectVersion()
vcsTag = gitTag()

gpg {
sign = true
passphrase = System.getenv('BINTRAY_GPG_PASSPHRASE')
}
}
}
}

0 comments on commit a9eac90

Please sign in to comment.