diff --git a/.gitignore b/.gitignore index d1004c2b..21955aea 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ build/ !gradle-wrapper.jar out docker-registry-artifact-plugin.iml +src/main/resources-generated/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6684f6e7..8ff7c595 100644 --- a/build.gradle +++ b/build.gradle @@ -14,31 +14,34 @@ * limitations under the License. */ -plugins { - id 'co.riiid.gradle' version '0.4.2' -} - apply plugin: 'java' -apply from: 'plugin-helpers.gradle' +apply from: "https://raw.githubusercontent.com/gocd/gocd-plugin-gradle-task-helpers/master/helper.gradle?_=${(int) (new Date().toInstant().epochSecond / 60)}" + +gocdPlugin { + id = 'cd.go.artifact.docker.registry' + pluginVersion = '1.0.0' + goCdVersion = '18.7.0' + name = 'Artifact plugin for docker' + description = 'Plugin allows to push/pull docker image from public or private docker registry' + vendorName = 'ThoughtWorks, Inc.' + vendorUrl = 'https://github.com/gocd/docker-registry-artifact-plugin' + + githubRepo { + owner = System.getenv('GITHUB_USER') ?: 'bob' + repo = 'docker-registry-artifact-plugin' + token = System.getenv('GITHUB_TOKEN') ?: 'bad-token' + } + pluginProject = project + + prerelease = !"No".equalsIgnoreCase(System.getenv('PRERELEASE')) + assetsToRelease = [project.tasks.findByName('jar')] +} sourceCompatibility = 1.8 targetCompatibility = 1.8 -project.ext.pluginVersion = '1.0.0' -project.ext.fullVersion = project.git.distVersion() ? "${project.pluginVersion}-${project.git.distVersion()}" : project.pluginVersion - -version = project.fullVersion -project.ext.pluginDesc = [ - id : 'cd.go.artifact.docker.registry', - repo : rootProject.name, - version : project.version, - goCdVersion: '18.7.0', - name : 'Artifact plugin for docker', - description: 'Plugin allows to push/pull docker image from public or private docker registry', - vendorName : 'GoCD Contributors', - vendorUrl : 'https://github.com/gocd/docker-registry-artifact-plugin' -] +version = gocdPlugin.fullVersion(project) repositories { mavenCentral() @@ -82,4 +85,3 @@ jar { // into "/" // } } -apply from: 'plugin-tasks.gradle' \ No newline at end of file diff --git a/plugin-helpers.gradle b/plugin-helpers.gradle deleted file mode 100644 index de42b6aa..00000000 --- a/plugin-helpers.gradle +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017 ThoughtWorks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import java.text.DecimalFormat - -static String gitRevision() { - def process = "git log -n 1 --format=%H".execute() - process.waitFor() - return process.text.stripIndent().trim() -} - -static String distVersion() { - def process = "git rev-list --count HEAD".execute() - process.waitFor() - return process.text.stripIndent().trim() -} - -static def getLastTag(boolean isExperimental) { - try { - def command = ["git", "describe", "--tags", "--abbrev=0"] - if (!isExperimental) { - command.add(command.size() - 1, '--match=*[^-exp]') - } - - def process = command.join(" ").execute() - process.waitFor() - def result = process.text - - return result.trim() - } catch (Exception e) { - return null - } -} - -String getCommitsSinceLastTag(String from) { - def hashStdOut = new ByteArrayOutputStream() - def hashErrorOutput = new ByteArrayOutputStream() - def commandToExecute = ["git", "log", "--no-merges", "--pretty=\"%h - %s\""] - if (from) { - commandToExecute.add("${from}..HEAD") - } - - try { - project.exec { - commandLine commandToExecute - standardOutput = hashStdOut - errorOutput = hashErrorOutput - } - } catch (Exception e) { - throw new GradleScriptException(hashErrorOutput.toString(), e) - } - - return hashStdOut.toString().trim() -} - -static String readableFileSize(long size) { - if (size <= 0) return "0" - final String[] units = ["B", "KB", "MB", "GB", "TB"] - int digitGroups = (int) (Math.log10(size) / Math.log10(1024)) - return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups] -} - -project.ext.git = { - gitRevision = this.&gitRevision - distVersion = this.&distVersion - getLastTag = this.&getLastTag - getCommitsSinceLastTag = this.&getCommitsSinceLastTag - readableFileSize = this.&readableFileSize -} \ No newline at end of file diff --git a/plugin-tasks.gradle b/plugin-tasks.gradle deleted file mode 100644 index d5f3a8cf..00000000 --- a/plugin-tasks.gradle +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright 2019 ThoughtWorks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import groovy.xml.MarkupBuilder - -processResources { - from("src/main/resource-templates") { - filesMatching('plugin.xml') { - expand project.pluginDesc - } - - filesMatching('plugin.properties') { - expand project.pluginDesc - } - - filesMatching('version.properties') { - expand project.pluginDesc - } - } -} - -project.ext.color = [ - ANSI_BOLD_WHITE: "\u001B[0;1m", - ANSI_RESET : "\u001B[0m", - ANSI_RED : "\u001B[31m", - ANSI_GREEN : "\u001B[32m", - ANSI_YELLOW : "\u001B[33m", - ANSI_WHITE : "\u001B[37m" -] - -project.ext.symbols = [ - CHECK_MARK : "\u2714", - NEUTRAL_FACE: "\u0CA0_\u0CA0", - X_MARK : "\u2718" -] - -tasks.withType(JavaCompile) { - options.deprecation = true - options.encoding = 'utf-8' - options.warnings = true - options.compilerArgs << "-Xlint:all" - options.compilerArgs << "-Xlint:-serial" -} - -tasks.withType(Jar) { jarTask -> - preserveFileTimestamps = false - reproducibleFileOrder = true - - ['MD5', 'SHA1', 'SHA-256'].each { algo -> - jarTask.outputs.files("${jarTask.archivePath}.${algo}") - jarTask.doLast { - ant.checksum file: jarTask.archivePath, format: 'MD5SUM', algorithm: algo - } - } - - - manifest { - attributes( - 'Go-Version': project.pluginDesc.goCdVersion, - 'Plugin-Revision': project.pluginDesc.version, - 'Implementation-Title': project.name, - 'Implementation-Version': project.version, - 'Source-Compatibility': project.sourceCompatibility, - 'Target-Compatibility': project.targetCompatibility - ) - } -} - -tasks.withType(Test) { - maxParallelForks = 1 - - testLogging { - def previousFailed = false - exceptionFormat 'full' - - beforeSuite { suite -> - if (suite.name.startsWith("Test Run") || suite.name.startsWith("Gradle Worker")) return - - if (suite.parent != null && suite.className != null) { - println(project.color.ANSI_BOLD_WHITE + suite.name + project.color.ANSI_RESET) - } - } - - beforeTest { - if (previousFailed) { - System.err.println("") - } - } - - afterTest { descriptor, result -> - previousFailed = false - def executionTime = (result.endTime - result.startTime) / 1000 - println(" ${resultIndicator(result)}$project.color.ANSI_RESET $descriptor.name $project.color.ANSI_YELLOW($executionTime seconds)$project.color.ANSI_RESET") - - if (result.failedTestCount > 0) { - previousFailed = true - println('') - println(result.exception) - } - } - - afterSuite { desc, result -> - if (desc.parent != null && desc.className != null) { - println("") - } - - if (!desc.parent) { // will match the outermost suite - def failStyle = project.color.ANSI_RED - def skipStyle = project.color.ANSI_YELLOW - def summaryStyle = summaryStyle(result) - - if (result.failedTestCount > 0) { - failStyle = project.color.ANSI_RED - } - if (result.skippedTestCount > 0) { - skipStyle = project.color.ANSI_YELLOW - } - - - println("--------------------------------------------------------------------------") - println("Results: $summaryStyle$result.resultType$project.color.ANSI_RESET ($result.testCount tests, $project.color.ANSI_GREEN$result.successfulTestCount passed$project.color.ANSI_RESET, $failStyle$result.failedTestCount failed$project.color.ANSI_RESET, $skipStyle$result.skippedTestCount skipped$project.color.ANSI_RESET)") - println("--------------------------------------------------------------------------") - } - } - } -} - -private String summaryStyle(result) { - def summaryStyle = project.color.ANSI_WHITE - switch (result.resultType) { - case TestResult.ResultType.SUCCESS: - summaryStyle = project.color.ANSI_GREEN - break - case TestResult.ResultType.FAILURE: - summaryStyle = project.color.ANSI_RED - break - } - summaryStyle -} - -private String resultIndicator(result) { - def indicator = project.color.ANSI_WHITE - - if (result.failedTestCount > 0) { - indicator = project.color.ANSI_RED + project.symbols.X_MARK - } else if (result.skippedTestCount > 0) { - indicator = project.color.ANSI_YELLOW + project.symbols.NEUTRAL_FACE - } else { - indicator = project.color.ANSI_GREEN + project.symbols.CHECK_MARK - } - indicator -} - -task previewGithubRelease() { - doLast { - def prerelease = !"No".equalsIgnoreCase(System.getenv('PRERELEASE')) - def lastTag = project.git.getLastTag(prerelease) - def targetCommitish = project.git.gitRevision() - def assets = jar.outputs.files.files - def tagName = "${project.fullVersion}${prerelease ? '-exp' : ''}" - - def releaseName = "${prerelease ? 'Experimental: ' : ''}${project.fullVersion}" - def changelogHeader = lastTag ? "Changelog ${lastTag}..${project.fullVersion}" : "Changelog" - - def changes = project.git.getCommitsSinceLastTag(lastTag).replaceAll("\"", "").stripIndent().trim() - - def previewFile = file("${project.buildDir}/preview.html") - if (!previewFile.exists()) { - previewFile.createNewFile() - } - def html = new MarkupBuilder(new FileWriter(previewFile)) - html.html { - body { - div { - h1(project.pluginDesc.repo) - h3(releaseName) - div { - b("Tag: ") - span(tagName) - } - div { - b("Commit: ") - span(targetCommitish.substring(0, 7)) - } - - div { - h4("Assets") - assets.each { div(it.getName() + " - " + project.git.readableFileSize(it.length())) } - } - - div { - h4(changelogHeader) - p { - changes.split("\n").each { div(it) } - } - } - } - } - } - } -} - -task deploy() { - dependsOn assemble - description 'Run ./gradlew deploy -Pserver_path=~/gocd to deploy plugin' - doLast { - if (project.hasProperty('server_path')) { - def server_path = "$server_path" - delete "$server_path/*.jar.*" - project.copy { - from "$project.buildDir/libs/" - include "*.jar" - into server_path - } - } else { - throw new GradleScriptException('Run ./gradlew deploy -Pserver_path=~/gocd to deploy plugin', null) - } - } -} - -previewGithubRelease.dependsOn assemble -githubRelease.dependsOn previewGithubRelease - -github { - def lastCommit = project.git.gitRevision() - owner = System.getenv('GITHUB_USER') ?: 'bob' - repo = project.pluginDesc.repo - token = System.getenv('GITHUB_TOKEN') ?: 'bad-token' - targetCommitish = lastCommit - assets = jar.outputs.files.files - - prerelease = !"No".equalsIgnoreCase(System.getenv('PRERELEASE')) - tagName = "${project.fullVersion}${prerelease ? '-exp' : ''}" - name = "${prerelease ? 'Experimental: ' : ''}${project.fullVersion}" - def lastTag = project.git.getLastTag(prerelease) - def changelogHeader = lastTag ? "### Changelog ${lastTag}..${lastCommit.substring(0, 7)}" : "### Changelog" - def changeLog = project.git.getCommitsSinceLastTag(lastTag).replaceAll("\"", "") - - body = """\n$changelogHeader\n\n${changeLog}\n""".stripIndent().trim() -} \ No newline at end of file diff --git a/src/main/resource-templates/plugin.properties b/src/main/resource-templates/plugin.properties deleted file mode 100644 index ab0a9338..00000000 --- a/src/main/resource-templates/plugin.properties +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2017 ThoughtWorks, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -name=${name} -pluginId=${id} -version=${version} diff --git a/src/main/resource-templates/plugin.xml b/src/main/resource-templates/plugin.xml deleted file mode 100644 index 0dea6241..00000000 --- a/src/main/resource-templates/plugin.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - ${name} - ${version} - ${goCdVersion} - ${description} - - ${vendorName} - ${vendorUrl} - - -