Skip to content

Commit 3dd195d

Browse files
pipeline and adapted gradle scripts
1 parent 167700e commit 3dd195d

File tree

5 files changed

+154
-5
lines changed

5 files changed

+154
-5
lines changed

.github/workflows/ci.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# © 2025. TU Dortmund University,
2+
# Institute of Energy Systems, Energy Efficiency and Energy Economics,
3+
# Research group Distribution grid planning and operation
4+
#
5+
6+
name: CI
7+
8+
on:
9+
push:
10+
paths-ignore:
11+
- 'docs/**'
12+
branches:
13+
- main
14+
- dev
15+
- 'hotfix/*'
16+
- 'rel/*'
17+
- 'dependabot/*'
18+
pull_request:
19+
branches:
20+
- main
21+
- dev
22+
23+
jobs:
24+
buildAndTest:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout Source
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Setup Gradle
34+
uses: gradle/actions/setup-gradle@v4
35+
36+
- name: Check Branch
37+
run: |
38+
if [ "${{ github.event_name }}" == "pull_request" ]; then
39+
branch_name="${{ github.head_ref }}"
40+
else
41+
branch_name="${{ github.ref_name }}"
42+
fi
43+
44+
if [[ "$branch_name" == refs/heads/* ]]; then
45+
branch_name="${branch_name#refs/heads/}"
46+
fi
47+
48+
echo "branch_name=$branch_name" >> $GITHUB_ENV
49+
50+
./gradlew checkBranchName -PbranchName="$branch_name"
51+
52+
- name: Version Check
53+
if: ${{ github.event_name == 'pull_request' }}
54+
run: |
55+
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
56+
echo "Base branch is $BASE_BRANCH"
57+
58+
if [ "$BASE_BRANCH" = "main" ] || [ "$BASE_BRANCH" = "dev" ]; then
59+
echo "Performing version check..."
60+
61+
git clone ${{ github.event.pull_request.base.repo.clone_url }} base-branch
62+
cd base-branch
63+
64+
git checkout ${{ github.event.pull_request.base.sha }}
65+
66+
BASE_VERSION="$(./gradlew -q currentVersion)"
67+
echo "Base version: $BASE_VERSION"
68+
cd ..
69+
70+
HEAD_VERSION="$(./gradlew -q currentVersion)"
71+
echo "PR head version: $HEAD_VERSION"
72+
73+
if [ "$BASE_VERSION" != "$HEAD_VERSION" ]; then
74+
echo "ERROR: Version mismatch! Base: $BASE_VERSION vs. PR head: $HEAD_VERSION"
75+
exit 1
76+
else
77+
echo "Version check passed. ($BASE_VERSION == $HEAD_VERSION)"
78+
fi
79+
else
80+
echo "Base branch is $BASE_BRANCH; no version check needed."
81+
fi
82+
83+
- name: Setup Java
84+
uses: actions/setup-java@v4
85+
with:
86+
distribution: 'temurin'
87+
java-version: 17
88+
89+
- name: Build Project
90+
run: ./gradlew --refresh-dependencies clean assemble spotlessCheck
91+
92+
- name: Run Tests
93+
run: ./gradlew test jacocoTestReport jacocoTestCoverageVerification
94+
95+
- name: Build Java-Docs
96+
run: ./gradlew javadoc
97+
98+
- name: SonarQube
99+
run: |
100+
./gradlew sonar \
101+
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \
102+
-Dsonar.host.url=${{ vars.SONAR_HOST_URL }} \
103+
-Dsonar.login=${{ secrets.SONAR_TOKEN }} \
104+
-Dsonar.qualitygate.wait=true
105+
106+
#Deployment
107+
- name: Deploy
108+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
109+
env:
110+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVENCENTRAL_SIGNINGKEY }}
111+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVENCENTRAL_SIGNINGPASS }}
112+
ORG_GRADLE_PROJECT_user: ${{ secrets.MAVENCENTRAL_USER }}
113+
ORG_GRADLE_PROJECT_password: ${{ secrets.MAVENCENTRAL_PASS }}
114+
run: |
115+
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then
116+
currentVersion=$(./gradlew -q currentVersion)
117+
else
118+
currentVersion=$(./gradlew -q devVersion)
119+
fi
120+
121+
echo "currentVersion=$currentVersion"
122+
123+
./gradlew publish -PdeployVersion=$currentVersion

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ apply from: scriptsLocation + 'mavenCentralPublish.gradle'
4040
apply from: scriptsLocation + 'jacoco.gradle'
4141
apply from: scriptsLocation + 'documentation.gradle'
4242
apply from: scriptsLocation + 'test.gradle'
43+
apply from: scriptsLocation + 'branchName.gradle' // checks naming scheme of branches
4344

4445
repositories {
4546
mavenCentral()

gradle/scripts/branchName.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
tasks.register('checkBranchName') {
2+
doLast {
3+
if (!project.hasProperty('branchName')) {
4+
throw new GradleException("Error: Missing required property 'branchName'.")
5+
}
6+
7+
def branchName = project.property('branchName')
8+
9+
def patterns = [
10+
~/^(developer|develop|dev)$/,
11+
~/.*rel\/.*/,
12+
~/^dependabot\/.*$/,
13+
~/.*hotfix\/\pL{2}\/#\d+.*/,
14+
~/.*main/,
15+
~/^[a-z]{2}\/#[0-9]+(?:-.+)?$/
16+
]
17+
18+
def isValid = patterns.any { pattern -> branchName ==~ pattern }
19+
20+
if (!isValid) {
21+
throw new GradleException("Error: Check Branch name format (e.g., ps/#1337-FeatureName). Current branch name is $branchName.")
22+
}
23+
24+
println "Branch name is $branchName"
25+
}
26+
}

gradle/scripts/semVer.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// tasks for semantic versioning using semver-gradle https://github.com/ethauvin/semver-gradle
22

3-
task currentVersion {
4-
doFirst{
3+
tasks.register('currentVersion') {
4+
doFirst {
55
println semver.semver
66
}
77
}
88

9-
task devVersion {
10-
doFirst{
9+
tasks.register('devVersion') {
10+
doFirst {
1111
println "${semver.major}.${semver.minor}-SNAPSHOT"
1212
}
1313
}

gradle/scripts/sonarqube.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ project.tasks["sonarqube"].dependsOn "pmdTest"
3333
project.tasks["sonarqube"].dependsOn "spotbugsMain"
3434
project.tasks["sonarqube"].dependsOn "spotbugsTest"
3535
project.tasks["sonarqube"].dependsOn "test"
36-

0 commit comments

Comments
 (0)