diff --git a/.github/actions/java/action.yml b/.github/actions/java/action.yml new file mode 100644 index 0000000..dfee969 --- /dev/null +++ b/.github/actions/java/action.yml @@ -0,0 +1,9 @@ +name: "Set up Adopt OpenJDK 17" + +runs: + using: "composite" + steps: + - uses: actions/setup-java@v4 + with: + distribution: adopt + java-version: 17 diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml new file mode 100644 index 0000000..3db6f4f --- /dev/null +++ b/.github/actions/lint/action.yml @@ -0,0 +1,13 @@ +name: "Lint code" + +runs: + using: "composite" + steps: + - name: "Set up Adopt OpenJDK 17" + uses: ./.github/actions/java + - name: "Run Detekt" + shell: sh + run: sh gradlew detekt + - name: "Run KtLint" + shell: sh + run: sh gradlew ktlintCheck diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bb9c3e4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: "Lint and build code" + +on: + push: + branches: + - "**" + - "!main" + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: "Clone code" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Lint code" + uses: ./.github/actions/lint + + build: + needs: lint + runs-on: macos-latest + steps: + - name: "Clone code" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Set up Adopt OpenJDK 17" + uses: ./.github/actions/java + - name: "Validate Gradle wrapper" + uses: gradle/wrapper-validation-action@v1 + - name: "Build code" + shell: sh + run: sh gradlew build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c5974df..aab9322 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,27 +1,44 @@ -name: Publish +name: "Lint and build code, and publish artifacts to repository" + on: - create: - tags: - - '^[0-9]+\.[0-9]+\.[0-9]+$' + push: + branches: + - "main" + jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: "Clone code" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Lint code" + uses: ./.github/actions/lint + build: + needs: lint runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - name: "Clone code" + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up Adopt OpenJDK 17 - uses: actions/setup-java@v3 - with: - distribution: adopt - java-version: 17 - - name: Validate Gradle wrapper + - name: "Set up Adopt OpenJDK 17" + uses: ./.github/actions/java + - name: "Validate Gradle wrapper" uses: gradle/wrapper-validation-action@v1 - - name: Publish to GitHub Packages - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} - GITHUB_ACCESS_TOKEN_READ_PACKAGES: ${{ secrets.ACCESS_TOKEN_READ_PACKAGES }} - shell: sh - run: | - sh gradlew --no-daemon publishAllPublicationsToAirthingsGitHubPackagesRepository + + publish: + needs: build + permissions: + contents: write + packages: write + uses: touchlab/KMMBridgeGithubWorkflow/.github/workflows/faktorybuildautoversion.yml@v1.1 + with: + runsOn: "macOS-14" + jvmVersion: 17 + versionBaseProperty: LIBRARY_VERSION + publishTask: kmmBridgePublish publishAllPublicationsToGitHubPackagesRepository + secrets: + gradle_params: -PGITHUB_PUBLISH_USER=${{ secrets.GITHUB_ACTOR }} -PGITHUB_PUBLISH_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_REPO=https://github.com/Airthings/KmpLog.git diff --git a/build.gradle.kts b/build.gradle.kts index c976e8d..fb60375 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,8 +17,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -rootProject.group = "com.airthings.lib" -rootProject.version = "0.2.6" +private val version = (properties["AUTO_VERSION"] ?: properties["LIBRARY_VERSION"])?.toString() + ?: error("Fatal error: unable to determine the library version.") + +private val iosFrameworkName = "KmpLog" + +rootProject.group = "${properties["GROUP"]}" +rootProject.version = version buildscript { repositories { @@ -52,6 +57,7 @@ plugins { id("com.github.ben-manes.versions") id("com.android.library") id("maven-publish") + id("co.touchlab.kmmbridge") } dependencies { @@ -105,7 +111,7 @@ kotlin { linkerOpts += "-ld64" } it.binaries.framework { - baseName = rootProject.name + baseName = iosFrameworkName } } @@ -120,6 +126,15 @@ kotlin { } } + // See for details: https://youtrack.jetbrains.com/issue/KT-61573 + targets.all { + compilations.all { + compilerOptions.configure { + freeCompilerArgs.add("-Xexpect-actual-classes") + } + } + } + sourceSets { val commonMain by getting { dependencies { @@ -170,18 +185,16 @@ android { } } -publishing { - repositories { - mavenLocal() - maven { - name = "AirthingsGitHubPackages" - url = uri("https://maven.pkg.github.com/airthings/kmplog") - - credentials { - // The following are automatically generated by GitHub. - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") - } - } - } +kmmbridge { + frameworkName.set(iosFrameworkName) + mavenPublishArtifacts() + spm( + spmDirectory = "./", + swiftToolVersion = "5.9", + targetPlatforms = { + iOS { v("15") } + }, + ) } + +addGithubPackagesRepository() diff --git a/gradle.properties b/gradle.properties index 235c22b..0f0d858 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,12 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +# Versioning: +# Note 1: KMMBridge manages the patch number automatically, so please leave it out below. +# Note 2: Bump up the minor version when big changes happen, otherwise leave the version intact. +GROUP=com.airthings.lib +LIBRARY_VERSION=0.2 + # Gradle/KMP options: org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" kotlin.code.style=official @@ -42,9 +48,10 @@ version.plugin.androidGradle=8.1.2 version.plugin.ktlintGradle=11.6.1 version.plugin.detekt=1.23.3 version.plugin.outdated=0.49.0 +version.plugin.kmmbridge=0.5.5 # Dependencies: -version.kotlin=1.9.22 +version.kotlin=1.9.23 version.kotlin.coroutines=1.7.3 version.kotlin.datetime=0.4.1 version.stately.concurrency=1.2.3 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/settings.gradle.kts b/settings.gradle.kts index 6ed4b72..04774d3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -36,6 +36,7 @@ pluginManagement { "org.jlleitschuh.gradle.ktlint" -> useVersion("${props["version.plugin.ktlintGradle"]}") "com.github.ben-manes.versions" -> useVersion("${props["version.plugin.outdated"]}") "com.android.library" -> useVersion("${props["version.plugin.androidGradle"]}") + "co.touchlab.kmmbridge" -> useVersion("${props["version.plugin.kmmbridge"]}") } } }