Skip to content
Back to skills

Kmp Ci Github Actions

ASecurity

Use when setting up, fixing or speeding up GitHub Actions CI for a Kotlin Multiplatform (Android + iOS) project - .github/workflows YAML, "add CI", macos-latest, macos-26 or xcode-27 runners, an old iosX64 or Intel macOS job, iosSimulatorArm64Test in CI, ~/.konan re-downloading every run, setup-gradle caching, Xcode or JDK version selection, slow or expensive macOS jobs, test or Kover reports as artifacts, or a release workflow with signing secrets.

  • 17 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentpythongojavarubyswiftkotlinshellbashexpressgit

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add Kushpawan/kmp-mobile-skills --skill kmp-ci-github-actions --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Kmp Ci Github Actions?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Kmp Ci Github Actions
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kushpawan-kmp-ci-github-actions/badge)](https://www.skillsdirectory.com/skills/kushpawan-kmp-ci-github-actions)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: kmp-ci-github-actions
description: Use when setting up, fixing or speeding up GitHub Actions CI for a Kotlin Multiplatform (Android + iOS) project - .github/workflows YAML, "add CI", macos-latest, macos-26 or xcode-27 runners, an old iosX64 or Intel macOS job, iosSimulatorArm64Test in CI, ~/.konan re-downloading every run, setup-gradle caching, Xcode or JDK version selection, slow or expensive macOS jobs, test or Kover reports as artifacts, or a release workflow with signing secrets.
license: Apache-2.0
compatibility: Kotlin Multiplatform Gradle project hosted on GitHub. iOS jobs use GitHub-hosted Apple-silicon macOS runners. Runner images, Xcode pairs and action versions verified December 2026.
metadata:
  category: release
  platforms: android, ios
---

# KMP CI on GitHub Actions

Split the pipeline by what each host can build: Linux runs the shared code, Android compile, host
tests and lint cheaply; macOS runs only what needs Apple tooling — the iOS framework link and the
iOS simulator tests. Signing secrets never appear in the pull-request workflow; they live in a
separate release workflow behind a protected environment.

## When to use

- Adding CI to a KMP repository, or porting a pipeline from another CI system to GitHub Actions.
- CI is slow: Kotlin/Native toolchain downloaded on every run, cold Gradle caches, macOS minutes
  burned on work Linux could do.
- iOS compile or link errors only show up after merge.
- Choosing runner labels and the Xcode that matches the project's Kotlin version.
- Removing a legacy x86_64 (`iosX64`, Intel macOS) job.
- Adding a release workflow that signs and uploads both apps.

## When not to use

- A specific build failure you need to diagnose: use `kmp-build-failure-triage`.
- A test that fails only in CI or only sometimes: use `kmp-flaky-test-triage`.
- Versioning, store tracks, Fastlane lanes and the release checklist: use `mobile-release`
  (this skill only runs those lanes).
- Slow Kotlin/Native builds in general (local and CI): see the Kotlin native build performance
  skill linked below.
- Bumping Kotlin, AGP, Gradle, Compose Multiplatform or Xcode: use `kmp-toolchain-upgrade`, then
  come back to align the workflow.
- Dependency vulnerability scanning, lockfiles, SBOMs and Dependabot: use `kmp-dependency-security`
  (planned for v0.2.0). This skill's workflows build and test only.

## Step 0 — Read the project first

```bash
ls .github/workflows 2>/dev/null && cat .github/workflows/*.yml   # existing pipelines to extend, not replace
ls .gitlab-ci.yml bitrise.yml .circleci 2>/dev/null               # pipeline being ported
cat gradle/wrapper/gradle-wrapper.properties                       # Gradle version
grep -nE '^(kotlin|agp|android-gradle|androidGradlePlugin|compose-multiplatform|kover)\b' gradle/libs.versions.toml
grep -rnE "jvmToolchain|JvmTarget" --include='*.kts' . | head        # JDK the build expects
cat .java-version .tool-versions 2>/dev/null
grep -rnE "iosX64|iosArm64|iosSimulatorArm64" --include=build.gradle.kts . | head
grep -nE "configuration-cache|org.gradle.caching|jvmargs" gradle.properties
find . -maxdepth 2 \( -name '*.xcodeproj' -o -name '*.xcworkspace' -o -name Gemfile -o -name fastlane \)
./gradlew :shared:tasks --all | grep -iE 'test|lint|kover|link.*Framework' | head -40
```

Record: module and task names, the Kotlin, AGP, Gradle and Compose Multiplatform versions, the JDK,
iOS targets declared, whether Kover/detekt/ktlint are applied, the Xcode project path and scheme, and
whether Fastlane exists. Use the real task names in every `run:` step. The Kotlin version picks the
Xcode and the macOS runner (step 5).

## Workflow

### 1. Split jobs by host

| Job | Runner | Runs | Why there |
|---|---|---|---|
| `android` | `ubuntu-latest` | `compileCommonMainKotlinMetadata`, Android host tests, lint, `assembleDebug`, Kover | Cheapest runner; Apple targets are skipped automatically on Linux |
| `ios` | `xcode-27` for Kotlin 2.5; `macos-26` for Kotlin 2.4 (both arm64) | `linkDebugFrameworkIosSimulatorArm64`, `iosSimulatorArm64Test`, optional `xcodebuild build` | Kotlin/Native for Apple targets needs macOS + the matching Xcode |

There is no x86_64 job. Compose Multiplatform 1.11+ removed `iosX64`, and Xcode 27 runs only on Apple
silicon. If an older workflow has an `iosX64Test` job on `macos-15-intel`, delete it along with the
`iosX64()` target.

Run `android` and `ios` in parallel. Do not run Android work on macOS: macOS minutes cost more
and the queue is longer.

Done when: every check the team runs locally before a PR is in exactly one job.

### 2. Start from the asset

Copy [assets/ci.yml](assets/ci.yml) to `.github/workflows/ci.yml` and replace every `TODO` with the
names from Step 0. It already contains the pieces below; adjust rather than rewrite.

### 3. Java and Gradle

- `actions/setup-java@v6` with `distribution: temurin` and the JDK the build expects. JDK 17 is the
  floor: the Kotlin 2.5 compiler and AGP 9.5 both need it. Use 21 if the project's toolchain does.
  `java-version-file: .java-version` reads it from the repo instead.
- The Gradle **wrapper** decides the Gradle version, not the workflow. AGP 9.5 needs Gradle 9.6.0 or
  newer; Kotlin 2.5.0 is tested with Gradle 8.14–9.8.1. Bump with
  `./gradlew wrapper --gradle-version <version>` and commit the wrapper files. Do not set
  `gradle-version:` on setup-gradle.
- `gradle/actions/setup-gradle@v6` owns Gradle caching and validates the wrapper checksum. Do not
  also set `cache: gradle` on setup-java; two caches of the same directory waste time and quota.
- **Cache provider (decide once per organisation).** In v6 the default `enhanced` provider is a
  closed-source component under Gradle's Terms of Use (free for public repositories, preview for
  private ones). `cache-provider: basic` is MIT-licensed, built on `actions/cache`, free everywhere,
  with coarser keys. The asset uses `basic`; switch if the team accepts the terms.
- By default only the default branch writes the Gradle cache; pull requests read it. Keep that.
- **Configuration cache:** `org.gradle.configuration-cache=true` in `gradle.properties` is a
  project choice, not a CI flag. setup-gradle v6 does not persist configuration-cache entries
  between runs (its experimental support was removed), so in CI it mainly proves compatibility. Put
  all tasks in **one** Gradle invocation per job so configuration happens once.

### 4. Kotlin/Native toolchain cache

Kotlin/Native downloads its compiler and LLVM dependencies into `~/.konan` on first use — large,
and slow to fetch. setup-gradle does not cache it. Cache it with `actions/cache@v6`, keyed on the
Kotlin version read from the catalog plus runner OS and architecture. JetBrains'
[kotlin-tooling-native-build-performance](https://github.com/Kotlin/kotlin-agent-skills/tree/main/skills/kotlin-tooling-native-build-performance)
skill covers the rest of a slow iOS job (link times, KSP on the native path, `transitiveExport`):

```yaml
- name: Read Kotlin version
  id: kotlin
  run: |
    version=$(sed -nE 's/^kotlin[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' gradle/libs.versions.toml | head -n 1)
    echo "version=${version:-unknown}" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v6
  with:
    path: ~/.konan
    key: konan-${{ runner.os }}-${{ runner.arch }}-${{ steps.kotlin.outputs.version }}
```

No `restore-keys`: an old Kotlin's toolchain is useless to a new one and only bloats the entry.
If the Kotlin version is not in `libs.versions.toml`, change the `sed` to read wherever it lives.

### 5. Xcode and runners

Each Kotlin release line supports one Xcode line, and GitHub ships Xcode 27 on its own image. Pick
the runner from the Kotlin version:

| Kotlin | Xcode ([compatibility guide](https://kotlinlang.org/docs/multiplatform/multiplatform-compatibility-guide.html)) | Runner label | Xcode on that image (Nov 2026) |
|---|---|---|---|
| 2.5.0 | 27.0 | `xcode-27` (macOS 27, arm64) | 27.0, 27.1 (default), 27.2 |
| 2.4.0–2.4.21 | 26.4 | `macos-26` = `macos-latest` (arm64) | 26.0.1–26.6 (default 26.6) |

- Select Xcode explicitly with `maxim-lobanov/setup-xcode@v1` and pin the version the guide lists:
  `'27.0'` for Kotlin 2.5, `'26.4'` for Kotlin 2.4. Move to a newer minor on purpose, after a green
  run. The image default moves without notice.
- `macos-latest`, `macos-26` and `macos-15` carry Xcode 26.x or older, never 27. Kotlin 2.5 on those
  labels fails in Kotlin/Native, not in your code.
- Xcode 27 runs only on Apple silicon. The `-intel` and `-large` macOS labels are x86_64 and carry
  Xcode 26.x at most.
- Image contents change every few weeks. Check the image's readme in
  [actions/runner-images](https://github.com/actions/runner-images) (the "Xcode" table) before pinning.
- Add a `xcodebuild -version` step so the log shows which Xcode ran.

### 6. Triggers, concurrency, path filters

```yaml
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}
```

New pushes cancel the stale PR run; `main` runs always finish. Use `paths-ignore` for docs-only
changes — but if a job is a **required** status check, a skipped workflow leaves the check pending
and blocks merge. Either keep required workflows unfiltered, or filter inside the job.

Set `permissions: contents: read` at the top. Add more only to the job that needs it.

### 7. Reports as artifacts

Upload with `actions/upload-artifact@v7` and `if: ${{ !cancelled() }}` so reports survive a failing
test step:

- tests: `**/build/reports/tests/` and `**/build/test-results/`
- lint: `**/build/reports/lint-results-*.html`
- Kover: run `koverXmlReport` (and `koverHtmlReport` if wanted), upload `**/build/reports/kover/`

Use distinct artifact names per job; v4+ artifacts are immutable and a duplicate name fails.
Set `retention-days` (7 for CI is plenty).

### 8. Optional iOS app build

`linkDebugFrameworkIosSimulatorArm64` proves the framework links; it does not prove the Swift code
still compiles against the changed Kotlin API. Add the commented `xcodebuild … CODE_SIGNING_ALLOWED=NO
build` step from the asset when the iOS app has meaningful Swift code. If the Xcode project runs a
Gradle build phase, the JDK from setup-java must be set up first in that job.

### 9. Release workflow

Copy [assets/release.yml](assets/release.yml). It triggers on app tags (`android-v*`, `ios-v*`) or
a manual run, checks that the tag matches the version in `gradle.properties`, and runs the Fastlane
lanes from `mobile-release`. Rules:

- Secrets exist only in this workflow, only on a GitHub **environment** (`release`) with required
  reviewers and a deployment-branch/tag rule.
- Never trigger it from `pull_request` or `pull_request_target`; fork code must never see signing
  secrets.
- Decode the keystore into `$RUNNER_TEMP`, never into the workspace; delete it in an
  `if: always()` step.
- Keep the R8 `mapping.txt` and the iOS dSYMs as artifacts — they are needed to symbolicate crashes.
- `cache-read-only: true` on setup-gradle: release jobs must not write the shared cache.

### 10. Porting from GitLab CI

`stages` become `needs:` between jobs; `rules: changes:` become `paths`/`paths-ignore`; protected
variables become environment secrets; `tags:` selecting a macOS runner become `runs-on:` labels.

## Quick reference

| Need | Use |
|---|---|
| Checkout | `actions/checkout@v7` |
| JDK | `actions/setup-java@v6` + `distribution: temurin`, 17 or newer |
| Gradle version | the wrapper; 9.6.0+ for AGP 9.5 |
| Gradle + cache | `gradle/actions/setup-gradle@v6` (`cache-provider: basic` or default `enhanced`) |
| `~/.konan` | `actions/cache@v6`, key on Kotlin version + `runner.os` + `runner.arch` |
| Xcode | `maxim-lobanov/setup-xcode@v1`, pinned per Kotlin version (step 5) |
| Reports | `actions/upload-artifact@v7`, `if: ${{ !cancelled() }}` |
| Ruby + Fastlane | `ruby/setup-ruby@v1` with `bundler-cache: true` |
| Linux | `ubuntu-latest` (x64) · `ubuntu-24.04-arm` (arm64) |
| macOS arm64, Xcode 27 | `xcode-27` (`xcode-27-xlarge` paid) |
| macOS arm64, Xcode 26.x | `macos-latest` = `macos-26`, `macos-15` |
| macOS x86_64 | none for KMP iOS work: Xcode 27 is Apple silicon only |

## Verify

Report each check as `PASS`, `FAIL` or `NOT RUN` with the reason. Never mark a check PASS that you
did not run.

```bash
ruby -ryaml -e 'ARGV.each { |f| YAML.safe_load(File.read(f)); puts "#{f}: ok" }' .github/workflows/*.yml   # YAML parses
python3 -c 'import sys, yaml; [yaml.safe_load(open(f)) for f in sys.argv[1:]]; print("ok")' .github/workflows/*.yml   # if PyYAML is installed
actionlint                                       # if installed: schema, expressions, shellcheck of run steps
./gradlew help --task :shared:iosSimulatorArm64Test   # every task named in the YAML exists (repeat per task)
grep -n "secrets\." .github/workflows/ci.yml     # expect no output: no secrets in PR CI
grep -nE "iosX64|macos-[0-9]+-intel" .github/workflows/*.yml   # expect no output: no x86_64 jobs left
```

Then push a branch and open a draft PR: confirm both jobs start, the iOS job restores `~/.konan` on
the second run (cache hit in the step log), and the report artifacts appear on the run page.
A workflow that only parses is `NOT RUN` for execution until a real run has been observed.

## Common mistakes

| Mistake | Why it bites | Fix |
|---|---|---|
| Everything on macOS | Slower queue, higher cost, same result for Android work | Linux for common/Android, macOS for Apple targets only |
| No `~/.konan` cache | Every iOS run re-downloads the Kotlin/Native toolchain | `actions/cache` keyed on the Kotlin version |
| `restore-keys` on the konan cache | Restores an old toolchain next to the new one; the entry keeps growing | Exact key only |
| `cache: gradle` on setup-java **and** setup-gradle | Double caching of the same directory | Let setup-gradle own it |
| One Gradle call per step | Configuration and daemon start-up repeated per step | One invocation with `--continue` |
| Kotlin 2.5 on `macos-latest` | That image has Xcode 26.x; Kotlin 2.5 needs Xcode 27 | `runs-on: xcode-27` + `xcode-version: '27.0'` |
| Keeping an `iosX64Test` job on an Intel runner | CMP 1.11+ removed `iosX64`; Xcode 27 is Apple silicon only | Delete the job and the target; `iosSimulatorArm64Test` covers the simulator |
| JDK 11 in `setup-java` | The Kotlin 2.5 compiler and AGP 9.5 need JDK 17 | `java-version: '17'` or newer |
| Gradle wrapper older than 9.6.0 with AGP 9.5 | AGP refuses to configure | `./gradlew wrapper --gradle-version <9.6.0+>` and commit |
| Adding a vulnerability scanner to this PR workflow ad hoc | Scanner, lockfile and SBOM choices are a separate decision | Use `kmp-dependency-security` |
| Unpinned Xcode in release | The image default changes and the App Store build changes with it | Pin `xcode-version` |
| Signing secrets in the PR workflow | Any workflow change in a PR can exfiltrate them | Separate release workflow + protected environment |
| `paths-ignore` on a required check | Docs-only PRs stay blocked on a pending check | Unfiltered required workflow or in-job filtering |
| Reports uploaded only on success | The run you need to debug has no report | `if: ${{ !cancelled() }}` |
| Same artifact name in two jobs | Upload fails: artifacts are immutable | One name per job |
| Moving to the v6 cache provider without reading its terms | Licence surprise for a private repository | Pick `basic` or `enhanced` deliberately |

## Related skills

- `kmp-build-check` — the local both-platform check this CI mirrors.
- `mobile-release` — versioning, tags, store tracks and the Fastfile the release workflow calls.
- `kmp-build-failure-triage`, `kmp-flaky-test-triage` — when a CI run fails.
- `kmp-test-coverage-backfill` — raising Kover numbers once reports are published.
- `kmp-xcframework-distribution` — publishing a framework from CI.
- `kmp-toolchain-upgrade` — the Kotlin / AGP / Gradle / Compose Multiplatform / Xcode upgrade plan
  this workflow must follow.
- `kmp-dependency-security` (planned for v0.2.0) — dependency scanning, lockfiles and SBOMs in CI.
- External: [gradle/actions](https://github.com/gradle/actions) ·
  [actions/runner-images](https://github.com/actions/runner-images) ·
  [Kotlin native build performance skill](https://github.com/Kotlin/kotlin-agent-skills/tree/main/skills/kotlin-tooling-native-build-performance) ·
  [fastlane docs](https://docs.fastlane.tools).

Files in this skill

  • SKILL.md16.2 KB
  • assets/ci.yml6.1 KB
  • assets/release.yml6.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.