diff --git a/gradle/publish.gradle b/gradle/publish.gradle index f705d91..ee553a1 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -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 } - } + diff --git a/plugin/build.gradle b/plugin/build.gradle index e517b1c..e41aee3 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -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' } }