Skip to content

Commit

Permalink
Use the Github API to fetch the latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Sep 30, 2022
1 parent 2f5f2c2 commit 053a0ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pl.zalas.gradle.structurizrcli
import org.junit.jupiter.api.io.TempDir
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class DownloadFunctionalTest : FunctionalTest {
Expand Down Expand Up @@ -45,15 +46,33 @@ class DownloadFunctionalTest : FunctionalTest {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.19.0"
version = "1.20.1"
download {
directory = "downloads"
directory = "tmp"
}
}
""")

execute(projectDir, "structurizrCliDownload")

assertTrue(File("${projectDir.absolutePath}/downloads/structurizr-cli-1.19.0.zip").exists())
assertTrue(File("${projectDir.absolutePath}/tmp/structurizr-cli-1.20.1.zip").exists())
}

@Test
fun `it downloads the latest version of structurizr cli`(@TempDir projectDir: File) {
givenConfiguration(projectDir, """
plugins {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
}
""")

execute(projectDir, "structurizrCliDownload")

val downloadedFiles = File("${projectDir.absolutePath}/build/downloads/")
.listFiles { _, fileName -> fileName.matches("structurizr-cli-.*\\.zip".toRegex()) }

assertEquals(1, downloadedFiles.size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class Version : DefaultTask() {

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

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

0 comments on commit 053a0ff

Please sign in to comment.