Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Automate the release
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasheine committed Mar 7, 2018
1 parent 76dfc20 commit 31eb2e6
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 4 deletions.
114 changes: 110 additions & 4 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,128 @@
apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'org.ajoberstar.github-pages'

ext {
websiteUrl = 'https://github.com/novoda/gradle-build-properties-plugin'
}

version = '0.3'
String tag = "v$project.version"
groovydoc.docTitle = 'Build Properties Plugin'

publish {
userOrg = 'novoda'
groupId = 'com.novoda'
artifactId = 'gradle-build-properties-plugin'
publishVersion = project.version
website = 'https://github.com/novoda/gradle-build-properties-plugin'
website = websiteUrl
}

githubPages {
commitMessage = "Deploy groovydoc for release $tag"
pages {
from groovydoc.destinationDir
into "docs/${project.version}"
}
}

pluginBundle {
website = websiteUrl
vcsUrl = websiteUrl
description = 'A Gradle plugin to consume external build properties.'
tags = ['java', 'android', 'gradle', 'build properties', 'project properties', "system properties"]

plugins {
gradleBuildPropertiesPlugin {
id = 'com.novoda.build-properties'
displayName = 'Gradle build properties plugin'
}
}
}

task prepareGhCredentials {
description = 'Prepare GitHub credentials'
group = 'release'
doLast {
String username = System.getenv()['GITHUB_USERNAME']
String password = System.getenv()['GITHUB_TOKEN']
System.properties['org.ajoberstar.grgit.auth.username'] = username
System.properties['org.ajoberstar.grgit.auth.password'] = password
}
}

prepareGhPages.dependsOn groovydoc
publishGhPages.dependsOn prepareGhCredentials

task prepareGradlePluginsRepoRelease {
doLast {
System.properties['gradle.publish.key'] = System.getenv()['GRADLE_PLUGINS_REPO_KEY']
System.properties['gradle.publish.secret'] = System.getenv()['GRADLE_PLUGINS_REPO_SECRET']
}
}

task prepareRelease {
description = 'Prepare changelog and tag for release'
group = 'release'
dependsOn prepareGhPages, prepareGhCredentials, prepareGradlePluginsRepoRelease
doLast {
String changelog = extractChangelog()
grgit.tag.add {
name = tag
message = "Release $tag\n\n$changelog"
}
}
}

String extractChangelog() {
String fullChangelog = rootProject.file('CHANGELOG.md').text
def latestChangelog = (fullChangelog =~ /\[Version ${project.version}.*\n-*([\s\S]*?)\[Version.*\n-*/)
if (latestChangelog.size() > 0) {
return latestChangelog[0][1].trim()
}

def firstChangelog = (fullChangelog =~ /\[Version ${project.version}.*\n-*([\s\S]*)/)
if (firstChangelog.size() > 0) {
return firstChangelog[0][1].trim()
}
throw new GradleException("No changelog found for version $project.version")
}

task printChangelog {
group = 'help'
description = "Print the provisional changelog for version $project.version"
doLast {
println "\nChangelog for version $project.version:\n${extractChangelog()}\n"
}
}

task publishArtifact {
description = "Publish artifact for plugin version: $tag"
group = 'release'
project.afterEvaluate { dependsOn bintrayUpload }
mustRunAfter prepareRelease
}

task publishGroovydoc {
description = "Deploy groovydoc for plugin version: $tag"
group = 'release'
dependsOn publishGhPages
mustRunAfter publishArtifact
}

task publishRelease {
description = "Publish release for plugin version: $tag"
group = 'release'

if (project.hasProperty('dryRun') && project['dryRun'] == 'false') {
dependsOn bintrayUpload
dependsOn prepareRelease, publishArtifact, publishGroovydoc, publishPlugins
doLast {
grgit.push {
tags = true
}
}
} else {
dependsOn publishArtifact
}

}

5 changes: 5 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.novoda:bintray-release:0.4.0'
classpath 'com.gradle.publish:plugin-publish-plugin:0.9.10'
classpath 'org.ajoberstar:gradle-git:1.6.0'
}
}

Expand Down

0 comments on commit 31eb2e6

Please sign in to comment.