diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d11126c218..57d023d308 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,12 +78,21 @@ jobs: exit 1 fi + #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: | - ./gradlew publish\ - -Puser=${{ secrets.MAVENCENTRAL_USER }} \ - -Ppassword=${{ secrets.MAVENCENTRAL_PASS }} \ - -Psigning.keyId=${{ secrets.MAVENCENTRAL_SIGNINGKEYID }} \ - -Psigning.password=${{ secrets.MAVENCENTRAL_SIGNINGPASS }} \ - -Psigning.secretKeyRingFile=${{ secrets.MAVENCENTRAL_SIGNINGKEY }} + if [ "${GITHUB_REF}" == "refs/heads/main" ]; then + currentVersion=$(./gradlew -q currentVersion) + else + currentVersion=$(./gradlew -q devVersion) + fi + + echo "currentVersion=$currentVersion" + + ./gradlew publish -PdeployVersion=$currentVersion diff --git a/CHANGELOG.md b/CHANGELOG.md index a360ef655e..f880393e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added weatherData HowTo for Copernicus ERA5 data [#967](https://github.com/ie3-institute/simona/issues/967) - Add some quote to 'printGoodbye' [#997](https://github.com/ie3-institute/simona/issues/997) - Add unapply method for ThermalHouseResults [#934](https://github.com/ie3-institute/simona/issues/934) +- Implemented GitHub Actions Pipeline [#939](https://github.com/ie3-institute/simona/issues/939) - Added `ApparentPower` to differentiate between different power types [#794](https://github.com/ie3-institute/simona/issues/794) - Update/enhance config documentation [#1013](https://github.com/ie3-institute/simona/issues/1013) - Create `CITATION.cff` [#1035](https://github.com/ie3-institute/simona/issues/1035) @@ -109,6 +110,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix implausible test cases of HpModelSpec [#1042](https://github.com/ie3-institute/simona/issues/1042) - Refactoring to only use 'lastHpState' and 'relevantData' for 'ThermalGrid' calculations [#916](https://github.com/ie3-institute/simona/issues/916) - Refactor thermal calcRelevantData [#1051](https://github.com/ie3-institute/simona/issues/1051) +- Removed Deployment stage from Jenkinsfile [#1063](https://github.com/ie3-institute/simona/issues/1063) +- Prepare 'ChpModelSpec' and 'CylindricalThermalStorageSpec' for Storage without storageVolumeLvlMin [#1012](https://github.com/ie3-institute/simona/issues/1012) ### Fixed - Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505) @@ -149,6 +152,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix initialisation freezing on empty primary data [#981](https://github.com/ie3-institute/simona/issues/981) - Shallow fetch in CI [#1041](https://github.com/ie3-institute/simona/issues/1041) - Correct wrong use of term "wall clock time" [#727](https://github.com/ie3-institute/simona/issues/727) +- Fixed Deployment of `simona` to `Maven Central` in new GHA Pipeline [#1029](https://github.com/ie3-institute/simona/issues/1029) ## [3.0.0] - 2023-08-07 diff --git a/Jenkinsfile b/Jenkinsfile index 84b3073e05..cb5281a764 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -133,52 +133,6 @@ node { } } - // deploy stage only if branch is main or dev - if (env.BRANCH_NAME == "main" || env.BRANCH_NAME == "dev") { - stage('deploy') { - // determine project version - String projectVersion = sh(returnStdout: true, script: "set +x && cd ${projectName}; ./gradlew -q " + - "${(env.BRANCH_NAME == "dev") ? "devVersion" : "currentVersion"}").toString().trim() - - // get the sonatype credentials stored in the jenkins secure keychain - withCredentials([ - usernamePassword(credentialsId: mavenCentralCredentialsId, usernameVariable: 'MAVENCENTRAL_USER', passwordVariable: 'MAVENCENTRAL_PASS'), - file(credentialsId: mavenCentralSignKeyFileId, variable: 'MAVENCENTRAL_KEYFILE'), - usernamePassword(credentialsId: mavenCentralSignKeyId, usernameVariable: 'MAVENCENTRAL_SIGNINGKEYID', passwordVariable: 'MAVENCENTRAL_SIGNINGPASS') - ]) { - - /* - * IMPORTANT: Do not issue 'clean' in the following task - */ - sh( - script: """set +x && cd $projectName""" + - ''' set +x; ./gradlew javadoc''', - returnStdout: true - ) - - String deployGradleTasks = '--refresh-dependencies test ' + - 'publish -Puser=${MAVENCENTRAL_USER} ' + - '-Ppassword=${MAVENCENTRAL_PASS} ' + - '-Psigning.keyId=${MAVENCENTRAL_SIGNINGKEYID} ' + - '-Psigning.password=${MAVENCENTRAL_SIGNINGPASS} ' + - '-Psigning.secretKeyRingFile=${MAVENCENTRAL_KEYFILE} ' + - "-PdeployVersion='$projectVersion'" - - gradle(deployGradleTasks, projectName) - } - - if (env.BRANCH_NAME == "main") { - // create tag on main and push it to origin - createAndPushTagOnMain(projectName, sshCredentialsId) - - // todo JH create github release - - // deploy java docs - deployJavaDocs(projectName, sshCredentialsId, gitCheckoutUrl) - } - } - } - // post processing stage('post processing') { diff --git a/build.gradle b/build.gradle index 54c2bf0b95..bfb0d52427 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ apply from: scriptsLocation + 'scoverage.gradle' // scoverage scala code coverag apply from: scriptsLocation + 'deploy.gradle' apply from: scriptsLocation + 'semVer.gradle' apply from: scriptsLocation + 'mavenCentralPublish.gradle' -apply from: scriptsLocation + 'branchName.gradle' +apply from: scriptsLocation + 'branchName.gradle' // checks naming scheme of branches configurations { scalaCompilerPlugin diff --git a/gradle/scripts/branchName.gradle b/gradle/scripts/branchName.gradle index b1357b16f1..99ba2c5097 100644 --- a/gradle/scripts/branchName.gradle +++ b/gradle/scripts/branchName.gradle @@ -18,7 +18,7 @@ tasks.register('checkBranchName') { def isValid = patterns.any { pattern -> branchName ==~ pattern } if (!isValid) { - throw new GradleException("Error: Check Branch name format (e.g., ps/#1337-FeatureName).") + throw new GradleException("Error: Check Branch name format (e.g., ps/#1337-FeatureName). Current branch name is $branchName.") } println "Branch name is $branchName" diff --git a/gradle/scripts/mavenCentralPublish.gradle b/gradle/scripts/mavenCentralPublish.gradle index c006100df7..9003d01c4c 100644 --- a/gradle/scripts/mavenCentralPublish.gradle +++ b/gradle/scripts/mavenCentralPublish.gradle @@ -10,17 +10,11 @@ task javadocJar(type: Jar, dependsOn: javadoc) { from javadoc.destinationDir } - if (project.hasProperty('user') && project.hasProperty('password') && project.hasProperty('deployVersion')) { // snapshot version differs from normal version String versionString = project.getProperty('deployVersion') - signing { - required { !versionString.endsWith('SNAPSHOT') } - if (required) - sign(publishing.publications) - } publishing { publications { @@ -87,9 +81,15 @@ if (project.hasProperty('user') && project.hasProperty('password') && project.ha } } } + signing { + useInMemoryPgpKeys( + findProperty('signingKey'), + findProperty('signingPassword') + ) + sign publishing.publications.mavenJava + } } - model { tasks.generatePomFileForMavenJavaPublication { destination = file("$buildDir/generated-pom.xml") @@ -98,7 +98,6 @@ if (project.hasProperty('user') && project.hasProperty('password') && project.ha } def removeTestDependenciesFromPom(pom) { - pom.withXml { def root = asNode() // eliminate test-scoped dependencies (no need in maven central POMs) diff --git a/gradle/scripts/semVer.gradle b/gradle/scripts/semVer.gradle index ec680a487b..c330089323 100644 --- a/gradle/scripts/semVer.gradle +++ b/gradle/scripts/semVer.gradle @@ -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" } } diff --git a/src/main/scala/edu/ie3/simona/model/thermal/MutableStorage.scala b/src/main/scala/edu/ie3/simona/model/thermal/MutableStorage.scala index 785c5c4d47..6854883720 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/MutableStorage.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/MutableStorage.scala @@ -53,6 +53,7 @@ trait MutableStorage { * @return * lack */ + @deprecated("Use thermal storage state instead") def tryToTakeAndReturnLack( takenEnergy: Energy ): Option[Energy] diff --git a/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala index 91a72ddd63..8a43b3c6ff 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala @@ -50,7 +50,7 @@ class ChpModelSpec val chpStateNotRunning: ChpState = ChpState(isRunning = false, 0, Kilowatts(0), KilowattHours(0)) val chpStateRunning: ChpState = - ChpState(isRunning = true, 0, Kilowatts(0), KilowattHours(0)) + ChpState(isRunning = true, 0, Kilowatts(42), KilowattHours(42)) val (storageInput, chpInput) = setupSpec() @@ -62,7 +62,7 @@ class ChpModelSpec "ThermalStorage", thermalBus, getQuantity(100, StandardUnits.VOLUME), - getQuantity(20, StandardUnits.VOLUME), + getQuantity(0, StandardUnits.VOLUME), getQuantity(30, StandardUnits.TEMPERATURE), getQuantity(40, StandardUnits.TEMPERATURE), getQuantity(1.15, StandardUnits.SPECIFIC_HEAT_CAPACITY), @@ -145,26 +145,26 @@ class ChpModelSpec "Check active power after calculating next state with #chpState and heat demand #heatDemand kWh:" in { val testCases = Table( ("chpState", "storageLvl", "heatDemand", "expectedActivePower"), - (chpStateNotRunning, 90, 0, 0), // tests case (false, false, true) + (chpStateNotRunning, 70, 0, 0), // tests case (false, false, true) ( chpStateNotRunning, - 90, + 70, 8 * 115, 95, ), // tests case (false, true, false) - (chpStateNotRunning, 90, 10, 0), // tests case (false, true, true) - (chpStateRunning, 90, 0, 95), // tests case (true, false, true) - (chpStateRunning, 90, 8 * 115, 95), // tests case (true, true, false) - (chpStateRunning, 90, 10, 95), // tests case (true, true, true) + (chpStateNotRunning, 70, 10, 0), // tests case (false, true, true) + (chpStateRunning, 70, 0, 95), // tests case (true, false, true) + (chpStateRunning, 70, 8 * 115, 95), // tests case (true, true, false) + (chpStateRunning, 70, 10, 95), // tests case (true, true, true) ( chpStateRunning, - 90, + 70, 7 * 115 + 1, 95, ), // test case (_, true, false) and demand covered together with chp ( chpStateRunning, - 90, + 70, 9 * 115, 95, ), // test case (_, true, false) and demand not covered together with chp @@ -190,26 +190,26 @@ class ChpModelSpec "Check total energy after calculating next state with #chpState and heat demand #heatDemand kWh:" in { val testCases = Table( ("chpState", "storageLvl", "heatDemand", "expectedTotalEnergy"), - (chpStateNotRunning, 90, 0, 0), // tests case (false, false, true) + (chpStateNotRunning, 70, 0, 0), // tests case (false, false, true) ( chpStateNotRunning, - 90, + 70, 8 * 115, 100, ), // tests case (false, true, false) - (chpStateNotRunning, 90, 10, 0), // tests case (false, true, true) - (chpStateRunning, 90, 0, 100), // tests case (true, false, true) - (chpStateRunning, 90, 8 * 115, 100), // tests case (true, true, false) - (chpStateRunning, 90, 10, 100), // tests case (true, true, true) + (chpStateNotRunning, 70, 10, 0), // tests case (false, true, true) + (chpStateRunning, 70, 0, 100), // tests case (true, false, true) + (chpStateRunning, 70, 8 * 115, 100), // tests case (true, true, false) + (chpStateRunning, 70, 10, 100), // tests case (true, true, true) ( chpStateRunning, - 90, + 70, 7 * 115 + 1, 100, ), // test case (_, true, false) and demand covered together with chp ( chpStateRunning, - 90, + 70, 9 * 115, 100, ), // test case (_, true, false) and demand not covered together with chp @@ -236,35 +236,35 @@ class ChpModelSpec "Check storage level after calculating next state with #chpState and heat demand #heatDemand kWh:" in { val testCases = Table( ("chpState", "storageLvl", "heatDemand", "expectedStoredEnergy"), - (chpStateNotRunning, 90, 0, 1035), // tests case (false, false, true) + (chpStateNotRunning, 70, 0, 805), // tests case (false, false, true) ( chpStateNotRunning, - 90, + 70, 8 * 115, - 230, + 0, ), // tests case (false, true, false) - (chpStateNotRunning, 90, 10, 1025), // tests case (false, true, true) - (chpStateRunning, 90, 0, 1135), // tests case (true, false, true) - (chpStateRunning, 90, 8 * 115, 230), // tests case (true, true, false) - (chpStateRunning, 90, 10, 1125), // tests case (true, true, true) + (chpStateNotRunning, 70, 10, 795), // tests case (false, true, true) + (chpStateRunning, 70, 0, 905), // tests case (true, false, true) + (chpStateRunning, 70, 8 * 115, 0), // tests case (true, true, false) + (chpStateRunning, 70, 10, 895), // tests case (true, true, true) ( chpStateRunning, - 90, + 70, 806, - 329, + 99, ), // test case (_, true, false) and demand covered together with chp ( chpStateRunning, - 90, + 70, 9 * 115, - 230, + 0, ), // test case (_, true, false) and demand not covered together with chp ( chpStateRunning, 92, 1, 1150, - ), // test case (true, true, true) and storage volume exceeds maximum + ), // test case (true, true, true) CHP running, storage at lvl 92 (1058 kWh) + 100 kWh from CHP exceeds max capacity (1150 kWh). ) forAll(testCases) { @@ -281,48 +281,54 @@ class ChpModelSpec } "Check time tick and running status after calculating next state with #chpState and heat demand #heatDemand kWh:" in { - val testCases = Seq( - // (ChpState, Storage Level, Heat Demand, Expected Time Tick, Expected Running Status) + val testCases = Table( + ( + "chpState", + "storageLvl", + "heatDemand", + "expectedTick", + "expectedRunningStatus", + ), ( chpStateNotRunning, - 90, + 70, 0, 7200, false, ), // Test case (false, false, true) ( chpStateNotRunning, - 90, + 70, 8 * 115, 7200, true, ), // Test case (false, true, false) ( chpStateNotRunning, - 90, + 70, 10, 7200, false, ), // Test case (false, true, true) - (chpStateRunning, 90, 0, 7200, true), // Test case (true, false, true) + (chpStateRunning, 70, 0, 7200, true), // Test case (true, false, true) ( chpStateRunning, - 90, + 70, 8 * 115, 7200, true, ), // Test case (true, true, false) - (chpStateRunning, 90, 10, 7200, true), // Test case (true, true, true) + (chpStateRunning, 70, 10, 7200, true), // Test case (true, true, true) ( chpStateRunning, - 90, + 70, 806, 7200, true, ), // Test case (_, true, false) and demand covered together with chp ( chpStateRunning, - 90, + 70, 9 * 115, 7200, true, @@ -336,23 +342,22 @@ class ChpModelSpec ), // Test case (true, true, true) and storage volume exceeds maximum ) - for ( + forAll(testCases) { ( - chpState, - storageLvl, - heatDemand, - expectedTimeTick, - expectedRunningStatus, - ) <- testCases - ) { - val chpData = buildChpRelevantData(chpState, heatDemand) - val thermalStorage = buildThermalStorage(storageInput, storageLvl) - val chpModel = buildChpModel(thermalStorage) + chpState, + storageLvl, + heatDemand, + expectedTick, + expectedRunningStatus, + ) => + val chpData = buildChpRelevantData(chpState, heatDemand) + val thermalStorage = buildThermalStorage(storageInput, storageLvl) + val chpModel = buildChpModel(thermalStorage) - val nextState = chpModel.calculateNextState(chpData) + val nextState = chpModel.calculateNextState(chpData) - nextState.lastTimeTick shouldEqual expectedTimeTick - nextState.isRunning shouldEqual expectedRunningStatus + nextState.lastTimeTick shouldEqual expectedTick + nextState.isRunning shouldEqual expectedRunningStatus } } diff --git a/src/test/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorageSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorageSpec.scala index 52cbb30f79..8936620e6a 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorageSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorageSpec.scala @@ -34,7 +34,7 @@ class CylindricalThermalStorageSpec "ThermalStorage", null, getQuantity(100, StandardUnits.VOLUME), - getQuantity(20, StandardUnits.VOLUME), + getQuantity(0, StandardUnits.VOLUME), getQuantity(30, StandardUnits.TEMPERATURE), getQuantity(40, StandardUnits.TEMPERATURE), getQuantity(1.15, StandardUnits.SPECIFIC_HEAT_CAPACITY), @@ -92,7 +92,7 @@ class CylindricalThermalStorageSpec storage.tryToStoreAndReturnRemainder(vol2Energy(CubicMeters(55))) val newLevel2 = storage._storedEnergy val isCovering = storage.isDemandCoveredByStorage(KilowattHours(5)) - val lack = storage.tryToTakeAndReturnLack(vol2Energy(CubicMeters(95))) + val lack = storage.tryToTakeAndReturnLack(vol2Energy(CubicMeters(115))) val newLevel3 = storage._storedEnergy val notCovering = storage.isDemandCoveredByStorage(KilowattHours(1)) @@ -101,7 +101,7 @@ class CylindricalThermalStorageSpec surplus.value shouldBe vol2Energy(CubicMeters(5)) newLevel2 should approximate(vol2Energy(CubicMeters(100))) lack.value shouldBe vol2Energy(CubicMeters(15)) - newLevel3 should approximate(vol2Energy(CubicMeters(20))) + newLevel3 should approximate(vol2Energy(CubicMeters(0))) isCovering shouldBe true notCovering shouldBe false } @@ -110,7 +110,7 @@ class CylindricalThermalStorageSpec val storage = buildThermalStorage(storageInput, CubicMeters(70)) val usableThermalEnergy = storage.usableThermalEnergy - usableThermalEnergy should approximate(KilowattHours(5 * 115)) + usableThermalEnergy should approximate(KilowattHours(805)) } "Apply, validation, and build method work correctly" in { @@ -145,11 +145,11 @@ class CylindricalThermalStorageSpec ), ( 0L, - 250.0, + 20.0, 10.0, 3600L, -42.0, - 260.0, + 30.0, ThermalStorage.ThermalStorageThreshold.StorageEmpty(6171L), ), ( @@ -163,11 +163,11 @@ class CylindricalThermalStorageSpec ), ( 0L, - 250.0, + 20.0, -10.0, 3600L, -42.0, - 240.0, + 10.0, ThermalStorage.ThermalStorageThreshold.StorageEmpty(4457L), ), ( @@ -181,11 +181,11 @@ class CylindricalThermalStorageSpec ), ( 0L, - 240.0, + 10.0, -9.0, 3600L, -5000.0, - 231.0, + 1.0, ThermalStorage.ThermalStorageThreshold.StorageEmpty(3601L), ), ) @@ -232,7 +232,7 @@ class CylindricalThermalStorageSpec "expectedStoredEnergy", ), (0L, 250.0, 10.0, 3600L, 0.0, 260.0), - (0L, 250.0, -10.0, 3600L, 0.0, 240.0), + (0L, 20.0, -10.0, 3600L, 0.0, 10.0), ) forAll(cases) {