-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented GHA for simonaAPI #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# © 2025. TU Dortmund University, | ||
# Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
# Research group Distribution grid planning and operation | ||
# | ||
|
||
name: CI | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- 'docs/**' | ||
branches: | ||
- main | ||
- dev | ||
- 'hotfix/*' | ||
- 'rel/*' | ||
- 'dependabot/*' | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
buildAndTest: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Source | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 17 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v4 | ||
|
||
- name: Check Branch | ||
run: | | ||
if [ "${{ github.event_name }}" == "pull_request" ]; then | ||
BRANCH_NAME="${{ github.head_ref }}" | ||
else | ||
BRANCH_NAME="${{ github.ref_name }}" | ||
fi | ||
|
||
if [[ "$BRANCH_NAME" == refs/heads/* ]]; then | ||
BRANCH_NAME="${BRANCH_NAME#refs/heads/}" | ||
fi | ||
|
||
export BRANCH_NAME | ||
|
||
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
|
||
./gradlew checkBranchName -PbranchName="$BRANCH_NAME" --warning-mode=none | ||
|
||
bash scripts/branch_type.sh | ||
|
||
- name: Version Check | ||
if: ${{ github.event_name == 'pull_request' }} | ||
env: | ||
BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
run: bash scripts/run-version-check.sh | ||
|
||
- name: Build Project | ||
run: ./gradlew --refresh-dependencies clean assemble spotlessCheck | ||
|
||
- name: Run Tests | ||
run: ./gradlew pmdMain pmdTest test jacocoTestReport jacocoTestCoverageVerification | ||
|
||
- name: Build Java-Docs | ||
run: ./gradlew javadoc | ||
|
||
- name: SonarQube | ||
run: | | ||
./gradlew sonar \ | ||
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \ | ||
-Dsonar.host.url=${{ vars.SONAR_HOST_URL }} \ | ||
-Dsonar.login=${{ secrets.SONAR_TOKEN }} \ | ||
-Dsonar.qualitygate.wait=true | ||
|
||
#Deployment | ||
- name: Deploy | ||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' | ||
env: | ||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVENCENTRAL_SIGNINGKEY }} | ||
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVENCENTRAL_SIGNINGPASS }} | ||
ORG_GRADLE_PROJECT_user: ${{ secrets.MAVENCENTRAL_USER }} | ||
ORG_GRADLE_PROJECT_password: ${{ secrets.MAVENCENTRAL_PASS }} | ||
run: | | ||
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then | ||
currentVersion=$(./gradlew -q currentVersion) | ||
else | ||
currentVersion=$(./gradlew -q devVersion) | ||
fi | ||
|
||
echo "currentVersion=$currentVersion" | ||
|
||
./gradlew publish -PdeployVersion=$currentVersion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
tasks.register('checkBranchName') { | ||
doLast { | ||
if (!project.hasProperty('branchName')) { | ||
throw new GradleException("Error: Missing required property 'branchName'.") | ||
} | ||
|
||
def branchName = project.property('branchName') | ||
|
||
def patterns = [ | ||
~/^(developer|develop|dev)$/, | ||
~/.*rel\/.*/, | ||
~/^dependabot\/.*$/, | ||
~/.*hotfix\/\pL{2}\/#\d+.*/, | ||
~/.*main/, | ||
~/^[a-z]{2}\/#[0-9]+(?:-.+)?$/ | ||
] | ||
|
||
def isValid = patterns.any { pattern -> branchName ==~ pattern } | ||
|
||
if (!isValid) { | ||
throw new GradleException("Error: Check Branch name format (e.g., ps/#1337-FeatureName). Current branch name is $branchName.") | ||
} | ||
|
||
println "Branch name is $branchName" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// tasks for semantic versioning using semver-gradle https://github.com/ethauvin/semver-gradle | ||
|
||
task currentVersion { | ||
doFirst{ | ||
tasks.register('currentVersion') { | ||
doFirst { | ||
println semver.semver | ||
} | ||
} | ||
|
||
task devVersion { | ||
doFirst{ | ||
tasks.register('devVersion') { | ||
doFirst { | ||
println "${semver.major}.${semver.minor}-SNAPSHOT" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
if [ -z "${BRANCH_NAME:-}" ]; then | ||
echo "Error: BRANCH_NAME variable is not set." | ||
exit 1 | ||
fi | ||
|
||
|
||
pattern_dev='^(developer|develop|dev)$' | ||
pattern_release='.*rel/.*' | ||
pattern_dependabot='^dependabot/.*' | ||
pattern_hotfix='.*hotfix/.*' | ||
pattern_main='.*main' | ||
pattern_feature='^[a-z]{2}/#[0-9]+(-.+)?$' | ||
|
||
BRANCH_TYPE="unknown" | ||
|
||
if [[ "$BRANCH_NAME" =~ $pattern_dev ]]; then | ||
BRANCH_TYPE="dev" | ||
elif [[ "$BRANCH_NAME" =~ $pattern_release ]]; then | ||
BRANCH_TYPE="release" | ||
elif [[ "$BRANCH_NAME" =~ $pattern_dependabot ]]; then | ||
BRANCH_TYPE="dependabot" | ||
elif [[ "$BRANCH_NAME" =~ $pattern_hotfix ]]; then | ||
BRANCH_TYPE="hotfix" | ||
elif [[ "$BRANCH_NAME" =~ $pattern_main ]]; then | ||
BRANCH_TYPE="main" | ||
elif [[ "$BRANCH_NAME" =~ $pattern_feature ]]; then | ||
BRANCH_TYPE="feature" | ||
else | ||
echo "Error:'$BRANCH_NAME' does not match any pattern." | ||
exit 1 | ||
fi | ||
|
||
echo "=========================" | ||
echo "Branch type: $BRANCH_TYPE" | ||
echo "BRANCH_TYPE=$BRANCH_TYPE" >> "$GITHUB_ENV" | ||
echo "=========================" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
REPO_URL=$(git config --get remote.origin.url) | ||
export REPO_URL | ||
echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV | ||
|
||
echo "Fetching current version of PR..." | ||
PR_VERSION=$(./gradlew -q currentVersion) | ||
echo "PR_VERSION=$PR_VERSION" | ||
echo "export PR_VERSION=$PR_VERSION" >> versions.env | ||
echo "PR_VERSION=$PR_VERSION" >> "$GITHUB_ENV" | ||
|
||
get_branch_version() { | ||
local BRANCH_NAME=$1 | ||
local DIR_NAME="${BRANCH_NAME}-branch" | ||
|
||
git clone --depth 1 --branch "$BRANCH_NAME" "$REPO_URL" "$DIR_NAME" | ||
cd "$DIR_NAME" | ||
|
||
echo "Fetching version from $BRANCH_NAME branch..." | ||
BRANCH_VERSION=$(./gradlew -q currentVersion) | ||
cd .. | ||
|
||
echo "${BRANCH_NAME^^}_VERSION=$BRANCH_VERSION" | ||
echo "export ${BRANCH_NAME^^}_VERSION=$BRANCH_VERSION" >> versions.env | ||
echo "${BRANCH_NAME^^}_VERSION=$BRANCH_VERSION" >> "$GITHUB_ENV" | ||
|
||
rm -rf "$DIR_NAME" | ||
} | ||
|
||
|
||
get_branch_version "dev" | ||
get_branch_version "main" | ||
|
||
echo "Get Versions: OK!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
rm -f versions.env | ||
|
||
scripts/get_versions.sh | ||
|
||
source versions.env | ||
|
||
scripts/version_check.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
echo "=========================" | ||
echo "LOADED ENV VARIABLES:" | ||
echo "PR_VERSION: $PR_VERSION" | ||
echo "DEV_VERSION: $DEV_VERSION" | ||
echo "MAIN_VERSION: $MAIN_VERSION" | ||
echo "BASE_BRANCH: $BASE_BRANCH" | ||
echo "=========================" | ||
|
||
semver_gt() { | ||
IFS='.' read -r major1 minor1 patch1 <<< "$1" | ||
IFS='.' read -r major2 minor2 patch2 <<< "$2" | ||
|
||
# Compare major version | ||
if [ "$major1" -gt "$major2" ]; then | ||
return 0 | ||
elif [ "$major1" -lt "$major2" ]; then | ||
return 1 | ||
fi | ||
|
||
# Compare minor version | ||
if [ "$minor1" -gt "$minor2" ]; then | ||
return 0 | ||
elif [ "$minor1" -lt "$minor2" ]; then | ||
return 1 | ||
fi | ||
|
||
# Compare patch version | ||
if [ "$patch1" -gt "$patch2" ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Version Checking Logic | ||
if [ "$BASE_BRANCH" = "dev" ]; then | ||
echo "PR into dev => applying dev rules" | ||
if [ "$DEV_VERSION" = "$PR_VERSION" ]; then | ||
echo "OK: PR version ($PR_VERSION) matches the current dev version ($DEV_VERSION)." | ||
exit 0 | ||
else | ||
if [ "$MAIN_VERSION" = "$DEV_VERSION" ]; then | ||
if semver_gt "$PR_VERSION" "$DEV_VERSION"; then | ||
echo "OK: Increasing working version in dev from $DEV_VERSION to $PR_VERSION" | ||
exit 0 | ||
else | ||
echo "FAIL: Release and working version are $MAIN_VERSION, but PR is not increasing the working version in dev" | ||
exit 1 | ||
fi | ||
else | ||
echo "FAIL: PR version ($PR_VERSION) does not match the current dev version ($DEV_VERSION)." | ||
echo "Regular PRs must not update the working version. The working version should only change in controlled updates." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
elif [ "$BASE_BRANCH" = "main" ]; then | ||
echo "PR into main => applying main rules" | ||
if semver_gt "$PR_VERSION" "$MAIN_VERSION"; then | ||
echo "OK: PR version ($PR_VERSION) is greater than the current main version ($MAIN_VERSION)." | ||
exit 0 | ||
else | ||
echo "FAIL: PR version ($PR_VERSION) is NOT greater than the current main version ($MAIN_VERSION)." | ||
echo "A new release must have a higher version than the existing main version." | ||
exit 1 | ||
fi | ||
|
||
else | ||
echo "Skipping version check: Base branch is '$BASE_BRANCH'. No version enforcement required." | ||
exit 0 | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.