|
| 1 | +name: Kotlin-name stubs |
| 2 | + |
| 3 | +# Issue #32: pythonx-compose consumes the binder's Kotlin-name `.pyi` stubs for the real Compose jars |
| 4 | +# but cannot run this repository's Gradle build. This job runs the stub task over the Compose version the |
| 5 | +# build resolves (`compose-plugin` in gradle/libs.versions.toml) and publishes the result. |
| 6 | +# |
| 7 | +# - every push to develop and every pull request: the stubs are generated, type-checked against |
| 8 | +# tools/stubs/consumer.py with mypy (issue #31), and uploaded as the workflow artifact `kotlin-stubs`; |
| 9 | +# - every `v*` tag: the same stubs are also attached to the tag's GitHub release as `kotlin-stubs.zip`. |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: [ "develop" ] |
| 14 | + tags: [ "v*" ] |
| 15 | + pull_request: |
| 16 | + branches: [ "develop" ] |
| 17 | + paths: |
| 18 | + - "python-multiplatform-gradle-plugin/**" |
| 19 | + - "ksp-fixtures/compose/**" |
| 20 | + - "tools/stubs/**" |
| 21 | + - "gradle/libs.versions.toml" |
| 22 | + - ".github/workflows/stubs.yml" |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: stubs-${{ github.ref }} |
| 30 | + cancel-in-progress: true |
| 31 | + |
| 32 | +jobs: |
| 33 | + stubs: |
| 34 | + name: Generate stubs |
| 35 | + # ubuntu, not macos: two Kotlin names can differ only by case (`graphics.Shadow` the class module and |
| 36 | + # `graphics.shadow` the package), which are two paths here and one on a case-insensitive filesystem. |
| 37 | + runs-on: ubuntu-latest |
| 38 | + permissions: |
| 39 | + contents: write # attaching the stubs to a tag's release |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Setup Java |
| 45 | + uses: actions/setup-java@v4 |
| 46 | + with: |
| 47 | + java-version: '21' |
| 48 | + distribution: 'zulu' |
| 49 | + cache: 'gradle' |
| 50 | + |
| 51 | + - name: Setup Python (for mypy) |
| 52 | + uses: actions/setup-python@v5 |
| 53 | + with: |
| 54 | + python-version: '3.13' |
| 55 | + |
| 56 | + - name: Generate the stubs over the Compose jars |
| 57 | + run: ./gradlew :ksp-fixtures:compose:generatePythonStubs --console=plain |
| 58 | + |
| 59 | + - name: Type-check a consumer against them (mypy) |
| 60 | + run: tools/stubs/check-stubs.sh ksp-fixtures/compose/build/generated/pythonStubs/desktopMain |
| 61 | + |
| 62 | + - name: Assemble the artifact |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | + compose_version="$(sed -nE 's/^compose-plugin = "([^"]+)".*/\1/p' gradle/libs.versions.toml)" |
| 66 | + test -n "$compose_version" |
| 67 | + out=build/kotlin-stubs |
| 68 | + rm -rf "$out" |
| 69 | + mkdir -p "$out" |
| 70 | + cp -R ksp-fixtures/compose/build/generated/pythonStubs/desktopMain/. "$out/" |
| 71 | + cat > "$out/README.md" <<README |
| 72 | + # Kotlin-name stubs for Compose ${compose_version} |
| 73 | +
|
| 74 | + \`.pyi\` stubs for the Kotlin declarations the python-multiplatform binder serves, under the |
| 75 | + **Kotlin** module paths and Kotlin names (\`androidx.compose.material3.Checkbox\`, parameters by |
| 76 | + their Kotlin names). Nothing here is renamed or Pythonic; that is pythonx-compose's layer. |
| 77 | +
|
| 78 | + | | | |
| 79 | + |---|---| |
| 80 | + | Compose | ${compose_version} (desktop jars) | |
| 81 | + | python-multiplatform commit | ${GITHUB_SHA} | |
| 82 | + | ref | ${GITHUB_REF} | |
| 83 | + | workflow run | ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} | |
| 84 | + | generator | \`:ksp-fixtures:compose:generatePythonStubs\` | |
| 85 | +
|
| 86 | + Packages stubbed: the \`artifactIncludePackages\` of \`ksp-fixtures/compose/build.gradle.kts\` at |
| 87 | + that commit. |
| 88 | +
|
| 89 | + Use: put this directory on the type checker's path (\`MYPYPATH=<this directory>\`, or the |
| 90 | + IDE's "stub path" / interpreter paths). It is checked with mypy against |
| 91 | + \`tools/stubs/consumer.py\` in the commit above. |
| 92 | + README |
| 93 | + (cd build && zip -qr kotlin-stubs.zip kotlin-stubs) |
| 94 | +
|
| 95 | + - name: Upload the stubs |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: kotlin-stubs |
| 99 | + path: build/kotlin-stubs |
| 100 | + if-no-files-found: error |
| 101 | + |
| 102 | + - name: Attach the stubs to the tag's release |
| 103 | + if: startsWith(github.ref, 'refs/tags/') |
| 104 | + env: |
| 105 | + GH_TOKEN: ${{ github.token }} |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | + gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 \ |
| 109 | + || gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes "Kotlin-name stubs for the Compose version this tag builds against." |
| 110 | + gh release upload "$GITHUB_REF_NAME" build/kotlin-stubs.zip --clobber |
0 commit comments