Final :) #132
This file contains 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
# © 2024. 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: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.ref || github.ref }} | |
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
- name: Check Branch | |
run: | | |
# Default to GITHUB_REF_NAME (works for push events) | |
BRANCH_NAME="${GITHUB_REF_NAME}" | |
# If it's a pull request, use GITHUB_HEAD_REF | |
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |
BRANCH_NAME="${GITHUB_HEAD_REF}" | |
fi | |
# Extract the branch name from refs/heads/ for push events | |
branch_name="${BRANCH_NAME#refs/heads/}" | |
# Adjusted regex pattern to match two lowercase initials, slash, hashtag, and number | |
if [[ ! "$branch_name" =~ ^[a-z]{2}/#([0-9]+)(-.*)?$ ]]; then | |
echo "Error: Branch name must start with two lowercase initials (e.g., ps/#1337-FeatureName)." | |
exit 1 | |
fi | |
echo "Branch name is $branch_name" | |
echo "branch_name=$branch_name" >> $GITHUB_ENV | |
- name: Determine Project Version | |
id: version | |
run: | | |
branch_name=$(echo ${{ github.ref_name }}) | |
project_version=$(./gradlew -q $([ "$branch_name" = "dev" ] && echo "devVersion" || echo "currentVersion")) | |
echo "project_version=${project_version}" >> $GITHUB_ENV | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
- name: Build Project | |
run: | | |
./gradlew --refresh-dependencies clean assemble | |
- name: Run Tests | |
run: | | |
./gradlew spotlessCheck pmdMain pmdTest | |
- name: Build Scala-Docs | |
run: | | |
./gradlew scaladoc | |
- name: SonarQube Analysis | |
uses: sonarsource/sonarqube-scan-action@master | |
with: | |
projectBaseDir: '.' | |
args: > | |
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} | |
-Dsonar.java.binaries=build/classes/scala/main | |
-Dsonar.verbose=true | |
-Dsonar.sourceEncoding=UTF-8 | |
-Dsonar.sources=src/main/resources,src/main/scala | |
-Dsonar.tests=src/test/resources,src/test/scala,src/test/groovy | |
-Dsonar.junit.reportPaths=build/test-results/test | |
-Dsonar.scala.scapegoat.reportPaths=build/reports/scapegoat/src/scapegoat-scalastyle.xml,build/reports/scapegoat/testsrc/scapegoat-scalastyle.xml | |
-Dsonar.scala.coverage.reportPaths=build/reports/scoverageTest/scoverage.xml | |
-Dsonar.groovy.binaries=build/classes/groovy | |
-Dsonar.exclusions=src/main/scala/edu/ie3/simona/config/SimonaConfig.scala | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} | |
- name: SonarQube Quality Gate | |
id: sonarqube-quality-gate-check | |
uses: sonarsource/sonarqube-quality-gate-action@master | |
# Force to fail step after specific time. | |
timeout-minutes: 15 | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} | |
- name: Deploy | |
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' | |
run: | | |
./gradlew --refresh-dependencies test publish\ | |
-Puser=${{ secrets.MAVENCENTRAL_USER }} \ | |
-Ppassword=${{ secrets.MAVENCENTRAL_PASS }} \ | |
-Psigning.keyId=${{ secrets.MAVENCENTRAL_SIGNINGKEYID }} \ | |
-Psigning.password=${{ secrets.MAVENCENTRAL_SIGNINGPASS }} \ | |
-Psigning.secretKeyRingFile=${{ secrets.MAVENCENTRAL_SIGNINGKEY }} |