diff --git a/docs/dependencies_update_process.md b/docs/dependencies_update_process.md index a30ab502a6..91b51216c3 100644 --- a/docs/dependencies_update_process.md +++ b/docs/dependencies_update_process.md @@ -10,10 +10,10 @@ Process run commands and update files with defined versions in the provided file ## Usage -### Manually -0. Generate report using command `./gradlew dependencyUpdates -DoutputFormatter=json -DoutputDir=..` +### Manually (root directory) +0. Generate report using command `./gradlew dependencyUpdates -DoutputFormatter=json -DoutputDir=.` 0. Build flank scripts using script `./flank-scripts/bash/buildFlankScripts.sh` -0. Run `/flank-scripts/bash/flankScripts dependencies update` +0. Run `./flank-scripts/bash/flankScripts dependencies update` ### Github action Run `Update dependencies` job using [Github action menu](https://github.com/Flank/flank/actions) by clicking `Run workflow` button diff --git a/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/DependencyExtensions.kt b/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/DependencyExtensions.kt index 47dbe58d57..e0d60217fa 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/DependencyExtensions.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/DependencyExtensions.kt @@ -8,4 +8,4 @@ val Dependency.versionToUpdate ?: availableVersion?.integration ?: version -fun GradleDependency.needsUpdate() = running.version != current.version +fun GradleDependency.needsUpdate() = (running.version != current.version) || (running.version != releaseCandidate.version) diff --git a/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/UpdateGradle.kt b/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/UpdateGradle.kt index e678c66a89..01abe3d0c6 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/UpdateGradle.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/UpdateGradle.kt @@ -14,7 +14,10 @@ private fun updateGradleWrapper(gradleDependency: GradleDependency, gradleWrappe findAllGradleWrapperPropertiesFiles(gradleWrapperPropertiesPath) .forEach { val from = gradleDependency.running.version - val to = gradleDependency.current.version + val to = if (gradleDependency.releaseCandidate.isUpdateAvailable) + gradleDependency.releaseCandidate.version + else + gradleDependency.current.version println("Update gradle wrapper $from to $to in file ${it.path}") it.updateGradleWrapperPropertiesFile(from, to) } diff --git a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/DependencyExtensionsTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/DependencyExtensionsTest.kt index 94e1acf976..2748b04d06 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/DependencyExtensionsTest.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/DependencyExtensionsTest.kt @@ -99,15 +99,23 @@ class DependencyExtensionsTest { releaseCandidate = GradleVersion("1.2rc", "test", false, false), running = GradleVersion("1", "test", false, false), ) - val gradleWhichDoesNotNeedUpdate = GradleDependency( + val gradleWhichNeedsUpdateRc = GradleDependency( current = GradleVersion("1.1", "test", false, false), nightly = GradleVersion("1.3", "test", false, false), releaseCandidate = GradleVersion("1.2rc", "test", false, false), running = GradleVersion("1.1", "test", false, false), ) + val gradleWhichDoesNotNeedUpdate = GradleDependency( + current = GradleVersion("1.1", "test", false, false), + nightly = GradleVersion("1.3", "test", false, false), + releaseCandidate = GradleVersion("1.1", "test", false, false), + running = GradleVersion("1.1", "test", false, false), + ) + - // when - then + // when - then assertTrue(gradleWhichNeedsUpdate.needsUpdate()) + assertTrue(gradleWhichNeedsUpdateRc.needsUpdate()) assertFalse(gradleWhichDoesNotNeedUpdate.needsUpdate()) } } diff --git a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/UpdateGradleTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/UpdateGradleTest.kt index 043a520c1c..fe8c1bb62f 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/UpdateGradleTest.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/UpdateGradleTest.kt @@ -1,24 +1,66 @@ package flank.scripts.dependencies.update import org.junit.Assert.assertEquals +import org.junit.Rule import org.junit.Test +import org.junit.rules.TemporaryFolder import java.io.File class UpdateGradleTest { + @get:Rule + val tempFolder = TemporaryFolder() + private val testReport = File("src/test/kotlin/flank/scripts/dependencies/update/testfiles/report.json") - private val testGradleVersionFile = File("src/test/kotlin/flank/scripts/dependencies/update/testfiles/test_gradle-wrapper.properties.test") + private val testGradleVersionFile = + File("src/test/kotlin/flank/scripts/dependencies/update/testfiles/test_gradle-wrapper.properties.test") @Test fun `Should update gradle`() { // given val expectedVersions = File("src/test/kotlin/flank/scripts/dependencies/update/testfiles/expected_gradle-wrapper.properties.test") - val copyOfTestVersions = - testGradleVersionFile.copyTo( - File("src/test/kotlin/flank/scripts/dependencies/update/testfiles/gradle-wrapper.properties")).apply { deleteOnExit() } + val copyOfTestVersions = tempFolder.newFile("gradle-wrapper.properties").apply { + writeText(testGradleVersionFile.readText()) + } + + // when + testReport.updateGradle(tempFolder.root.absolutePath) + + // then + assertEquals(copyOfTestVersions.readText(), expectedVersions.readText()) + } + + @Test + fun `Should update RC version gradle`() { + val rcReportText = testReport.readText().replace( + """ + | "releaseCandidate": { + | "version": "6.7-rc-1", + | "reason": "", + | "isUpdateAvailable": false, + | "isFailure": false + | } + """.trimMargin(), """ + | "releaseCandidate": { + | "version": "6.7-rc-1", + | "reason": "", + | "isUpdateAvailable": true, + | "isFailure": false + | } + """.trimMargin() + ) + + val rcReport = tempFolder.newFile("rcReport.json").apply { writeText(rcReportText) } + + // given + val expectedVersions = + File("src/test/kotlin/flank/scripts/dependencies/update/testfiles/expected_gradle-wrapper.properties_RC.test") + val copyOfTestVersions = tempFolder.newFile("gradle-wrapper.properties").apply { + writeText(testGradleVersionFile.readText()) + } // when - testReport.updateGradle("src/test/kotlin/flank/scripts/dependencies/update/testfiles/") + rcReport.updateGradle(tempFolder.root.absolutePath) // then assertEquals(copyOfTestVersions.readText(), expectedVersions.readText()) diff --git a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/expected_gradle-wrapper.properties_RC.test b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/expected_gradle-wrapper.properties_RC.test new file mode 100644 index 0000000000..21f9f98d6c --- /dev/null +++ b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/expected_gradle-wrapper.properties_RC.test @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-rc-1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/report.json b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/report.json index 5da4273038..b8902be211 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/report.json +++ b/flank-scripts/src/test/kotlin/flank/scripts/dependencies/update/testfiles/report.json @@ -135,7 +135,7 @@ "releaseCandidate": { "version": "6.7-rc-1", "reason": "", - "isUpdateAvailable": true, + "isUpdateAvailable": false, "isFailure": false }, "running": {