Skip to content

Commit 2e8285a

Browse files
committed
Add GitHub Actions and Sonar support
ePages-deGH-235
1 parent 0b5d511 commit 2e8285a

9 files changed

+150
-25
lines changed

.github/workflows/publish.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
publish:
10+
name: Publish
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
- name: Set up JDK
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: 17
20+
distribution: 'temurin'
21+
- name: Cache Gradle packages
22+
uses: actions/cache@v3
23+
with:
24+
path: ~/.gradle/caches
25+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
26+
restore-keys: ${{ runner.os }}-gradle
27+
- name: Test
28+
run: ./ci_test.sh
29+
- name: Publish to Gradle Plugin Portal
30+
env:
31+
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
32+
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
33+
run: ./ci_publish_gradle.sh
34+
- name: Publish to Maven Central
35+
env:
36+
FILE_ENCRYPTION_PASSWORD: ${{ secrets.FILE_ENCRYPTION_PASSWORD }}
37+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
38+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
39+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
40+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
41+
run: ./ci_publish.sh

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
build:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- name: Set up JDK
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: 17
21+
distribution: 'temurin'
22+
- name: Cache SonarCloud packages
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.sonar/cache
26+
key: ${{ runner.os }}-sonar
27+
restore-keys: ${{ runner.os }}-sonar
28+
- name: Cache Gradle packages
29+
uses: actions/cache@v3
30+
with:
31+
path: ~/.gradle/caches
32+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
33+
restore-keys: ${{ runner.os }}-gradle
34+
- name: Test
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
37+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
38+
run: ./ci_test.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.gradle/
33
.*
44
!.gitignore
5+
!.github/
56
.settings/
67
build/
78
out/

build.gradle.kts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11

22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3-
import org.kt3k.gradle.plugin.CoverallsPluginExtension
43
import pl.allegro.tech.build.axion.release.domain.TagNameSerializationConfig
54
import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig
65

76

87
plugins {
9-
id("com.github.kt3k.coveralls") version "2.12.0"
8+
`maven-publish`
109
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
1110
id("org.jmailen.kotlinter") version "3.3.0" apply false
11+
id("org.sonarqube") version "4.0.0.2929"
1212
id("pl.allegro.tech.build.axion-release") version "1.9.2"
1313
jacoco
1414
java
1515
kotlin("jvm") version "1.7.22" apply false
16-
`maven-publish`
1716
}
1817

1918
repositories {
@@ -85,12 +84,6 @@ subprojects {
8584
}
8685
}
8786

88-
//coverall multi module plugin configuration starts here
89-
configure<CoverallsPluginExtension> {
90-
sourceDirs = nonSampleProjects.flatMap { it.sourceSets["main"].allSource.srcDirs }.filter { it.exists() }.map { it.path }
91-
jacocoReportPath = "$buildDir/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
92-
}
93-
9487
tasks {
9588
val jacocoMerge by creating(JacocoMerge::class) {
9689
executionData = files(nonSampleProjects.map { File(it.buildDir, "/jacoco/test.exec") })
@@ -115,11 +108,19 @@ tasks {
115108
xml.isEnabled = true
116109
}
117110
}
118-
getByName("coveralls").dependsOn(jacocoRootReport)
111+
getByName("sonar").dependsOn(jacocoRootReport)
119112
}
120113

121114
nexusPublishing {
122115
repositories {
123116
sonatype ()
124117
}
125118
}
119+
120+
sonar {
121+
properties {
122+
property("sonar.projectKey", "ePages-de_restdocs-api-spec")
123+
property("sonar.organization", "epages-de")
124+
property("sonar.host.url", "https://sonarcloud.io")
125+
}
126+
}

ci_build.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

ci_publish_gradle.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
#!/bin/bash
22
set -e
33

4+
function check_variable_set() {
5+
_VARIABLE_NAME=$1
6+
_VARIABLE_VALUE=${!_VARIABLE_NAME}
7+
if [[ -z ${_VARIABLE_VALUE} ]]; then
8+
echo "Missing env variable ${_VARIABLE_NAME}"
9+
exit 1
10+
fi
11+
}
12+
check_variable_set GRADLE_PUBLISH_KEY
13+
check_variable_set GRADLE_PUBLISH_SECRET
14+
415
./gradlew publishPlugins -p restdocs-api-spec-gradle-plugin

ci_publish_java.sh

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
#!/bin/bash
2-
set -e
32

4-
openssl aes-256-cbc -K $encrypted_7b7bcfd5be68_key -iv $encrypted_7b7bcfd5be68_iv \
5-
-in secret-keys.gpg.enc \
6-
-out "${SIGNING_KEYRING_FILE}" \
7-
-d
3+
set -e # Exit with nonzero exit code if anything fails
84

5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
SECRET_KEYS_FILE="${SCRIPT_DIR}/secret-keys.gpg"
7+
8+
function check_variable_set() {
9+
_VARIABLE_NAME=$1
10+
_VARIABLE_VALUE=${!_VARIABLE_NAME}
11+
if [[ -z ${_VARIABLE_VALUE} ]]; then
12+
echo "Missing env variable ${_VARIABLE_NAME}"
13+
exit 1
14+
fi
15+
}
16+
check_variable_set FILE_ENCRYPTION_PASSWORD
17+
check_variable_set SIGNING_KEY_ID
18+
check_variable_set SIGNING_PASSWORD
19+
check_variable_set SONATYPE_USERNAME
20+
check_variable_set SONATYPE_PASSWORD
21+
22+
# Decrypt signing key
23+
gpg --quiet --batch --yes --decrypt --passphrase="${FILE_ENCRYPTION_PASSWORD}" \
24+
--output ${SECRET_KEYS_FILE} secret-keys.gpg.enc
25+
26+
if [[ ! -f "${SECRET_KEYS_FILE}" ]]; then
27+
echo "File ${SECRET_KEYS_FILE} does not exist"
28+
exit 1
29+
fi
30+
31+
# Publish
932
./gradlew publishToSonatype \
10-
--info \
33+
--info \
1134
--exclude-task :restdocs-api-spec-gradle-plugin:publishToSonatype \
12-
-Dorg.gradle.project.sonatypeUsername="${SONATYPE_USERNAME}" \
13-
-Dorg.gradle.project.sonatypePassword="${SONATYPE_PASSWORD}" \
14-
-Dorg.gradle.project.signing.keyId="${SIGNING_KEY_ID}" \
15-
-Dorg.gradle.project.signing.password="${SIGNING_PASSWORD}" \
16-
-Dorg.gradle.project.signing.secretKeyRingFile="${SIGNING_KEYRING_FILE}"
35+
-Dorg.gradle.project.sonatypeUsername="${SONATYPE_USERNAME}" \
36+
-Dorg.gradle.project.sonatypePassword="${SONATYPE_PASSWORD}" \
37+
-Dorg.gradle.project.signing.keyId="${SIGNING_KEY_ID}" \
38+
-Dorg.gradle.project.signing.password="${SIGNING_PASSWORD}" \
39+
-Dorg.gradle.project.signing.secretKeyRingFile="${SECRET_KEYS_FILE}"

ci_test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e # Exit with nonzero exit code if anything fails
3+
4+
if [[ -n "${SONAR_TOKEN}" ]]; then
5+
SONAR_GRADLE_TASK="sonar"
6+
else
7+
echo "INFO: Skipping sonar analysis as SONAR_TOKEN is not set"
8+
fi
9+
10+
./gradlew \
11+
clean \
12+
${SONAR_GRADLE_TASK} \
13+
build \
14+
--info

secret-keys.gpg.enc

3.77 KB
Binary file not shown.

0 commit comments

Comments
 (0)