Skip to content

Commit 053a0ff

Browse files
committed
Use the Github API to fetch the latest release
1 parent 2f5f2c2 commit 053a0ff

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/functionalTest/kotlin/pl/zalas/gradle/structurizrcli/DownloadFunctionalTest.kt

+22-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package pl.zalas.gradle.structurizrcli
1818
import org.junit.jupiter.api.io.TempDir
1919
import java.io.File
2020
import kotlin.test.Test
21+
import kotlin.test.assertEquals
2122
import kotlin.test.assertTrue
2223

2324
class DownloadFunctionalTest : FunctionalTest {
@@ -45,15 +46,33 @@ class DownloadFunctionalTest : FunctionalTest {
4546
id 'pl.zalas.structurizr-cli'
4647
}
4748
structurizrCli {
48-
version = "1.19.0"
49+
version = "1.20.1"
4950
download {
50-
directory = "downloads"
51+
directory = "tmp"
5152
}
5253
}
5354
""")
5455

5556
execute(projectDir, "structurizrCliDownload")
5657

57-
assertTrue(File("${projectDir.absolutePath}/downloads/structurizr-cli-1.19.0.zip").exists())
58+
assertTrue(File("${projectDir.absolutePath}/tmp/structurizr-cli-1.20.1.zip").exists())
59+
}
60+
61+
@Test
62+
fun `it downloads the latest version of structurizr cli`(@TempDir projectDir: File) {
63+
givenConfiguration(projectDir, """
64+
plugins {
65+
id 'pl.zalas.structurizr-cli'
66+
}
67+
structurizrCli {
68+
}
69+
""")
70+
71+
execute(projectDir, "structurizrCliDownload")
72+
73+
val downloadedFiles = File("${projectDir.absolutePath}/build/downloads/")
74+
.listFiles { _, fileName -> fileName.matches("structurizr-cli-.*\\.zip".toRegex()) }
75+
76+
assertEquals(1, downloadedFiles.size)
5877
}
5978
}

src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Version.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class Version : DefaultTask() {
3838

3939
private fun latestVersionProvider(): Provider<String> = project.provider(this::latestVersion)
4040

41-
private fun latestVersion(): String = URL("https://github.com/structurizr/cli/releases/latest")
41+
private fun latestVersion(): String = URL("https://api.github.com/repos/structurizr/cli/releases/latest")
4242
.readText()
43-
.replace("(?smi).*?<h1.*?>v([0-9.]*)<.*".toRegex(), "$1")
43+
.replace("(?smi).*?\"tag_name\":\\s*\"v([0-9.]*)\".*".toRegex(), "$1")
4444
}

0 commit comments

Comments
 (0)