Skip to content

Commit

Permalink
setup ci publish and signing (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MarvinSchramm authored Feb 15, 2021
1 parent 114142c commit 8574799
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
name: Tests
name: gradle

# Controls when the action will run.
on:

pull_request:
branches: [ main ]

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

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

steps:
- name: Git Checkout
- name: git checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java
- name: setup java
uses: actions/setup-java@v1
with:
java-version: '15'
java-version: '11'

- name: Setup Build Cache
- name: gradle cache
uses: actions/cache@v2
with:
path: |
Expand All @@ -34,6 +32,7 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Tests
- name: test
run: |
./gradlew check
44 changes: 44 additions & 0 deletions .github/workflows/hndrs-gradle-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: gradle

# Controls when the action will run.
on:
push:
tags:
- v*

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

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: git checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: setup java
uses: actions/setup-java@v1
with:
java-version: '11'

- name: setup build cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: publish
env:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
./gradlew publish
51 changes: 51 additions & 0 deletions .github/workflows/hndrs-gradle-sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: gradle

# Controls when the action will run.
on:
push:
branches:
- master
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]

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

jobs:
analyse:
runs-on: ubuntu-latest

steps:
- name: git checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: setup java
uses: actions/setup-java@v1
with:
java-version: '11'

- name: gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: sonar cache
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: analyse
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew check jacocoTestReport sonarqube --info
84 changes: 64 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

object Versions {
const val KOTLIN_VERSION = "1.4.30"
}

buildscript {
repositories {
mavenCentral()
Expand All @@ -14,27 +10,40 @@ buildscript {
}
}

val springBootDependencies: String by extra
val kotlinVersion: String by extra

plugins {
id("org.sonarqube").version("3.0")
`maven-publish`
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm").version("1.4.30")
kotlin("plugin.spring").version("1.4.30")
kotlin("kapt").version("1.4.30")
id("org.sonarqube").version("3.1.1")
id("io.spring.dependency-management")
kotlin("jvm")
kotlin("plugin.spring")
kotlin("kapt")
id("java")
id("maven-publish")
id("idea")
id("signing")
id("io.hndrs.publishing-info").version("1.0.0")
}

group = "com.elvah.auth"
group = "io.hndrs"
version = rootProject.file("version.txt").readText().trim()
java.sourceCompatibility = JavaVersion.VERSION_15
java.targetCompatibility = JavaVersion.VERSION_15
java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

sonarqube {
properties {
property("sonar.projectKey", "hndrs_jsonapi-spring-boot-starter")
property("sonar.organization", "hndrs")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.exclusions", "**/sample/**")
}
}

subprojects {

apply(plugin = "kotlin")
Expand All @@ -46,16 +55,32 @@ subprojects {
apply(plugin = "jacoco")
apply(plugin = "propdeps")
apply(plugin = "propdeps-idea")


apply(plugin = "signing")
apply(plugin = "io.hndrs.publishing-info")

publishingInfo {
url = "https://github.com/hndrs/jsonapi-spring-boot-starter"
license = io.hndrs.gradle.plugin.License(
"https://github.com/hndrs/jsonapi-spring-boot-starter/blob/main/LICENSE",
"MIT License"
)
developers = listOf(
io.hndrs.gradle.plugin.Developer("marvinschramm", "Marvin Schramm", "[email protected]")
)
organization = io.hndrs.gradle.plugin.Organization("hndrs", "https://oss.hndrs.io")
scm = io.hndrs.gradle.plugin.Scm(
"scm:git:git://github.com/hndrs/jsonapi-spring-boot-starter",
"https://github.com/hndrs/jsonapi-spring-boot-starter"
)
}

dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor(0, "seconds")
}
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.4.2") {
bomProperty("kotlin.version", Versions.KOTLIN_VERSION)
mavenBom("org.springframework.boot:spring-boot-dependencies:$springBootDependencies") {
bomProperty("kotlin.version", kotlinVersion)
}
}
}
Expand All @@ -81,7 +106,7 @@ subprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "15"
jvmTarget = "11"
}
}

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


if (project.name != "sample") {

publishing {
repositories {

maven {
name = "release"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}
publications {
create<MavenPublication>(project.name) {
Expand All @@ -104,9 +138,19 @@ subprojects {
groupId = rootProject.group as? String
artifactId = project.name
version = "${rootProject.version}${project.findProperty("version.appendix") ?: ""}"
pom {

}
}
}
val signingKey: String? = System.getenv("SIGNING_KEY")
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")
if (signingKey != null && signingPassword != null) {
signing {
useInMemoryPgpKeys(groovy.json.StringEscapeUtils.unescapeJava(signingKey), signingPassword)
sign(publications[project.name])
}
}

}
}

Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kotlinVersion=1.4.30
springDependencyManagement=1.0.11.RELEASE
springBootDependencies=2.4.2
16 changes: 16 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ project(":spring-json-api-starter").projectDir = File("spring-json-api-starter")

include("sample")
project(":sample").projectDir = File("sample")

pluginManagement {
val kotlinVersion: String by settings
val springDependencyManagement: String by settings
println("Settings ${settings.extra.properties}")
plugins {
id("io.spring.dependency-management").version(springDependencyManagement)
kotlin("jvm").version(kotlinVersion)
kotlin("plugin.spring").version(kotlinVersion)
kotlin("kapt").version(kotlinVersion)
id("maven-publish")
id("idea")
}
repositories {
}
}
6 changes: 6 additions & 0 deletions spring-json-api-starter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
dependencies {
api(project(":spring-json-api"))
api(group = "org.springframework.boot", name = "spring-boot-autoconfigure")

annotationProcessor(group = "org.springframework.boot", name = "spring-boot-configuration-processor")
kapt(group = "org.springframework.boot", name = "spring-boot-configuration-processor")

testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test")
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-web")
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class JsonApiAutoConfigurationTest {
.withConfiguration(
AutoConfigurations.of(JsonApiAutoConfiguration::class.java)
).run {

Assertions.assertNotNull(it.getBean(ExceptionHandler::class.java))
Assertions.assertNotNull(it.getBean(ResponseAdvice::class.java))
}
Expand Down
2 changes: 1 addition & 1 deletion spring-json-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies {
api(group = "org.springframework.boot", name = "spring-boot-starter-web")
optional(group = "org.springframework.boot", name = "spring-boot-starter-web")
}

0 comments on commit 8574799

Please sign in to comment.