Skip to content

Commit da1df1f

Browse files
authored
Merge pull request #39 from kritika-singh3/github-release
GitHub release tasks automation
2 parents 3dc15ca + 4de4f2e commit da1df1f

File tree

8 files changed

+358
-39
lines changed

8 files changed

+358
-39
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Intellij files
2-
.idea/
2+
.idea/*
3+
!.idea/copyright
34

45
# gradle's output dir
56
build/

.idea/copyright/Apache_2_0.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ThoughtWorks, Inc.
2+
* Copyright 2019 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,17 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17+
plugins {
18+
id 'co.riiid.gradle' version '0.4.2'
19+
}
20+
1721
apply plugin: 'java'
18-
apply from: 'plugin-common.gradle'
22+
apply from: 'plugin-helpers.gradle'
23+
24+
sourceCompatibility = 1.8
25+
targetCompatibility = 1.8
1926

2027
project.ext.pluginVersion = '2.2.0'
21-
project.ext.fullVersion = project.distVersion ? "${project.pluginVersion}-${project.distVersion}" : project.pluginVersion
28+
project.ext.fullVersion = project.git.distVersion() ? "${project.pluginVersion}-${project.git.distVersion()}" : project.pluginVersion
2229

2330
version = project.fullVersion
2431
group = 'cd.go'
2532

2633
project.ext.pluginDesc = [
2734
id : 'cd.go.authorization.github',
35+
repo : rootProject.name,
2836
version : project.fullVersion,
2937
goCdVersion: '17.5.0',
3038
name : 'GitHub OAuth authorization plugin',
@@ -53,18 +61,6 @@ dependencies {
5361
testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.12.0'
5462
}
5563

56-
processResources {
57-
from("src/main/resource-templates") {
58-
filesMatching('plugin.xml') {
59-
expand project.pluginDesc
60-
}
61-
62-
filesMatching('plugin.properties') {
63-
expand project.pluginDesc
64-
}
65-
}
66-
}
67-
6864
sourceSets {
6965
test {
7066
java {
@@ -85,25 +81,4 @@ jar {
8581
// }
8682
}
8783

88-
tasks.withType(Jar) { jarTask ->
89-
preserveFileTimestamps = false
90-
reproducibleFileOrder = true
91-
92-
['MD5', 'SHA1', 'SHA-256'].each { algo ->
93-
jarTask.outputs.files("${jarTask.archivePath}.${algo}")
94-
jarTask.doLast {
95-
ant.checksum file: jarTask.archivePath, format: 'MD5SUM', algorithm: algo
96-
}
97-
}
98-
99-
manifest {
100-
attributes(
101-
'Go-Version': project.pluginDesc.goCdVersion,
102-
'Plugin-Revision': project.pluginDesc.version,
103-
'Implementation-Title': project.name,
104-
'Implementation-Version': project.version,
105-
'Source-Compatibility': project.sourceCompatibility,
106-
'Target-Compatibility': project.targetCompatibility
107-
)
108-
}
109-
}
84+
apply from: 'plugin-tasks.gradle'

gradle/wrapper/gradle-wrapper.jar

0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

plugin-helpers.gradle

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2017 ThoughtWorks, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.text.DecimalFormat
17+
18+
static String gitRevision() {
19+
def process = "git log -n 1 --format=%H".execute()
20+
process.waitFor()
21+
return process.text.stripIndent().trim()
22+
}
23+
24+
static String distVersion() {
25+
def process = "git rev-list --count HEAD".execute()
26+
process.waitFor()
27+
return process.text.stripIndent().trim()
28+
}
29+
30+
static def getLastTag(boolean isExperimental) {
31+
try {
32+
def command = ["git", "describe", "--tags", "--abbrev=0"]
33+
if (!isExperimental) {
34+
command.add(command.size() - 1, '--match=*[^-exp]')
35+
}
36+
37+
def process = command.join(" ").execute()
38+
process.waitFor()
39+
def result = process.text
40+
41+
return result.trim()
42+
} catch (Exception e) {
43+
return null
44+
}
45+
}
46+
47+
String getCommitsSinceLastTag(String from) {
48+
def hashStdOut = new ByteArrayOutputStream()
49+
def hashErrorOutput = new ByteArrayOutputStream()
50+
def commandToExecute = ["git", "log", "--no-merges", "--pretty=\"%h - %s\""]
51+
if (from) {
52+
commandToExecute.add("${from}..HEAD")
53+
}
54+
55+
try {
56+
project.exec {
57+
commandLine commandToExecute
58+
standardOutput = hashStdOut
59+
errorOutput = hashErrorOutput
60+
}
61+
} catch (Exception e) {
62+
throw new GradleScriptException(hashErrorOutput.toString(), e)
63+
}
64+
65+
return hashStdOut.toString().trim()
66+
}
67+
68+
static String readableFileSize(long size) {
69+
if (size <= 0) return "0"
70+
final String[] units = ["B", "KB", "MB", "GB", "TB"]
71+
int digitGroups = (int) (Math.log10(size) / Math.log10(1024))
72+
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]
73+
}
74+
75+
project.ext.git = {
76+
gitRevision = this.&gitRevision
77+
distVersion = this.&distVersion
78+
getLastTag = this.&getLastTag
79+
getCommitsSinceLastTag = this.&getCommitsSinceLastTag
80+
readableFileSize = this.&readableFileSize
81+
}

0 commit comments

Comments
 (0)