|
| 1 | +name: Publish SharedCore |
| 2 | + |
| 3 | +# Cuts a release of the `:kmp:shared-core` XCFramework into |
| 4 | +# code-payments/flipcash-shared-core-spm, which is the repo iOS depends on. The |
| 5 | +# Kotlin stays here; that repo only ever holds the generated `Package.swift` and |
| 6 | +# the release assets it points at. |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version: |
| 11 | + description: 'Version to publish, e.g. 0.1.0 — also the Swift Package tag' |
| 12 | + required: true |
| 13 | + |
| 14 | +concurrency: |
| 15 | + # Two publishes at once would race on the same tag and release. |
| 16 | + group: publish-shared-core |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +env: |
| 20 | + CI: true |
| 21 | + SPM_REPO: code-payments/flipcash-shared-core-spm |
| 22 | + |
| 23 | +jobs: |
| 24 | + publish: |
| 25 | + name: Publish SharedCore ${{ inputs.version }} |
| 26 | + # Apple targets and `swift package compute-checksum` both need Xcode, so this |
| 27 | + # lane can't share the Ubuntu runners the rest of CI uses. |
| 28 | + runs-on: macos-15 |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 1 |
| 33 | + |
| 34 | + - name: Validate Gradle wrapper |
| 35 | + uses: gradle/actions/wrapper-validation@v4 |
| 36 | + |
| 37 | + - name: Setup Java env |
| 38 | + uses: actions/setup-java@v3 |
| 39 | + with: |
| 40 | + java-version: '21' |
| 41 | + distribution: 'corretto' |
| 42 | + cache: 'gradle' |
| 43 | + |
| 44 | + # A fine-grained PAT with Contents: read & write on the Swift Package repo. |
| 45 | + # The job's own GITHUB_TOKEN can't reach another repository, and a deploy |
| 46 | + # key can only push git — it can't create the GitHub release the |
| 47 | + # XCFramework is uploaded to — so one PAT covers both halves. |
| 48 | + - name: Check out the Swift Package repo |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + repository: ${{ env.SPM_REPO }} |
| 52 | + path: spm-repo |
| 53 | + token: ${{ secrets.SHARED_CORE_PUBLISH_TOKEN }} |
| 54 | + |
| 55 | + # Gradle configures every project in the build, and the Android app applies the |
| 56 | + # secrets plugin, which fails configuration outright when `local.properties` is |
| 57 | + # absent. This lane only builds the KMP module — nothing here compiles the app or |
| 58 | + # talks to any of these services — so obviously-fake values are enough to get |
| 59 | + # through configuration without handing this workflow the real secrets. |
| 60 | + - name: Write placeholder local.properties |
| 61 | + run: | |
| 62 | + set -euo pipefail |
| 63 | + { |
| 64 | + echo 'BUGSNAG_API_KEY="00000000000000000000000000000000"' |
| 65 | + echo 'GOOGLE_CLOUD_PROJECT_NUMBER=000000000000' |
| 66 | + echo 'MIXPANEL_API_KEY="00000000000000000000000000000000"' |
| 67 | + echo 'COINBASE_ONRAMP_API_KEY=00000000-0000-0000-0000-000000000000' |
| 68 | + } > ./local.properties |
| 69 | +
|
| 70 | + # The Swift half of the package lives here, next to the Kotlin it wraps, so the |
| 71 | + # two move in one commit; the Swift Package repo is a publish target, not a place |
| 72 | + # to edit. `Package.swift` has to be in place before Gradle runs, since KMMBridge |
| 73 | + # only rewrites the variables block inside it. |
| 74 | + - name: Stage the Swift package sources |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | + rm -rf spm-repo/Sources spm-repo/Tests |
| 78 | + cp -R kmp/shared-core/spm/Package.swift kmp/shared-core/spm/Sources kmp/shared-core/spm/Tests spm-repo/ |
| 79 | +
|
| 80 | + - name: Build the XCFramework, upload it, and update Package.swift |
| 81 | + env: |
| 82 | + # Gradle reads ORG_GRADLE_PROJECT_-prefixed vars as project properties, |
| 83 | + # which keeps the token out of the command line. |
| 84 | + ORG_GRADLE_PROJECT_GITHUB_PUBLISH_TOKEN: ${{ secrets.SHARED_CORE_PUBLISH_TOKEN }} |
| 85 | + run: | |
| 86 | + ./gradlew :kmp:shared-core:kmmBridgePublish \ |
| 87 | + -PENABLE_PUBLISHING=true \ |
| 88 | + -PsharedCoreVersion=${{ inputs.version }} \ |
| 89 | + -PspmRepoDir=$GITHUB_WORKSPACE/spm-repo |
| 90 | +
|
| 91 | + # The release asset is up by now but the tag still points at the old |
| 92 | + # Package.swift, so nothing consumes this build until the next step. Compiling |
| 93 | + # the Swift glue against the framework we just uploaded is the last moment a |
| 94 | + # mismatch between the two is cheap to fix — after the tag moves, it's a |
| 95 | + # published-and-broken version. |
| 96 | + - name: Verify the package builds against the uploaded framework |
| 97 | + working-directory: spm-repo |
| 98 | + run: | |
| 99 | + set -euo pipefail |
| 100 | + xcodebuild -scheme SharedCore \ |
| 101 | + -destination 'generic/platform=iOS Simulator' \ |
| 102 | + -clonedSourcePackagesDirPath "$RUNNER_TEMP/spm-verify" \ |
| 103 | + -quiet \ |
| 104 | + build |
| 105 | +
|
| 106 | + - name: Commit and tag the Swift Package |
| 107 | + working-directory: spm-repo |
| 108 | + run: | |
| 109 | + set -euo pipefail |
| 110 | + git config user.name "github-actions[bot]" |
| 111 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 112 | +
|
| 113 | + git add -A Package.swift Sources Tests |
| 114 | + if git diff --cached --quiet; then |
| 115 | + echo "Nothing to commit — the upload produced the same URL and checksum, and the Swift sources are unchanged." |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + git commit -m "SharedCore ${{ inputs.version }}" |
| 119 | + git push origin HEAD:main |
| 120 | +
|
| 121 | + # The release upload already created this tag, pointing at whatever |
| 122 | + # main was before the commit above — i.e. at a Package.swift that |
| 123 | + # doesn't mention this release. Move it onto the commit that does, or |
| 124 | + # SPM resolves the version to the previous binary. |
| 125 | + git tag -f "${{ inputs.version }}" |
| 126 | + git push -f origin "${{ inputs.version }}" |
| 127 | +
|
| 128 | + - name: Summary |
| 129 | + run: | |
| 130 | + { |
| 131 | + echo "### SharedCore ${{ inputs.version }} published" |
| 132 | + echo |
| 133 | + echo "- Release: https://github.com/${SPM_REPO}/releases/tag/${{ inputs.version }}" |
| 134 | + echo '- Consume: `.package(url: "https://github.com/'"${SPM_REPO}"'", from: "${{ inputs.version }}")`' |
| 135 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments