From a7c4ff7988e8e1a513310a399d394bd3e190c7d7 Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Mon, 25 Nov 2024 19:32:37 -0500 Subject: [PATCH] build: jgitver --- .editorconfig | 2 - .github/actions/run-with-avd/action.yml | 47 +++---- .github/actions/setup/action.yml | 13 +- .github/dependabot.yml | 3 +- .github/workflows/ci.yml | 134 ++++++++++++-------- .github/workflows/dependency-submission.yml | 20 +-- .github/workflows/release.yml | 57 +++++---- CONTRIBUTING.md | 3 +- build.gradle.kts | 5 +- demo-app/build.gradle.kts | 14 +- demo-app/demo_app.podspec | 2 +- gradle/libs.versions.toml | 1 + iosApp/Podfile.lock | 6 +- lib/maplibre-compose/build.gradle.kts | 7 +- 14 files changed, 186 insertions(+), 128 deletions(-) diff --git a/.editorconfig b/.editorconfig index 6786c6ca..b3dfee7a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,5 @@ root = true [*] end_of_line = lf insert_final_newline = true - -[*.{yml,json,kt,kts,swift,md}] indent_style = space indent_size = 2 diff --git a/.github/actions/run-with-avd/action.yml b/.github/actions/run-with-avd/action.yml index de104c21..f0b02f75 100644 --- a/.github/actions/run-with-avd/action.yml +++ b/.github/actions/run-with-avd/action.yml @@ -1,43 +1,44 @@ -name: 'Execute with AVD' -description: 'Set up an Android virtual device, cache it, and run a script' +--- +name: "Execute with AVD" +description: "Set up an Android virtual device, cache it, and run a script" inputs: api-level: - description: 'API level of the platform system image' + description: "API level of the platform system image" required: true script: - description: 'Custom script to run' + description: "Custom script to run" required: true runs: using: "composite" steps: - - name: Configure KVM - shell: bash + - name: "Configure KVM" + shell: "bash" run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - - name: Cache AVD - uses: actions/cache@v4 - id: avd-cache + - name: "Cache AVD" + uses: "actions/cache@v4" + id: "avd-cache" with: path: | ~/.android/avd/* ~/.android/adb* - key: avd-v${{ inputs.api-level }} - - name: Create AVD for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2 + key: "avd-v${{ inputs.api-level }}" + - name: "Create AVD for caching" + if: "steps.avd-cache.outputs.cache-hit != 'true'" + uses: "reactivecircus/android-emulator-runner@v2" with: - api-level: ${{ inputs.api-level }} - arch: x86_64 + api-level: "${{ inputs.api-level }}" + arch: "x86_64" force-avd-creation: false - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - script: echo "Generated AVD snapshot for caching." - - name: ${{ inputs.script }} - uses: reactivecircus/android-emulator-runner@v2 + emulator-options: "-no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none" + script: "echo 'Generated AVD snapshot for caching.'" + - name: "${{ inputs.script }}" + uses: "reactivecircus/android-emulator-runner@v2" with: - api-level: ${{ inputs.api-level }} - arch: x86_64 + api-level: "${{ inputs.api-level }}" + arch: "x86_64" force-avd-creation: false - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - script: ${{ inputs.script }} + emulator-options: "-no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none" + script: "${{ inputs.script }}" diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 13440b1a..88150346 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -1,13 +1,14 @@ -name: 'Setup' -description: 'Set up the build environment, used by most jobs' +--- +name: "Setup" +description: "Set up the build environment, used by most jobs" runs: using: "composite" steps: - - uses: actions/setup-java@v4 + - uses: "actions/setup-java@v4" with: - distribution: 'temurin' - java-version: '21' - - uses: gradle/actions/setup-gradle@v4 + distribution: "temurin" + java-version: "21" + - uses: "gradle/actions/setup-gradle@v4" with: build-scan-publish: true build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1b8d8f3a..542d3da0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,10 @@ +--- version: 2 updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "weekly" + interval: "weekly" - package-ecosystem: "gradle" directory: "/" schedule: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70640acd..4ea93810 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,91 +1,121 @@ -name: CI +--- +name: "CI" on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: "${{ github.workflow }}-${{ github.ref }}" cancel-in-progress: true jobs: check-format: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew spotlessCheck + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew spotlessCheck" + + check-podspec: + runs-on: "macos-latest" + steps: + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew podInstall" + - run: | + git diff -I '^COCOAPODS: [0-9]+\.[0-9]+\.[0-9]+$' --exit-code lint-android: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew lint + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew lint" test-android: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - name: Run with AVD ./gradlew connectedDebugAndroidTest - uses: ./.github/actions/run-with-avd + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - name: "Run with AVD ./gradlew connectedDebugAndroidTest" + uses: "./.github/actions/run-with-avd" with: api-level: 35 - script: ./gradlew connectedDebugAndroidTest + script: "./gradlew connectedDebugAndroidTest" test-ios: - runs-on: macos-latest + runs-on: "macos-latest" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew iosSimulatorArm64Test + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew iosSimulatorArm64Test" build-docs: - runs-on: macos-latest + runs-on: "macos-latest" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew dokkaHtmlMultiModule - - uses: actions/upload-pages-artifact@v3 + - uses: "actions/checkout@v4" with: - path: build/dokka/htmlMultiModule + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew dokkaHtmlMultiModule" + - uses: "actions/upload-pages-artifact@v3" + with: + path: "build/dokka/htmlMultiModule" build-android-app: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew packageDebug packageRelease - - uses: actions/upload-artifact@v4 + - uses: "actions/checkout@v4" with: - if-no-files-found: error - name: demo-app-debug - path: demo-app/build/outputs/apk/debug/demo-app-debug.apk - - uses: actions/upload-artifact@v4 + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew packageDebug" + - uses: "actions/upload-artifact@v4" with: - if-no-files-found: error - name: demo-app-release-unsigned - path: demo-app/build/outputs/apk/release/demo-app-release-unsigned.apk + if-no-files-found: "error" + name: "demo-app-debug" + path: "demo-app/build/outputs/apk/debug/demo-app-debug.apk" publish-snapshot: - needs: [test-android, test-ios] - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - runs-on: macos-latest + needs: + - "test-android" + - "test-ios" + if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}" + runs-on: "macos-latest" permissions: - packages: write + packages: "write" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew publishAllPublicationsToGitHubPackagesRepository + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew publishAllPublicationsToGitHubPackagesRepository" env: - ORG_GRADLE_PROJECT_githubToken: ${{ secrets.GITHUB_TOKEN }} - ORG_GRADLE_PROJECT_githubUser: ${{ github.actor }} + ORG_GRADLE_PROJECT_githubToken: "${{ secrets.GITHUB_TOKEN }}" + ORG_GRADLE_PROJECT_githubUser: "${{ github.actor }}" all-good: - needs: [check-format, lint-android, test-android, test-ios, build-docs, build-android-app] - runs-on: ubuntu-latest + needs: + - "check-format" + - "check-podspec" + - "lint-android" + - "test-android" + - "test-ios" + - "build-docs" + - "build-android-app" + runs-on: "ubuntu-latest" steps: - - run: echo "All checks passed!" + - run: "echo 'All checks passed!'" diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml index a6ae4651..d3ca52de 100644 --- a/.github/workflows/dependency-submission.yml +++ b/.github/workflows/dependency-submission.yml @@ -1,23 +1,25 @@ -name: Dependency Submission +--- +name: "Dependency Submission" on: push: - branches: [ 'main' ] + branches: + - "main" jobs: dependency-submission: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" permissions: - contents: write + contents: "write" steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 + - uses: "actions/checkout@v4" + - uses: "actions/setup-java@v4" with: - distribution: temurin + distribution: "temurin" java-version: 21 - - uses: gradle/actions/dependency-submission@v4 + - uses: "gradle/actions/dependency-submission@v4" with: build-scan-publish: true build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use" build-scan-terms-of-use-agree: "yes" - - uses: advanced-security/cocoapods-dependency-submission-action@v1.1 + - uses: "advanced-security/cocoapods-dependency-submission-action@v1.1" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b578c0df..7937b63f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,39 +1,46 @@ -name: Release +--- +name: "Release" on: - workflow_dispatch: + push: + tags: ["v*.*.*"] jobs: publish-maven: - runs-on: macos-latest + runs-on: "macos-latest" environment: - name: maven-central - url: https://central.sonatype.com/namespace/dev.sargunv.maplibre-compose + name: "maven-central" + url: "https://central.sonatype.com/namespace/dev.sargunv.maplibre-compose" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew publishAndReleaseToMavenCentral --no-configuration-cache" env: - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} - ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} - ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} + ORG_GRADLE_PROJECT_mavenCentralUsername: "${{ secrets.MAVEN_CENTRAL_USERNAME }}" + ORG_GRADLE_PROJECT_mavenCentralPassword: "${{ secrets.MAVEN_CENTRAL_PASSWORD }}" + ORG_GRADLE_PROJECT_signingInMemoryKey: "${{ secrets.GPG_PRIVATE_KEY }}" + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: "${{ secrets.GPG_PASSPHRASE }}" publish-pages: - needs: [publish-maven] - runs-on: macos-latest + needs: + - "publish-maven" + runs-on: "macos-latest" permissions: - pages: write - id-token: write + pages: "write" + id-token: "write" environment: - name: github-pages - url: ${{ steps.deploy-pages.outputs.page_url }} + name: "github-pages" + url: "${{ steps.deploy-pages.outputs.page_url }}" steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - run: ./gradlew dokkaHtmlMultiModule - - uses: actions/upload-pages-artifact@v3 + - uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - uses: "./.github/actions/setup" + - run: "./gradlew dokkaHtmlMultiModule" + - uses: "actions/upload-pages-artifact@v3" with: - path: build/dokka/htmlMultiModule - - uses: actions/deploy-pages@v4 - id: deploy-pages + path: "build/dokka/htmlMultiModule" + - uses: "actions/deploy-pages@v4" + id: "deploy-pages" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1ff21696..4c91dcfb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,4 +18,5 @@ run the tests: A Git pre-commit hook is available to ensure that the code is formatted before every commit. Run `./gradlew installGitHooks` to install it. It will run `./gradlew spotlessApply` before every -commit. +commit. To run the formatter, you'll need to have `swift` installed (for `swift format`) and `npm` +installed (for `prettier`). diff --git a/build.gradle.kts b/build.gradle.kts index c337dc8f..246ef641 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,6 @@ plugins { alias(libs.plugins.kotlin.cocoapods) apply false alias(libs.plugins.spotless) alias(libs.plugins.dokka) - alias(libs.plugins.maven.publish) apply false } spotless { @@ -22,6 +21,10 @@ spotless { target("**/*.md") flexmark() } + yaml { + target("**/*.yml", "**/*.yaml") + prettier().config(mapOf("quoteProps" to "consistent")) + } } tasks.register("installGitHooks") { diff --git a/demo-app/build.gradle.kts b/demo-app/build.gradle.kts index d51cc800..25763ddd 100644 --- a/demo-app/build.gradle.kts +++ b/demo-app/build.gradle.kts @@ -1,5 +1,6 @@ @file:OptIn(ExperimentalKotlinGradlePluginApi::class) +import fr.brouillard.oss.jgitver.Strategies import org.jetbrains.compose.ExperimentalComposeLibrary import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget @@ -13,9 +14,13 @@ plugins { alias(libs.plugins.kotlin.cocoapods) alias(libs.plugins.kotlin.serialization) alias(libs.plugins.spotless) + alias(libs.plugins.jgitver) } -version = project.properties["LIBRARY_VERSION"]!!.toString() +jgitver { + strategy(Strategies.PATTERN) + nonQualifierBranches("main") +} android { namespace = "dev.sargunv.maplibrecompose.demoapp" @@ -26,7 +31,7 @@ android { minSdk = libs.versions.android.minSdk.get().toInt() targetSdk = libs.versions.android.targetSdk.get().toInt() versionCode = 1 - versionName = project.properties["LIBRARY_VERSION"]!!.toString() + versionName = project.version.toString() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } @@ -53,7 +58,10 @@ kotlin { homepage = "PLACEHOLDER HOMEPAGE" ios.deploymentTarget = "15.3" podfile = project.file("../iosApp/Podfile") - framework { baseName = "DemoApp" } + framework { + baseName = "DemoApp" + version = "0.0.0" + } pod("MapLibre", libs.versions.maplibre.ios.get()) } diff --git a/demo-app/demo_app.podspec b/demo-app/demo_app.podspec index e00682cd..ccde1b36 100644 --- a/demo-app/demo_app.podspec +++ b/demo-app/demo_app.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'demo_app' - spec.version = '0.1.1-SNAPSHOT' + spec.version = '0.0.0' spec.homepage = 'PLACEHOLDER HOMEPAGE' spec.source = { :http=> ''} spec.authors = '' diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e728687d..d2c92215 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,6 +29,7 @@ android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } dokka = { id = "org.jetbrains.dokka", version = "1.9.20" } jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "compose" } +jgitver = { id = "fr.brouillard.oss.gradle.jgitver", version = "0.10.0-rc03" } kotlin-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } diff --git a/iosApp/Podfile.lock b/iosApp/Podfile.lock index 3ccfd021..1e7f11ce 100644 --- a/iosApp/Podfile.lock +++ b/iosApp/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - demo_app (0.1.1-SNAPSHOT): + - demo_app (0.0.0): - MapLibre (= 6.8.1) - MapLibre (6.8.1) @@ -15,9 +15,9 @@ EXTERNAL SOURCES: :path: "../demo-app" SPEC CHECKSUMS: - demo_app: 6a2ee1ca6577a342a7fce1edcfe6aa7270d36663 + demo_app: a5a32dc01c2392d3d763615568685a2318d40f44 MapLibre: 46c5f2254df2ea03bcd097778bb19c92207d8c2a PODFILE CHECKSUM: faffe0b5720ea7a96818a908bd93100321d4e51f -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.1 diff --git a/lib/maplibre-compose/build.gradle.kts b/lib/maplibre-compose/build.gradle.kts index f52f4f7e..cc583599 100644 --- a/lib/maplibre-compose/build.gradle.kts +++ b/lib/maplibre-compose/build.gradle.kts @@ -1,5 +1,6 @@ @file:OptIn(ExperimentalKotlinGradlePluginApi::class, ExperimentalComposeLibrary::class) +import fr.brouillard.oss.jgitver.Strategies import org.jetbrains.compose.ExperimentalComposeLibrary import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget @@ -14,12 +15,16 @@ plugins { alias(libs.plugins.spotless) alias(libs.plugins.dokka) alias(libs.plugins.maven.publish) + alias(libs.plugins.jgitver) id("maven-publish") } group = "dev.sargunv.maplibre-compose" -version = project.properties["LIBRARY_VERSION"]!!.toString() +jgitver { + strategy(Strategies.MAVEN) + nonQualifierBranches("main") +} android { namespace = "dev.sargunv.maplibrecompose"