bundle WebUI for stable builds

This commit is contained in:
Aria Moradi
2021-08-08 06:18:00 +04:30
parent fb1f88e971
commit 7d2f542f8a
4 changed files with 46 additions and 24 deletions

View File

@@ -65,7 +65,7 @@ jobs:
with:
build-root-directory: master
wrapper-directory: master
arguments: :webUI:copyBuild :server:shadowJar --stacktrace
arguments: :server:downloadWebUI :server:shadowJar --stacktrace
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true

2
.gitignore vendored
View File

@@ -6,7 +6,7 @@ gradle.properties
# Ignore Gradle build output directory
build
server/src/main/resources/webUI
server/src/main/resources/WebUI.zip
server/tmp/
server/tachiserver-data/

View File

@@ -181,6 +181,12 @@ tasks {
named<Copy>("processResources") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
mustRunAfter("downloadWebUI")
}
register<de.undercouch.gradle.tasks.download.Download>("downloadWebUI") {
src("https://github.com/Suwayomi/Tachidesk-WebUI-preview/releases/download/$webUIRevisionTag/Tachidesk-WebUI-$webUIRevisionTag.zip")
dest("src/main/resources/WebUI.zip")
}
withType<LintTask> {

View File

@@ -53,40 +53,56 @@ fun setupWebUI() {
} else {
File(applicationDirs.webUIRoot).deleteRecursively()
// download webUI zip
val webUIZip = "Tachidesk-WebUI-${BuildConfig.WEBUI_TAG}.zip"
val webUIZipPath = "$tmpDir/$webUIZip"
val webUIZipURL = "${BuildConfig.WEBUI_REPO}/releases/download/${BuildConfig.WEBUI_TAG}/$webUIZip"
val webUIZipFile = File(webUIZipPath)
webUIZipFile.delete()
logger.info { "Downloading WebUI zip from the Internet..." }
val data = ByteArray(1024)
// try with resources first
val resourceWebUI = try {
BuildConfig::class.java.getResourceAsStream("/WebUI.zip")
} catch (e: NullPointerException) { null }
webUIZipFile.outputStream().use { webUIZipFileOut ->
BufferedInputStream(URL(webUIZipURL).openStream()).use { inp ->
var totalCount = 0
var tresh = 0
while (true) {
val count = inp.read(data, 0, 1024)
totalCount += count
if (totalCount > tresh + 10 * 1024) {
tresh = totalCount
print(" *")
if (resourceWebUI == null) { // is not bundled
// download webUI zip
val webUIZipURL = "${BuildConfig.WEBUI_REPO}/releases/download/${BuildConfig.WEBUI_TAG}/$webUIZip"
webUIZipFile.delete()
logger.info { "Downloading WebUI zip from the Internet..." }
val data = ByteArray(1024)
webUIZipFile.outputStream().use { webUIZipFileOut ->
BufferedInputStream(URL(webUIZipURL).openStream()).use { inp ->
var totalCount = 0
var tresh = 0
while (true) {
val count = inp.read(data, 0, 1024)
totalCount += count
if (totalCount > tresh + 10 * 1024) {
tresh = totalCount
print(" *")
}
if (count == -1)
break
webUIZipFileOut.write(data, 0, count)
}
if (count == -1)
break
webUIZipFileOut.write(data, 0, count)
println()
logger.info { "Downloading WebUI Done." }
}
}
} else {
logger.info { "Using the bundled WebUI zip..." }
resourceWebUI.use { input ->
webUIZipFile.outputStream().use { output ->
input.copyTo(output)
}
println()
logger.info { "Downloading WebUI Done." }
}
}
// extract webUI zip
logger.info { "Extracting downloaded WebUI zip..." }
logger.info { "Extracting WebUI zip..." }
File(applicationDirs.webUIRoot).mkdirs()
ZipFile(webUIZipPath).extractAll(applicationDirs.webUIRoot)
logger.info { "Extracting downloaded WebUI zip Done." }
logger.info { "Extracting WebUI zip Done." }
}
}