Use gradle to get Tachidesk.jar when required

This commit is contained in:
Syer10
2021-07-09 00:07:17 -04:00
parent 1bc129e1e5
commit 4c5a784b1e
15 changed files with 185 additions and 216 deletions

View File

@@ -1,5 +1,3 @@
# This is a basic workflow to help you get started with Actions
name: CI
on:
@@ -18,32 +16,28 @@ jobs:
arch: x64
os: ubuntu-latest
shell: bash
buildPackage: ./scripts/BuildLinuxDeb.sh
buildJar: ./scripts/BuildUnixJar.sh
build: setupTachideskJar packageUberJarForCurrentOS packageDeb
setupCl: ./scripts/SetupClUnix.sh
- runtime: linux-centos-x64
arch: x64
os: ubuntu-latest
shell: bash
buildPackage: ./scripts/BuildLinuxRpm.sh
buildJar: ./scripts/BuildUnixJar.sh
build: setupTachideskJar packageRpm
setupCl: ./scripts/SetupClUnix.sh
- runtime: osx-x64
arch: x64
os: macOS-latest
shell: bash
buildPackage: ./scripts/BuildMacDmg.sh
buildJar: ./scripts/BuildUnixJar.sh
build: setupTachideskJar packageUberJarForCurrentOS
setupCl: ./scripts/SetupClUnix.sh
- runtime: win-x64
arch: x64
os: windows-latest
shell: powershell
buildPackage: ./scripts/BuildWindowsMsi.ps1
buildJar: ./scripts/BuildWindowsJar.ps1
build: setupTachideskJar packageUberJarForCurrentOS packageMsi
setupCl: ./scripts/SetupClWindows.ps1
runs-on: ${{ matrix.os }}
@@ -63,11 +57,7 @@ jobs:
- name: Setup Cl
run: ${{ matrix.setupCl }}
- name: Build Package
if: ${{ matrix.runtime != 'linux-centos-x64' && matrix.runtime != 'osx-x64' }}
run: ${{ matrix.buildPackage }}
- name: Build MacOS Package
- name: Setup MacOS Keychain
if: ${{ matrix.runtime == 'osx-x64' }}
run: |
echo ${{ secrets.APPLE_CERT }} | base64 --decode > certificate.p12
@@ -77,21 +67,34 @@ jobs:
security import certificate.p12 -k build.keychain -P ${{ secrets.APPLE_CERT_PASSWORD }} -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k ${{ secrets.APPLE_KEYCHAIN_PASSWORD }} build.keychain
${{ matrix.buildPackage }} notarizeDmg \
- name: Build Mac Package
if: ${{ matrix.runtime == 'osx-x64' }}
uses: eskatos/gradle-command-action@v1
with:
arguments: |
packageDmg notarizeDmg \
-Pcompose.desktop.mac.sign=true \
-Pcompose.desktop.mac.signing.identity=${{ secrets.APPLE_IDENTITY }} \
-Pcompose.desktop.mac.notarization.appleID=${{ secrets.APPLE_ID }} \
-Pcompose.desktop.mac.notarization.password=${{ secrets.APPLE_PASSWORD }}
- name: Build Jar
if: ${{ matrix.runtime != 'linux-centos-x64' }}
run: ${{ matrix.buildJar }}
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
- name: Build rpm Package
if: ${{ matrix.runtime == 'linux-centos-x64' }}
uses: Syer10/CentOS-Java15-Action@v1
with:
command: ${{ matrix.buildPackage }}
command: ./gradlew ${{ matrix.build }}
- name: Build
if: ${{ matrix.runtime != 'linux-centos-x64' }}
uses: eskatos/gradle-command-action@v1
with:
arguments: ${{ matrix.build }}
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
# Upload runner package tar.gz/zip as artifact
- name: Publish Artifact

View File

@@ -10,10 +10,11 @@
</option>
<option name="taskNames">
<list>
<option value="setupTachideskJar" />
<option value="run" />
</list>
</option>
<option name="vmOptions" value="" />
<option name="vmOptions" value="--illegal-access=warn" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>

View File

@@ -1,3 +1,4 @@
import Config.tachideskVersion
import org.gradle.jvm.tasks.Jar
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
@@ -87,15 +88,15 @@ dependencies {
}
java {
sourceCompatibility = JavaVersion.VERSION_15
targetCompatibility = JavaVersion.VERSION_15
sourceCompatibility = Config.jvmTarget
targetCompatibility = Config.jvmTarget
}
tasks {
withType<KotlinCompile> {
dependsOn(formatKotlinMain)
kotlinOptions {
jvmTarget = "15"
jvmTarget = Config.jvmTarget.toString()
freeCompilerArgs = listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.time.ExperimentalTime",
@@ -125,6 +126,8 @@ tasks {
withType<FormatTask> {
source(files("src"))
}
registerTachideskTasks(project)
}
@@ -179,7 +182,7 @@ buildConfig {
packageName = project.group.toString()
buildConfigField("boolean", "DEBUG", project.hasProperty("debugApp").toString())
buildConfigField("String", "TACHIDESK_SP_VERSION", "v0.4.3")
buildConfigField("String", "TACHIDESK_SP_VERSION", tachideskVersion)
}
kotlinter {

16
buildSrc/build.gradle.kts Normal file
View File

@@ -0,0 +1,16 @@
plugins {
groovy
`kotlin-dsl`
}
repositories {
mavenCentral()
maven { url = uri("https://plugins.gradle.org/m2/") }
}
dependencies {
implementation(gradleKotlinDsl())
implementation(gradleApi())
implementation(localGroovy())
implementation("de.undercouch:gradle-download-task:4.1.2")
}

View File

@@ -0,0 +1,6 @@
import org.gradle.api.JavaVersion
object Config {
const val tachideskVersion = "v0.4.3"
val jvmTarget = JavaVersion.VERSION_15
}

View File

@@ -0,0 +1,125 @@
import de.undercouch.gradle.tasks.download.Download
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.KotlinClosure1
import org.gradle.kotlin.dsl.TaskContainerScope
import org.gradle.kotlin.dsl.register
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.io.File
import Config.tachideskVersion
import org.gradle.api.Project
import org.gradle.api.Task
private const val tachideskGroup = "tachidesk"
private const val downloadTask = "downloadTar"
private const val extractTask = "extractTar"
private const val androidScriptTask = "runGetAndroid"
private const val setupCITask = "setupServerCI"
private const val buildTachideskTask = "buildTachidesk"
private const val copyTachideskJarTask = "copyTachidesk"
private const val deleteTmpFolderTask = "deleteTmp"
private const val runAllTachideskTasks = "setupTachideskJar"
private fun Task.onlyIfTachideskDoesntExist(rootDir: File) {
onlyIf { !File(rootDir, "src/main/resources/Tachidesk.jar").exists() }
}
private fun Project.tmpDir() = File(rootDir, "tmp")
fun TaskContainerScope.registerTachideskTasks(project: Project) {
with(project) {
register<Download>(downloadTask) {
group = tachideskGroup
onlyIfTachideskDoesntExist(rootDir)
val tmpDir = tmpDir()
src("https://github.com/Suwayomi/Tachidesk/archive/refs/tags/$tachideskVersion.tar.gz")
dest(
KotlinClosure1<Any?, File>(
{
File(tmpDir.also { it.mkdir() }, "Tachidesk.tar.gz")
},
this,
this
)
)
}
register<Copy>(extractTask) {
group = tachideskGroup
mustRunAfter(downloadTask)
onlyIfTachideskDoesntExist(rootDir)
from(tarTree(File(rootDir, "tmp/Tachidesk.tar.gz")))
into(tmpDir())
}
register<Exec>(androidScriptTask) {
group = tachideskGroup
mustRunAfter(extractTask)
onlyIfTachideskDoesntExist(rootDir)
val workingDir = File(tmpDir(), "Tachidesk-${tachideskVersion.drop(1)}/")
val getAndroidScript = File(workingDir, "AndroidCompat/getAndroid").absolutePath
workingDir(workingDir)
val os = DefaultNativePlatform.getCurrentOperatingSystem()
when {
os.isWindows -> commandLine("cmd", "/c", """Powershell -File "$getAndroidScript.ps1"""")
os.isLinux || os.isMacOsX -> commandLine("$getAndroidScript.sh")
}
}
register<Copy>(setupCITask) {
group = tachideskGroup
mustRunAfter(androidScriptTask)
onlyIfTachideskDoesntExist(rootDir)
val tachideskDir = File(tmpDir(), "Tachidesk-${tachideskVersion.drop(1)}/")
from(File(tachideskDir, ".github/runner-files/ci-gradle.properties"))
into(File(tachideskDir, ".gradle/"))
rename {
it.replace("ci-", "")
}
}
register<Exec>(buildTachideskTask) {
group = tachideskGroup
mustRunAfter(setupCITask)
onlyIfTachideskDoesntExist(rootDir)
workingDir(File(tmpDir(), "Tachidesk-${tachideskVersion.drop(1)}/"))
commandLine("cmd", "/c", "gradlew", ":server:shadowJar")
}
register<Copy>(copyTachideskJarTask) {
group = tachideskGroup
mustRunAfter(buildTachideskTask)
onlyIfTachideskDoesntExist(rootDir)
from(File(tmpDir(), "Tachidesk-${tachideskVersion.drop(1)}/server/build/"))
include("Tachidesk-$tachideskVersion-r*.jar")
into(File(rootDir, "src/main/resources/"))
rename {
"Tachidesk.jar"
}
}
register<Delete>(deleteTmpFolderTask) {
mustRunAfter(copyTachideskJarTask)
delete(tmpDir())
}
register(runAllTachideskTasks) {
group = tachideskGroup
dependsOn(
downloadTask,
extractTask,
androidScriptTask,
setupCITask,
buildTachideskTask,
copyTachideskJarTask,
deleteTmpFolderTask
)
}
}
named("processResources") {
mustRunAfter(runAllTachideskTasks)
}
}

View File

@@ -1,15 +0,0 @@
#!/bin/bash
if [ "$(basename "$(pwd)")" = "scripts" ]; then
cd ..
fi
if test -f "src/main/resources/Tachidesk.jar"; then
echo "Tachidesk.jar already exists"
else
scripts/SetupUnix.sh
fi
echo "Building Deb package"
./gradlew packageDeb

View File

@@ -1,14 +0,0 @@
#!/bin/bash
if [ "$(basename "$(pwd)")" = "scripts" ]; then
cd ..
fi
if test -f "src/main/resources/Tachidesk.jar"; then
echo "Tachidesk.jar already exists"
else
scripts/SetupUnix.sh
fi
echo "Building Rpm package"
./gradlew packageRpm

View File

@@ -1,13 +0,0 @@
#!/bin/bash
if [ "$(basename "$(pwd)")" = "scripts" ]; then
cd ..
fi
if test -f "src/main/resources/Tachidesk.jar"; then
echo "Tachidesk.jar exists, removing as MacOS installers cannot run it"
rm "src/main/resources/Tachidesk.jar"
fi
echo "Building Dmg package"
./gradlew packageDmg "$@"

View File

@@ -1,14 +0,0 @@
#!/bin/bash
if [ "$(basename "$(pwd)")" = "scripts" ]; then
cd ..
fi
if test -f "src/main/resources/Tachidesk.jar"; then
echo "Tachidesk.jar already exists"
else
scripts/SetupUnix.sh
fi
echo "Building Jar package"
./gradlew packageUberJarForCurrentOS

View File

@@ -1,15 +0,0 @@
if ($(Split-Path -Path (Get-Location) -Leaf) -eq "scripts" ) {
Set-Location ..
}
if (Test-Path "src/main/resources/Tachidesk.jar" -PathType leaf)
{
Write-Output "Tachidesk.jar already exists"
}
else
{
&"./scripts/SetupWindows.ps1"
}
Write-Output "Building Exe package"
&"./gradlew" packageExe

View File

@@ -1,15 +0,0 @@
if ($(Split-Path -Path (Get-Location) -Leaf) -eq "scripts" ) {
Set-Location ..
}
if (Test-Path "src/main/resources/Tachidesk.jar" -PathType leaf)
{
Write-Output "Tachidesk.jar already exists"
}
else
{
&"./scripts/SetupWindows.ps1"
}
Write-Output "Building Jar package"
&"./gradlew" packageUberJarForCurrentOS

View File

@@ -1,15 +0,0 @@
if ($(Split-Path -Path (Get-Location) -Leaf) -eq "scripts" ) {
Set-Location ..
}
if (Test-Path "src/main/resources/Tachidesk.jar" -PathType leaf)
{
Write-Output "Tachidesk.jar already exists"
}
else
{
&"./scripts/SetupWindows.ps1"
}
Write-Output "Building Msi package"
&"./gradlew" packageMsi

View File

@@ -1,41 +0,0 @@
#!/bin/bash
if [ "$(basename "$(pwd)")" = "scripts" ]; then
cd ..
fi
mkdir -p "tmp"
echo "Getting latest Tachidesk build files"
#TARBALL_LINK="$(curl -s "https://api.github.com/repos/Suwayomi/Tachidesk/releases/latest" | grep -o "https.*tarball\/[a-zA-Z0-9.]*")"
#curl -L "$TARBALL_LINK" -o tmp/Tachidesk.tar
curl -L "https://github.com/Suwayomi/Tachidesk/archive/refs/tags/v0.4.3.tar.gz" -o tmp/Tachidesk.tar.gz
tar -xvf tmp/Tachidesk.tar.gz -C tmp
TACHIDESK_FOLDER=$(find tmp -type d -regex ".*Tachidesk-[a-z0-9\.]*")
pushd "$TACHIDESK_FOLDER" || exit
echo "Setting up android.jar"
AndroidCompat/getAndroid.sh
echo "Writing ci gradle.properties"
[ ! -d "/path/to/dir" ] && mkdir ".gradle"
cp ".github/runner-files/ci-gradle.properties" ".gradle/gradle.properties"
echo "Building Tachidesk.jar"
./gradlew :server:shadowJar -x :webUI:copyBuild
TACHIDESK_JAR=$(find server/build -type f -regex ".*\.jar")
popd || exit
echo "Copying Tachidesk.jar to resources folder..."
mv "$TACHIDESK_FOLDER/$TACHIDESK_JAR" src/main/resources/Tachidesk.jar
echo "Cleaning up..."
rm -rf "tmp"
echo "Done!"

View File

@@ -1,43 +0,0 @@
if ($(Split-Path -Path (Get-Location) -Leaf) -eq "scripts" ) {
Set-Location ..
}
Remove-Item -Recurse -Force "tmp" -ErrorAction SilentlyContinue | Out-Null
New-Item -ItemType Directory -Force -Path "tmp"
Write-Output "Getting latest Tachidesk build files"
#$zipball = (Invoke-WebRequest -Uri "https://api.github.com/repos/Suwayomi/Tachidesk/releases/latest" -UseBasicParsing).content | Select-String -Pattern 'https[\.:\/A-Za-z0-9]*zipball\/[a-zA-Z0-9.]*' -CaseSensitive
#Invoke-WebRequest -Uri $zipball.Matches.Value -OutFile tmp/Tachidesk.zip -UseBasicParsing
Invoke-WebRequest -Uri "https://github.com/Suwayomi/Tachidesk/archive/refs/tags/v0.4.3.zip" -OutFile tmp/Tachidesk.zip -UseBasicParsing
Expand-Archive -Path "tmp/Tachidesk.zip" -DestinationPath "tmp"
$tachidesk_folder = Get-ChildItem -Path "tmp" | Where-Object {$_.Name -match ".*Tachidesk-[a-z0-9\.]*"} | Select-Object FullName
Push-Location $tachidesk_folder.FullName
Write-Output "Setting up android.jar"
&"./AndroidCompat/getAndroid.ps1"
Write-Output "Writing ci gradle.properties"
if (!(Test-Path -Path ".gradle")) {
New-Item -ItemType Directory -Force -Path ".gradle" -ErrorAction SilentlyContinue
}
Copy-Item ".github/runner-files/ci-gradle.properties" ".gradle/gradle.properties" -Force
Write-Output "Building Tachidesk.jar"
&"./gradlew" :server:shadowJar -x :webUI:copyBuild
$tachidesk_jar = $(Get-ChildItem "server/build" | Where-Object { $_.Name -match '.*\.jar' })[0].FullName
Pop-Location
Write-Output "Copying Tachidesk.jar to resources folder..."
Move-Item -Force $tachidesk_jar "src/main/resources/Tachidesk.jar" -ErrorAction SilentlyContinue
Write-Output "Cleaning up..."
Remove-Item -Recurse -Force "tmp" -ErrorAction SilentlyContinue | Out-Null
Write-Output "Done!"