Skip to content

Commit

Permalink
Build scripts with non-JVM targets disabled (#265)
Browse files Browse the repository at this point in the history
* Selectively enable targets
* Add test logging
* Move integration tests
* Revert configuration caching
* Test utils for kmp-chat
  • Loading branch information
wkal-pubnub authored Aug 5, 2024
1 parent cff96bb commit 3e82af3
Show file tree
Hide file tree
Showing 32 changed files with 259 additions and 206 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
- name: Build and run tests
run: |
./gradlew check
env:
SDK_PUB_KEY: ${{ secrets.SDK_PUB_KEY }}
SDK_SUB_KEY: ${{ secrets.SDK_SUB_KEY }}
SDK_PAM_SUB_KEY: ${{ secrets.SDK_PAM_SUB_KEY }}
SDK_PAM_PUB_KEY: ${{ secrets.SDK_PAM_PUB_KEY }}
SDK_PAM_SEC_KEY: ${{ secrets.SDK_PAM_SEC_KEY }}
- name: Cancel workflow runs for commit on error
if: failure()
uses: ./.github/.release/actions/actions/utils/fast-jobs-failure
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Validate clean build
run: ./gradlew build
run: ./gradlew ktlintFormat publishAllPublicationsToRepoRepository -PRELEASE_SIGNING_ENABLED=false
- name: Cancel workflow runs for commit on error
if: failure()
uses: ./.github/.release/actions/actions/utils/fast-jobs-failure
Expand Down
4 changes: 0 additions & 4 deletions build-logic/gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
alias(libs.plugins.kotlin.jvm)
}

kotlin {
jvmToolchain(8)
}

dependencies {
compileOnly(gradleKotlinDsl())
compileOnly(libs.nexus.gradlePlugin)
Expand Down
4 changes: 2 additions & 2 deletions build-logic/gradle-plugins/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.parallel=true
org.gradle.parallel=false
org.gradle.caching=true
org.gradle.configureondemand=true
org.gradle.configuration-cache=true
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class PubNubDokkaPlugin : Plugin<Project> {
apply<DokkaPlugin>()

tasks.withType<DokkaTask>().configureEach { task ->
task.dokkaSourceSets.configureEach {
it.perPackageOption {
task.notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/2231")
task.dokkaSourceSets.configureEach { sourceSetBuilder ->
sourceSetBuilder.perPackageOption {
it.matchingRegex.set(".*internal.*")
it.suppress.set(true)
}
it.skipEmptyPackages.set(true)
sourceSetBuilder.skipEmptyPackages.set(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,70 @@ package com.pubnub.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.tasks.testing.AbstractTestTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.yarn

class PubNubKotlinMultiplatformPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
apply<KotlinMultiplatformPluginWrapper>()
apply<KotlinCocoapodsPlugin>()
if (enableAnyIosTarget) {
apply<KotlinCocoapodsPlugin>()
}

// Kotlin
extensions.configure<KotlinMultiplatformExtension> {
compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes")
jvmToolchain(8)

js {
browser {
if (enableJsTarget) {
js { ->
useEsModules()
browser {
testTask {
it.useMocha {
timeout = "10s"
}
}
}
// nodejs {
// testTask {
// it.useMocha {
// timeout = "5s"
// }
// }
// }
}
binaries.executable()
}
jvm {
compilations.all {
it.compileTaskProvider.configure {
it.compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")

jvm { ->
compilations.configureEach { compilation ->
compilation.compileTaskProvider.configure { task ->
task.compilerOptions {
javaParameters.set(true)
}
}
}
}

listOf(
iosArm64(),
iosSimulatorArm64(),
).forEach {
it.binaries {
framework {
isStatic = true
}
}

if (enableIosTarget) {
iosArm64()
}
if (enableIosSimulatorTarget) {
iosSimulatorArm64()
}

applyDefaultHierarchyTemplate()
with (sourceSets) {
val commonMain = getByName("commonMain")
Expand All @@ -62,54 +75,68 @@ class PubNubKotlinMultiplatformPlugin : Plugin<Project> {
it.dependsOn(commonMain)
}

val jsMain = getByName("jsMain") {
it.dependsOn(nonJvm)
if (enableJsTarget) {
getByName("jsMain") {
it.dependsOn(nonJvm)
}
}

val iosMain = getByName("iosMain") {
it.dependsOn(nonJvm)
if (enableAnyIosTarget) {
getByName("iosMain") {
it.dependsOn(nonJvm)
}
}
}

(this as? ExtensionAware)?.extensions?.configure<CocoapodsExtension> {
ios.deploymentTarget = "14"
if (enableAnyIosTarget) {
(this as? ExtensionAware)?.extensions?.configure<CocoapodsExtension> {
ios.deploymentTarget = "14"
//
// summary = "Some description for a Kotlin/Native module"
// homepage = "Link to a Kotlin/Native module homepage"

// Required properties
// Specify the required Pod version here. Otherwise, the Gradle project version is used.
version = "1.0"
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
// Maps custom Xcode configuration to NativeBuildType
xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = NativeBuildType.DEBUG
xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = NativeBuildType.RELEASE

// Maps custom Xcode configuration to NativeBuildType
xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = NativeBuildType.DEBUG
xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = NativeBuildType.RELEASE

// podfile = project.file(project.file("Sample Chat app/Podfile"))

framework {
// Required properties
// Framework name configuration. Use this property instead of deprecated 'frameworkName'

// Optional properties
// Specify the framework linking type. It's dynamic by default.
isStatic = true
transitiveExport = true
}
framework {
isStatic = true
transitiveExport = true
}

pod("PubNubSwift") {
pod("PubNubSwift") {
val swiftPath = project.findProperty("SWIFT_PATH") as? String ?: "swift"
// source = git("https://github.com/pubnub/swift") {
// branch = "feat/kmp"
// }
// headers = "PubNub/PubNub.h"
source = path(rootProject.file("swift"))
// version = "7.1.0"

moduleName = "PubNub"
extraOpts += listOf("-compiler-option", "-fmodules")
// version = "7.1.0"
source = path(rootProject.file(swiftPath))
moduleName = "PubNub"
extraOpts += listOf("-compiler-option", "-fmodules")
}
}
}
}

if (enableJsTarget) {
yarn.yarnLockMismatchReport = YarnLockMismatchReport.WARNING
yarn.yarnLockAutoReplace = true
}
tasks.withType<AbstractTestTask> {
testLogging {
it.showStackTraces = true
it.showCauses = true
it.showExceptions = true
it.exceptionFormat = TestExceptionFormat.FULL
}
// if (providers.environmentVariable("CI").isPresent && !providers.environmentVariable("CI_FORCE_RUN_INTEGRATION_TESTS").isPresent) {
// filter.excludeTestsMatching("com.pubnub.test.integration.*")
// }
}
}
}
}
}

val Project.enableJsTarget get() = project.findProperty("ENABLE_TARGET_JS") == "true"
val Project.enableIosTarget get() = project.findProperty("ENABLE_TARGET_IOS") == "true"
val Project.enableIosSimulatorTarget get() = project.findProperty("ENABLE_TARGET_IOS_SIMULATOR") == "true"
val Project.enableAnyIosTarget get() = enableIosTarget || enableIosSimulatorTarget
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.pubnub.gradle
import com.vanniktech.maven.publish.MavenPublishPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.project
import org.gradle.kotlin.dsl.repositories
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.KtlintPlugin

Expand All @@ -16,6 +19,14 @@ class PubNubSharedPlugin : Plugin<Project> {
apply<MavenPublishPlugin>()
apply<KtlintPlugin>()

extensions.configure<PublishingExtension> {
repositories {
it.maven(uri(rootProject.layout.buildDirectory.dir("repo"))) { ->
name = "repo"
}
}
}

group = providers.gradleProperty("GROUP").get()
version = providers.gradleProperty("VERSION_NAME").get()

Expand All @@ -42,7 +53,7 @@ class PubNubSharedPlugin : Plugin<Project> {
}

dependencies {
"ktlintRuleset"(project(":build-logic:ktlint-custom-rules"))
"ktlintRuleset"("com.pubnub:ktlint-custom-rules:1.0.0")
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion build-logic/ktlint-custom-rules/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ plugins {
dependencies {
compileOnly("com.pinterest.ktlint:ktlint-rule-engine-core:1.2.1")
compileOnly("com.pinterest.ktlint:ktlint-cli-ruleset-core:1.2.1")
}
}

group = "com.pubnub"
version = "1.0.0"
4 changes: 4 additions & 0 deletions build-logic/ktlint-custom-rules/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.parallel=true
org.gradle.caching=true
#org.gradle.configureondemand=true
org.gradle.configuration-cache=true
17 changes: 17 additions & 0 deletions build-logic/ktlint-custom-rules/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../../gradle/libs.versions.toml"))
}
}
}
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ org.gradle.caching=true
org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
org.gradle.unsafe.configuration-cache=false

RELEASE_SIGNING_ENABLED=true
SONATYPE_HOST=DEFAULT
Expand All @@ -40,3 +39,8 @@ POM_DEVELOPER_NAME=PubNub
POM_DEVELOPER_URL=[email protected]

IOS_SIMULATOR_ID=iPhone 15 Pro
SWIFT_PATH=swift

ENABLE_TARGET_JS=false
ENABLE_TARGET_IOS=false
ENABLE_TARGET_IOS_SIMULATOR=false
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ okhttp = "4.12.0"
retrofit2 = "2.9.0"
nexus = "2.0.0-rc-2"
kotlin = "2.0.0"
vanniktech = "0.22.0"
vanniktech = "0.29.0"
ktlint = "12.1.0"
dokka = "1.9.20"
kotlinx_datetime = "0.6.0-RC.2"
Expand Down
2 changes: 1 addition & 1 deletion kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@ [email protected]:
iconv-lite "^0.6.3"
source-map-js "^1.0.2"

source-map-support@~0.5.20:
source-map-support@0.5.21, source-map-support@~0.5.20:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
Expand Down
6 changes: 3 additions & 3 deletions pubnub-core/pubnub-core-api/pubnub_core_api.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |spec|
spec.name = 'pubnub_core_api'
spec.version = '1.0'
spec.homepage = 'Link to a Kotlin/Native module homepage'
spec.version = '9.2.3'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = 'Some description for a Kotlin/Native module'
spec.summary = ''
spec.vendored_frameworks = 'build/cocoapods/framework/pubnub_core_api.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '14'
Expand Down
Loading

0 comments on commit 3e82af3

Please sign in to comment.