Skip to content

Commit

Permalink
Merge pull request #73 from Konyaco/update_build_script
Browse files Browse the repository at this point in the history
Update Build Script
  • Loading branch information
Sanlorng authored Oct 28, 2024
2 parents 1de020a + 9cec829 commit 2af3c21
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 14 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/github_snapshot_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: Gradle Snapshot Build

on:
push:
branches:
- dev

jobs:
build:

strategy:
matrix:
type: [PublishLibrary, Android, Windows, Linux, macOS]
include:
- type: PublishLibrary
publish: release
os: macos-latest
- type: Android
android: apk
os: macos-latest
- type: Windows
desktop: msi
os: windows-latest
- type: Linux
desktop: deb
os: ubuntu-latest
- type: macOS
desktop: dmg
os: macos-latest

runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: $ {{ github.ref }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Publish Library
if: ${{ matrix.publish }}
run: |
./gradlew publishToMavenLocal
./gradlew publish
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}

- name: Upload Library Artifact
if: ${{ matrix.publish }}
uses: actions/upload-artifact@v4
with:
name: Repository-${{ github.run_id }}
path: ~/.m2/repository

- name: Build Gallery for ${{ matrix.type }}
if: ${{ matrix.android }}
run: |
echo "$ANDROID_KEYSTORE" | base64 --decode > ${{ github.workspace }}/android_sign_key.jks
./gradlew :gallery:assembleRelease
env:
ANDROID_KEYSTORE: ${{ secrets.ANDROID_KEYSTORE }}
ANDROID_SIGNING_FILE: ${{ github.workspace }}/android_sign_key.jks
ANDROID_SIGNING_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
ANDROID_SIGNING_KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
ANDROID_SIGNING_KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}

- name: Upload android build artifacts
if: ${{ matrix.android }}
uses: actions/upload-artifact@v4
with:
name: Gallery-${{ matrix.type }}-${{ github.run_id }}
path: ${{github.workspace}}/gallery/build/outputs/**/*.${{ matrix.android }}

- name: Build Gallery for ${{ matrix.type }}
if: ${{ matrix.desktop }}
run: |
./gradlew :gallery:packageReleaseDistributionForCurrentOS
- name: Upload desktop build artifacts
if: ${{ matrix.desktop }}
uses: actions/upload-artifact@v4
with:
name: Gallery-${{ matrix.type }}-${{ github.run_id }}
path: ${{github.workspace}}/gallery/build/compose/binaries/main-release/${{ matrix.desktop }}/*.${{ matrix.desktop }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,55 @@ object BuildConfig {

const val packageName = "$group.fluent"

const val libraryVersion = "0.0.1-dev.8"
private const val snapshotLibraryVersion = "0.1.0-SNAPSHOT"

val isRelease = System.getenv("PROJECT_BUILD_TYPE") == "release"

val gitTag = Runtime
.getRuntime()
.exec("git describe --abbrev=0 --tags")
.inputReader()
.readLine()

val relativeCommitCount = Runtime
.getRuntime()
.exec("git describe --tags")
.inputReader()
.readLine()
.removePrefix(gitTag)
.let {
if (it.isNotEmpty()) {
it.split("-")[1].toInt()
} else {
0
}
}

val libraryVersion = when {
isRelease -> gitTag
else -> snapshotLibraryVersion
}

val integerVersionName = libraryVersion
.removePrefix("v")
.removeSuffix("-SNAPSHOT")
.substringBefore("-dev")
.let {
val parts = it.split(".")
var major = parts.getOrNull(0) ?: "0"
var minor = parts.getOrNull(1) ?: "0"
if (major.startsWith("0")) {
major = "1"
minor = "0"
}
when(parts.size) {
1, 2 -> "${major}.$minor.$relativeCommitCount"
else -> {
val patchVersion = parts[2].toIntOrNull() ?: 0
"${major}.${minor}.${patchVersion * 200 + relativeCommitCount}"
}
}
}

object Android {
const val compileSdkVersion = 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension

class BuildPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.allprojects.forEach {
it.afterEvaluate {
target.allprojects.forEach { project ->
project.afterEvaluate {

it.extensions.findByType<PublishingExtension>()?.apply {
setupMavenPublishing(it)
it.extensions.findByType<SigningExtension>()?.setupSigning(this)
project.extensions.findByType<PublishingExtension>()?.apply {
setupMavenPublishing(project)
project.extensions.findByType<SigningExtension>()?.let { signing ->
signing.setupSigning(this)

// workaround for publishing with javadoc see https://github.com/gradle/gradle/issues/26091#issuecomment-1722947958
project.tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTask = project.tasks.withType<Sign>()
mustRunAfter(signingTask)
}
}
}
}
}
Expand Down Expand Up @@ -67,12 +77,12 @@ class BuildPlugin : Plugin<Project> {
}
repositories {
maven {
val releasesUrl ="https://s01.oss.sonatype.org/content/repositories/snapshots/"
val snapshotsUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
val snapshotsUrl ="https://s01.oss.sonatype.org/content/repositories/snapshots/"
val releasesUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
name = "OSSRH"
url = target.uri(
if (target.version.toString().endsWith("SNAPSHOT")) releasesUrl
else snapshotsUrl
if (target.version.toString().endsWith("SNAPSHOT")) snapshotsUrl
else releasesUrl
)
credentials {
username = System.getenv("OSSRH_USERNAME")
Expand Down
40 changes: 37 additions & 3 deletions gallery/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.android.build.api.variant.impl.VariantOutputImpl
import com.konyaco.fluent.plugin.build.BuildConfig
import com.konyaco.fluent.plugin.build.applyTargets
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
Expand Down Expand Up @@ -60,7 +61,7 @@ android {
minSdk = BuildConfig.Android.minSdkVersion
targetSdk = BuildConfig.Android.compileSdkVersion
versionCode = 1
versionName = "1.0"
versionName = BuildConfig.libraryVersion
vectorDrawables {
useSupportLibrary = true
}
Expand All @@ -70,7 +71,36 @@ android {
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.android.pro")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.android.pro"
)
val signFile = System.getenv("ANDROID_SIGNING_FILE")
signFile?.let {
val password = System.getenv("ANDROID_SIGNING_PASSWORD")
val keyAlias = System.getenv("ANDROID_SIGNING_KEY_ALIAS")
val keyPassword = System.getenv("ANDROID_SIGNING_KEY_PASSWORD")
signingConfig = signingConfigs.register("release") {
this.storeFile = file(signFile)
this.storePassword = password
this.keyAlias = keyAlias
this.keyPassword = keyPassword
}.get()
}
}
}

androidComponents.onVariants { variant ->
variant.outputs.forEach { output ->
if (output is VariantOutputImpl) {
output.apply {
outputFileName.set(
"${variant.applicationId.get()}-" +
"${versionName.get()}-" +
"${variant.buildType}.apk"
)
}
}
}
}

Expand All @@ -89,10 +119,13 @@ android {
compose.desktop {
application {
mainClass = "${BuildConfig.packageName}.gallery.MainKt"
buildTypes.release.proguard {
configurationFiles.from(project.file("proguard-rules.desktop.pro"))
}
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Compose Fluent Design Gallery"
packageVersion = "1.0.0"
packageVersion = BuildConfig.integerVersionName
macOS {
iconFile.set(project.file("icons/icon.icns"))
jvmArgs(
Expand All @@ -101,6 +134,7 @@ compose.desktop {
}
windows {
iconFile.set(project.file("icons/icon.ico"))
upgradeUuid = "a23572e1-c6fd-4b76-98ec-1e45953eb941"
}
linux {
iconFile.set(project.file("icons/icon.png"))
Expand Down
3 changes: 3 additions & 0 deletions gallery/proguard-rules.desktop.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-dontwarn com.sun.jna.internal.Cleaner
-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ androidGradlePlugin = "8.3.2"
androidBuildTools = "31.3.2"
windowStyler = "0.3.3-SNAPSHOT"
highlights = "0.8.0"
jna = "5.14.0"
jna = "5.13.0"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
Expand Down

0 comments on commit 2af3c21

Please sign in to comment.