-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.gradle
136 lines (125 loc) · 4.87 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
plugins {
id 'signing'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
ext {
githubRepo = "github.com/ProtonVPN/go-vpn-lib"
}
import groovy.json.JsonOutput
task publishSlack {
doLast {
Helpers.notifyPublishOnSlack()
}
}
afterEvaluate {
publishing {
publications {
govpn(MavenPublication) {
groupId 'me.proton.vpn'
artifactId 'go-vpn-lib'
version Helpers.getFullVersionName()
artifact("artifacts/govpn.aar")
artifact("artifacts/govpn-sources.jar") { classifier = "sources" }
signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.govpn
}
pom {
name = "me.proton.vpn:go-vpn-lib"
description = "Go library with shared code for ProtonVPN clients"
url = "https://${githubRepo}"
licenses {
license {
name = "GNU GENERAL PUBLIC LICENSE, Version 3.0"
url = "https://www.gnu.org/licenses/gpl-3.0.en.html"
}
}
developers {
developer {
id = "opensource@proton.me"
name = "Open Source Proton"
email = "opensource@proton.me"
}
}
scm {
connection = "scm:git:git://${githubRepo}.git"
developerConnection = "scm:git:ssh://${githubRepo}.git"
url = "https://${githubRepo}"
}
}
}
}
repositories {
def sonatypeUser = System.getenv("SONATYPE_USER")
if (sonatypeUser != null) {
maven {
url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username sonatypeUser
password System.getenv("SONATYPE_PASSWORD")
}
}
}
}
}
}
class Helpers {
static String getFullVersionName() {
// Find last tag in the form M.m.D, D is optional. Add number of commits from that tag to D to form final
// version name
def tag = exec('git tag --merged HEAD').trim().split('\n').reverse().find { it.matches('\\d+(\\.\\d+){1,2}') }
def tagSplit = Arrays.stream(tag.split("\\.")).mapToInt { it.toInteger() }.toArray()
def major = tagSplit[0]
def minor = tagSplit[1]
def dev = tagSplit.size() > 2 ? tagSplit[2] : 0
dev += exec(["bash", "-c", "git log --first-parent ${tag}..HEAD --oneline | wc -l"]).trim().toInteger()
return "${major}.${minor}.${dev}"
}
static String getReleaseNotes(int trimAt) {
def lastSha = System.getenv("CI_COMMIT_BEFORE_SHA")
if (lastSha == null || lastSha.matches("0*"))
return "(empty)"
def notes = exec(["git", "log", "${lastSha}..HEAD", "--pretty=format:- %s"])
if (notes.length() > trimAt)
return notes.take(trimAt) + "\n..."
return notes
}
static void notifyPublishOnSlack() {
def hook = System.getenv("SLACK_PUBLISH_HOOK")
if (hook == null)
return
def json = new JsonOutput().toJson(["text": "<https://github.com/ProtonVPN/go-vpn-lib|go-vpn-lib> ${getFullVersionName()} published\n" +
"Release notes:\n" +
"${getReleaseNotes(1000)}"])
exec(["curl", "-X", "POST", "-H", "'Content-type: application/json'", "--data", json, hook])
}
static String exec(String cmd, boolean throwOnError = true) {
def out = new StringBuffer()
def err = new StringBuffer()
def proc = cmd.execute()
proc.waitForProcessOutput(out, err)
if (proc.exitValue() != 0) {
if (throwOnError)
throw new GradleScriptException("Error executing: ${cmd}", new RuntimeException(err.toString()))
else
return null
}
return out.toString()
}
static String exec(ArrayList<String> cmd, boolean throwOnError = true) {
def out = new StringBuffer()
def err = new StringBuffer()
def proc = cmd.execute()
proc.waitForProcessOutput(out, err)
if (proc.exitValue() != 0) {
if (throwOnError)
throw new GradleScriptException("Error executing: ${cmd}", new RuntimeException(err.toString()))
else
return null
}
return out.toString()
}
}