Merge pull request #1016 from meshtastic/ci/kmp-build-cache #42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish KMP snapshot | |
| on: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - "meshtastic/**/*.proto" | |
| - "nanopb.proto" | |
| - "packages/kmp/**" | |
| # Allow republishing on demand (e.g. after a versioning-scheme change that | |
| # touches only this workflow, which the push paths above don't match). | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }} | |
| GRADLE_CACHE_USERNAME: ${{ secrets.GRADLE_CACHE_USERNAME }} | |
| GRADLE_CACHE_PASSWORD: ${{ secrets.GRADLE_CACHE_PASSWORD }} | |
| jobs: | |
| publish-snapshot: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Java | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: "21" | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v4 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v6 | |
| - name: Cache Konan (Kotlin/Native toolchain) | |
| uses: actions/cache@v6 | |
| with: | |
| path: ~/.konan | |
| key: konan-${{ runner.os }}-${{ hashFiles('packages/kmp/build.gradle.kts', 'packages/kmp/gradle/wrapper/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| konan-${{ runner.os }}- | |
| - name: Set version name | |
| run: | | |
| # Name the snapshot after the latest tag (v-stripped), the commit count | |
| # since that tag, and the short SHA, e.g. 2.7.26.88-gd77b460-SNAPSHOT. | |
| # | |
| # The count goes after a DOT, not a hyphen, and that is load-bearing. In | |
| # Maven's ComparableVersion a dot-separated numeric segment outranks ANY | |
| # hyphen-nested token, so these sort ABOVE the legacy `<tag>-<sha>-SNAPSHOT` | |
| # snapshots still in the repo — whose SHA can tokenize to a huge integer | |
| # (e.g. 678281c -> 678281) that would otherwise dwarf the count and mask | |
| # every new snapshot from dependency bots. Among themselves, higher count = | |
| # newer commit sorts higher, so bots pick the newest. Still sorts ABOVE the | |
| # tag's release (no downgrade) and BELOW the next release. `--long` forces | |
| # the -<N>-g<sha> suffix even on a tagged commit, so a bare `-SNAPSHOT` | |
| # (which sorts below its base) is never produced. (Local fallback in | |
| # build.gradle.kts still uses bare `-SNAPSHOT`.) | |
| # | |
| # Parsed right-to-left (describe = <tag>-<N>-g<sha>) so a hyphenated tag | |
| # like v1.2.3-rc1 would still split correctly. | |
| DESCRIBE=$(git describe --tags --long); DESCRIBE=${DESCRIBE#v} | |
| SHA=${DESCRIBE##*-}; REST=${DESCRIBE%-*}; COUNT=${REST##*-}; TAG=${REST%-*} | |
| echo "VERSION_NAME=${TAG}.${COUNT}-${SHA}-SNAPSHOT" >> "$GITHUB_ENV" | |
| - name: Build KMP package | |
| run: packages/kmp/gradlew --no-daemon -p packages/kmp build -PVERSION_NAME=${{ env.VERSION_NAME }} | |
| - name: Publish snapshot to Maven Central | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_SIGNING_KEY }} | |
| run: | | |
| set -euo pipefail | |
| if [ -z "${ORG_GRADLE_PROJECT_mavenCentralUsername}" ] || [ -z "${ORG_GRADLE_PROJECT_mavenCentralPassword}" ]; then | |
| echo "Missing Maven Central secrets — skipping snapshot publish." >&2 | |
| exit 0 | |
| fi | |
| packages/kmp/gradlew --no-daemon -p packages/kmp publishAllPublicationsToMavenCentralRepository -PVERSION_NAME=${{ env.VERSION_NAME }} |