Skip to content

Implementation of GHA #1

Implementation of GHA

Implementation of GHA #1

Workflow file for this run

# © 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 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
echo "branch_name=$branch_name" >> $GITHUB_ENV
./gradlew checkBranchName -PbranchName="$branch_name"
- name: Version Check
if: ${{ github.event_name == 'pull_request' }}
run: |
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
echo "Base branch is $BASE_BRANCH"
if [ "$BASE_BRANCH" = "main" ] || [ "$BASE_BRANCH" = "dev" ]; then
echo "Performing version check..."
git clone ${{ github.event.pull_request.base.repo.clone_url }} base-branch
cd base-branch
git checkout ${{ github.event.pull_request.base.sha }}
BASE_VERSION="$(./gradlew -q currentVersion)"
echo "Base version: $BASE_VERSION"
cd ..
HEAD_VERSION="$(./gradlew -q currentVersion)"
echo "PR head version: $HEAD_VERSION"
if [ "$BASE_VERSION" != "$HEAD_VERSION" ]; then
echo "ERROR: Version mismatch! Base: $BASE_VERSION vs. PR head: $HEAD_VERSION"
exit 1
else
echo "Version check passed. ($BASE_VERSION == $HEAD_VERSION)"
fi
else
echo "Base branch is $BASE_BRANCH; no version check needed."
fi
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Build Project
run: ./gradlew --refresh-dependencies clean assemble spotlessCheck
- name: Run Tests
run: ./gradlew 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