Skip to content

Commit aba2d2f

Browse files
authored
Merge pull request #398 from mockito/sf--ci
Enabled releases to Central
2 parents 398e0f2 + d91b926 commit aba2d2f

File tree

3 files changed

+110
-42
lines changed

3 files changed

+110
-42
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ jobs:
7272
java-version: 8
7373

7474
- name: Build and publish to Bintray/MavenCentral
75-
run: ./gradlew # TODO fix the release build
75+
run: ./gradlew writeActualVersion
76+
&& export PROJECT_VERSION=`cat version.actual`
77+
&& ./build.sh
78+
&& ./gradlew publishToSonatype githubRelease closeAndReleaseStagingRepository releaseSummary
7679
env:
80+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
7781
NEXUS_TOKEN_USER: ${{secrets.NEXUS_TOKEN_USER}}
7882
NEXUS_TOKEN_PWD: ${{secrets.NEXUS_TOKEN_PWD}}
83+
PGP_KEY: ${{secrets.PGP_KEY}}
84+
PGP_PWD: ${{secrets.PGP_PWD}}

build.gradle

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,114 @@ buildscript {
88
//Using buildscript.classpath so that we can resolve plugins from maven local, during local testing
99
classpath "org.shipkit:shipkit-auto-version:1.+"
1010
classpath "org.shipkit:shipkit-changelog:1.+"
11-
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+"
11+
classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
1212
}
1313
}
1414

15+
group = 'org.mockito'
16+
1517
apply from: "gradle/shipkit.gradle"
1618

17-
task build(type: Exec) {
18-
commandLine "./build.sh"
19-
environment "PROJECT_VERSION", version
19+
apply plugin: "maven-publish"
20+
21+
def pubNames = []
22+
publishing {
23+
publications {
24+
int i = 1
25+
[
26+
"mockito-scala_2.11", "mockito-scala_2.12", "mockito-scala_2.13",
27+
"mockito-scala-cats_2.11", "mockito-scala-cats_2.12", "mockito-scala-cats_2.13",
28+
"mockito-scala-scalatest_2.11", "mockito-scala-scalatest_2.12", "mockito-scala-scalatest_2.13",
29+
"mockito-scala-scalaz_2.11", "mockito-scala-scalaz_2.12", "mockito-scala-scalaz_2.13",
30+
"mockito-scala-specs2_2.11", "mockito-scala-specs2_2.12", "mockito-scala-specs2_2.13",
31+
].each {pub ->
32+
String pubName = "publication${i++}"
33+
pubNames << pubName
34+
"$pubName"(MavenPublication) {
35+
groupId = 'org.mockito'
36+
artifactId = pub
37+
38+
def jarFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}.jar")
39+
artifact jarFile
40+
41+
def srcFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}-sources.jar")
42+
artifact source: srcFile, classifier: "sources"
43+
44+
def jFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}-javadoc.jar")
45+
artifact source: jFile, classifier: "javadoc"
46+
47+
pom {
48+
withXml {
49+
def xml = asString()
50+
xml.setLength(0)
51+
def pomFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}.pom")
52+
assert pomFile.file
53+
xml.append(pomFile.text)
54+
}
55+
}
56+
}
57+
}
58+
}
2059
}
2160

22-
task clean(type: Exec) {
23-
commandLine "./clean.sh"
24-
environment "PROJECT_VERSION", version
61+
apply plugin: 'signing' //https://docs.gradle.org/current/userguide/signing_plugin.html
62+
signing {
63+
if (System.getenv("PGP_KEY")) {
64+
useInMemoryPgpKeys(System.getenv("PGP_KEY"), System.getenv("PGP_PWD"))
65+
pubNames.each {
66+
sign publishing.publications."$it"
67+
}
68+
}
2569
}
70+
71+
apply plugin: "io.github.gradle-nexus.publish-plugin"
72+
73+
nexusPublishing {
74+
repositories {
75+
if (System.getenv("NEXUS_TOKEN_PWD")) {
76+
sonatype {
77+
// Publishing to: https://s01.oss.sonatype.org (faster instance)
78+
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
79+
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
80+
81+
username = System.getenv("NEXUS_TOKEN_USER")
82+
password = System.getenv("NEXUS_TOKEN_PWD")
83+
}
84+
}
85+
}
86+
}
87+
88+
task writeActualVersion {
89+
doLast {
90+
file("version.actual") << "$version"
91+
}
92+
}
93+
94+
def isSnapshot = version.endsWith("-SNAPSHOT")
95+
96+
if (isSnapshot) {
97+
println "Building a -SNAPSHOT version (Github release and Maven Central tasks are skipped)"
98+
tasks.named("githubRelease") {
99+
//snapshot versions do not produce changelog / Github releases
100+
enabled = false
101+
}
102+
tasks.named("closeAndReleaseStagingRepository") {
103+
//snapshot binaries are available in Sonatype without the need to close the staging repo
104+
enabled = false
105+
}
106+
}
107+
108+
tasks.register("releaseSummary") {
109+
doLast {
110+
if (isSnapshot) {
111+
println "RELEASE SUMMARY\n" +
112+
" SNAPSHOTS released to: https://s01.oss.sonatype.org/content/repositories/snapshots/org/mockito/kotlin/mockito-kotlin\n" +
113+
" Release to Maven Central: SKIPPED FOR SNAPSHOTS\n" +
114+
" Github releases: SKIPPED FOR SNAPSHOTS"
115+
} else {
116+
println "RELEASE SUMMARY\n" +
117+
" Release to Maven Central (available after delay): https://repo1.maven.org/maven2/org/mockito/kotlin/mockito-kotlin/\n" +
118+
" Github releases: https://github.com/mockito/mockito-kotlin/releases"
119+
}
120+
}
121+
}

gradle/shipkit.gradle

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,3 @@ tasks.named("githubRelease") {
1616
githubToken = System.getenv("GITHUB_TOKEN")
1717
newTagRevision = System.getenv("GITHUB_SHA")
1818
}
19-
20-
apply plugin: 'com.jfrog.bintray'
21-
22-
//Bintray configuration is handled by JFrog Bintray Gradle Plugin
23-
//For reference see the official documentation: https://github.com/bintray/gradle-bintray-plugin
24-
bintray {
25-
26-
key = System.getenv("BINTRAY_API_KEY")
27-
28-
pkg {
29-
repo = 'maven'
30-
user = 'szczepiq'
31-
name = 'mockito-scala'
32-
userOrg = 'mockito'
33-
licenses = ['MIT']
34-
labels = ['mocks', 'tdd', 'unit tests']
35-
publish = true // can be changed to 'false' for testing
36-
dryRun = project.hasProperty("bintrayDryRun")
37-
38-
filesSpec {
39-
// all contents of this directory will be uploaded to Bintray
40-
from fileTree("target/dist")
41-
into '.'
42-
}
43-
44-
version {
45-
mavenCentralSync {
46-
//sync = true // enable after #351 is fixed. In the meantime, we will publish to Maven Central from Bintray UI
47-
user = System.env.NEXUS_TOKEN_USER
48-
password = System.env.NEXUS_TOKEN_PWD
49-
}
50-
}
51-
}
52-
}

0 commit comments

Comments
 (0)