Skip to content

Commit 8574799

Browse files
setup ci publish and signing (#3)
* setup ci publish and signing * make signing optional based on signing key * use env variables during publish * setup publish and pom description * setup new workflows * gradle properties * add test dependency * enable jacoco and sonar * use hndrs templates
1 parent 114142c commit 8574799

File tree

9 files changed

+194
-30
lines changed

9 files changed

+194
-30
lines changed
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
name: Tests
1+
name: gradle
22

33
# Controls when the action will run.
44
on:
5-
65
pull_request:
76
branches: [ main ]
87

98
# Allows you to run this workflow manually from the Actions tab
109
workflow_dispatch:
1110

12-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1311
jobs:
14-
test:
12+
check:
1513
runs-on: ubuntu-latest
1614

1715
steps:
18-
- name: Git Checkout
16+
- name: git checkout
1917
uses: actions/checkout@v2
2018
with:
2119
fetch-depth: 0
2220

23-
- name: Setup Java
21+
- name: setup java
2422
uses: actions/setup-java@v1
2523
with:
26-
java-version: '15'
24+
java-version: '11'
2725

28-
- name: Setup Build Cache
26+
- name: gradle cache
2927
uses: actions/cache@v2
3028
with:
3129
path: |
@@ -34,6 +32,7 @@ jobs:
3432
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
3533
restore-keys: |
3634
${{ runner.os }}-gradle-
37-
- name: Tests
35+
36+
- name: test
3837
run: |
3938
./gradlew check
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: gradle
2+
3+
# Controls when the action will run.
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: git checkout
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
22+
- name: setup java
23+
uses: actions/setup-java@v1
24+
with:
25+
java-version: '11'
26+
27+
- name: setup build cache
28+
uses: actions/cache@v2
29+
with:
30+
path: |
31+
~/.gradle/caches
32+
~/.gradle/wrapper
33+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
34+
restore-keys: |
35+
${{ runner.os }}-gradle-
36+
37+
- name: publish
38+
env:
39+
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
40+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
41+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
42+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
43+
run: |
44+
./gradlew publish
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: gradle
2+
3+
# Controls when the action will run.
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches: [ main ]
10+
types: [ opened, synchronize, reopened ]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
analyse:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: git checkout
21+
uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 0
24+
25+
- name: setup java
26+
uses: actions/setup-java@v1
27+
with:
28+
java-version: '11'
29+
30+
- name: gradle cache
31+
uses: actions/cache@v2
32+
with:
33+
path: |
34+
~/.gradle/caches
35+
~/.gradle/wrapper
36+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
37+
restore-keys: |
38+
${{ runner.os }}-gradle-
39+
40+
- name: sonar cache
41+
uses: actions/cache@v1
42+
with:
43+
path: ~/.sonar/cache
44+
key: ${{ runner.os }}-sonar
45+
restore-keys: ${{ runner.os }}-sonar
46+
47+
- name: analyse
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
50+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
51+
run: ./gradlew check jacocoTestReport sonarqube --info

build.gradle.kts

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

3-
object Versions {
4-
const val KOTLIN_VERSION = "1.4.30"
5-
}
6-
73
buildscript {
84
repositories {
95
mavenCentral()
@@ -14,27 +10,40 @@ buildscript {
1410
}
1511
}
1612

13+
val springBootDependencies: String by extra
14+
val kotlinVersion: String by extra
15+
1716
plugins {
18-
id("org.sonarqube").version("3.0")
19-
`maven-publish`
20-
id("io.spring.dependency-management") version "1.0.10.RELEASE"
21-
kotlin("jvm").version("1.4.30")
22-
kotlin("plugin.spring").version("1.4.30")
23-
kotlin("kapt").version("1.4.30")
17+
id("org.sonarqube").version("3.1.1")
18+
id("io.spring.dependency-management")
19+
kotlin("jvm")
20+
kotlin("plugin.spring")
21+
kotlin("kapt")
2422
id("java")
2523
id("maven-publish")
2624
id("idea")
25+
id("signing")
26+
id("io.hndrs.publishing-info").version("1.0.0")
2727
}
2828

29-
group = "com.elvah.auth"
29+
group = "io.hndrs"
3030
version = rootProject.file("version.txt").readText().trim()
31-
java.sourceCompatibility = JavaVersion.VERSION_15
32-
java.targetCompatibility = JavaVersion.VERSION_15
31+
java.sourceCompatibility = JavaVersion.VERSION_11
32+
java.targetCompatibility = JavaVersion.VERSION_11
3333

3434
repositories {
3535
mavenCentral()
3636
}
3737

38+
sonarqube {
39+
properties {
40+
property("sonar.projectKey", "hndrs_jsonapi-spring-boot-starter")
41+
property("sonar.organization", "hndrs")
42+
property("sonar.host.url", "https://sonarcloud.io")
43+
property("sonar.exclusions", "**/sample/**")
44+
}
45+
}
46+
3847
subprojects {
3948

4049
apply(plugin = "kotlin")
@@ -46,16 +55,32 @@ subprojects {
4655
apply(plugin = "jacoco")
4756
apply(plugin = "propdeps")
4857
apply(plugin = "propdeps-idea")
49-
50-
58+
apply(plugin = "signing")
59+
apply(plugin = "io.hndrs.publishing-info")
60+
61+
publishingInfo {
62+
url = "https://github.com/hndrs/jsonapi-spring-boot-starter"
63+
license = io.hndrs.gradle.plugin.License(
64+
"https://github.com/hndrs/jsonapi-spring-boot-starter/blob/main/LICENSE",
65+
"MIT License"
66+
)
67+
developers = listOf(
68+
io.hndrs.gradle.plugin.Developer("marvinschramm", "Marvin Schramm", "marvin.schramm@gmail.com")
69+
)
70+
organization = io.hndrs.gradle.plugin.Organization("hndrs", "https://oss.hndrs.io")
71+
scm = io.hndrs.gradle.plugin.Scm(
72+
"scm:git:git://github.com/hndrs/jsonapi-spring-boot-starter",
73+
"https://github.com/hndrs/jsonapi-spring-boot-starter"
74+
)
75+
}
5176

5277
dependencyManagement {
5378
resolutionStrategy {
5479
cacheChangingModulesFor(0, "seconds")
5580
}
5681
imports {
57-
mavenBom("org.springframework.boot:spring-boot-dependencies:2.4.2") {
58-
bomProperty("kotlin.version", Versions.KOTLIN_VERSION)
82+
mavenBom("org.springframework.boot:spring-boot-dependencies:$springBootDependencies") {
83+
bomProperty("kotlin.version", kotlinVersion)
5984
}
6085
}
6186
}
@@ -81,7 +106,7 @@ subprojects {
81106
tasks.withType<KotlinCompile> {
82107
kotlinOptions {
83108
freeCompilerArgs = listOf("-Xjsr305=strict")
84-
jvmTarget = "15"
109+
jvmTarget = "11"
85110
}
86111
}
87112

@@ -91,10 +116,19 @@ subprojects {
91116
from(sourceSets["main"].allSource)
92117
}
93118

119+
94120
if (project.name != "sample") {
121+
95122
publishing {
96123
repositories {
97-
124+
maven {
125+
name = "release"
126+
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
127+
credentials {
128+
username = System.getenv("SONATYPE_USER")
129+
password = System.getenv("SONATYPE_PASSWORD")
130+
}
131+
}
98132
}
99133
publications {
100134
create<MavenPublication>(project.name) {
@@ -104,9 +138,19 @@ subprojects {
104138
groupId = rootProject.group as? String
105139
artifactId = project.name
106140
version = "${rootProject.version}${project.findProperty("version.appendix") ?: ""}"
141+
pom {
142+
143+
}
144+
}
145+
}
146+
val signingKey: String? = System.getenv("SIGNING_KEY")
147+
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")
148+
if (signingKey != null && signingPassword != null) {
149+
signing {
150+
useInMemoryPgpKeys(groovy.json.StringEscapeUtils.unescapeJava(signingKey), signingPassword)
151+
sign(publications[project.name])
107152
}
108153
}
109-
110154
}
111155
}
112156

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kotlinVersion=1.4.30
2+
springDependencyManagement=1.0.11.RELEASE
3+
springBootDependencies=2.4.2

settings.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ project(":spring-json-api-starter").projectDir = File("spring-json-api-starter")
88

99
include("sample")
1010
project(":sample").projectDir = File("sample")
11+
12+
pluginManagement {
13+
val kotlinVersion: String by settings
14+
val springDependencyManagement: String by settings
15+
println("Settings ${settings.extra.properties}")
16+
plugins {
17+
id("io.spring.dependency-management").version(springDependencyManagement)
18+
kotlin("jvm").version(kotlinVersion)
19+
kotlin("plugin.spring").version(kotlinVersion)
20+
kotlin("kapt").version(kotlinVersion)
21+
id("maven-publish")
22+
id("idea")
23+
}
24+
repositories {
25+
}
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
dependencies {
22
api(project(":spring-json-api"))
3+
api(group = "org.springframework.boot", name = "spring-boot-autoconfigure")
4+
5+
annotationProcessor(group = "org.springframework.boot", name = "spring-boot-configuration-processor")
6+
kapt(group = "org.springframework.boot", name = "spring-boot-configuration-processor")
7+
38
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test")
9+
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-web")
410
}

spring-json-api-starter/src/test/kotlin/io/hndrs/api/autoconfigure/JsonApiAutoConfigurationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal class JsonApiAutoConfigurationTest {
1717
.withConfiguration(
1818
AutoConfigurations.of(JsonApiAutoConfiguration::class.java)
1919
).run {
20+
2021
Assertions.assertNotNull(it.getBean(ExceptionHandler::class.java))
2122
Assertions.assertNotNull(it.getBean(ResponseAdvice::class.java))
2223
}

spring-json-api/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dependencies {
2-
api(group = "org.springframework.boot", name = "spring-boot-starter-web")
2+
optional(group = "org.springframework.boot", name = "spring-boot-starter-web")
33
}

0 commit comments

Comments
 (0)