|
| 1 | +name: Publish to Maven Central |
| 2 | + |
| 3 | +on: |
| 4 | + # TODO: remove after testing |
| 5 | + push: |
| 6 | + branches: [ci/kotlin-release] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Version to publish (leave empty for release version)" |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + dry_run: |
| 14 | + description: "Dry run - publish to local Maven repo only" |
| 15 | + required: false |
| 16 | + default: true |
| 17 | + type: boolean |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - os: ubuntu-latest |
| 26 | + target: x86_64-unknown-linux-gnu |
| 27 | + lib_ext: so |
| 28 | + - os: ubuntu-latest |
| 29 | + target: aarch64-unknown-linux-gnu |
| 30 | + lib_ext: so |
| 31 | + - os: macos-latest |
| 32 | + target: x86_64-apple-darwin |
| 33 | + lib_ext: dylib |
| 34 | + - os: macos-latest |
| 35 | + target: aarch64-apple-darwin |
| 36 | + lib_ext: dylib |
| 37 | + - os: windows-latest |
| 38 | + target: x86_64-pc-windows-msvc |
| 39 | + lib_ext: dll |
| 40 | + steps: |
| 41 | + - name: Checkout repository |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Set up JDK 21 |
| 45 | + uses: actions/setup-java@v4 |
| 46 | + with: |
| 47 | + java-version: "21" |
| 48 | + distribution: "temurin" |
| 49 | + |
| 50 | + - name: Install Rust |
| 51 | + uses: dtolnay/rust-toolchain@stable |
| 52 | + with: |
| 53 | + targets: ${{ matrix.target }} |
| 54 | + |
| 55 | + - name: Build the bindings |
| 56 | + run: make kotlin |
| 57 | + |
| 58 | + - name: Upload native library |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + with: |
| 61 | + name: native-lib-${{ matrix.os }}-${{ matrix.target }} |
| 62 | + path: bindings/kotlin/lib/*iota_sdk_ffi* |
| 63 | + |
| 64 | + publish: |
| 65 | + runs-on: ubuntu-latest |
| 66 | + needs: build |
| 67 | + steps: |
| 68 | + - name: Checkout repository |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Set up JDK 21 |
| 72 | + uses: actions/setup-java@v4 |
| 73 | + with: |
| 74 | + java-version: "21" |
| 75 | + distribution: "temurin" |
| 76 | + |
| 77 | + - name: Install Rust |
| 78 | + uses: dtolnay/rust-toolchain@stable |
| 79 | + |
| 80 | + # - name: Build Rust library |
| 81 | + # run: cargo build -p iota-sdk-ffi --lib --release |
| 82 | + |
| 83 | + - name: Download native libraries |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + path: libs |
| 87 | + |
| 88 | + - name: Prepare libraries |
| 89 | + run: | |
| 90 | + echo "Listing contents of libs directory:" |
| 91 | + ls -la libs/ |
| 92 | + echo "Listing contents of native-lib-ubuntu-latest-x86_64-unknown-linux-gnu:" |
| 93 | + ls -la libs/native-lib-ubuntu-latest-x86_64-unknown-linux-gnu/ |
| 94 | + echo "Listing contents of bindings/kotlin/lib before copying:" |
| 95 | + ls -la bindings/kotlin/lib/ |
| 96 | + cd bindings/kotlin/lib |
| 97 | + echo "Copying libraries..." |
| 98 | + cp ../../../libs/native-lib-ubuntu-latest-x86_64-unknown-linux-gnu/libiota_sdk_ffi.so . |
| 99 | + cp ../../../libs/native-lib-ubuntu-latest-aarch64-unknown-linux-gnu/libiota_sdk_ffi.so libiota_sdk_ffi_arm64.so |
| 100 | + cp ../../../libs/native-lib-macos-latest-x86_64-apple-darwin/libiota_sdk_ffi.dylib . |
| 101 | + cp ../../../libs/native-lib-macos-latest-aarch64-apple-darwin/libiota_sdk_ffi.dylib libiota_sdk_ffi_arm64.dylib |
| 102 | + cp ../../../libs/native-lib-windows-latest-x86_64-pc-windows-msvc/iota_sdk_ffi.dll . |
| 103 | + echo "Contents after copying:" |
| 104 | + ls -la |
| 105 | +
|
| 106 | + - name: Generate Kotlin bindings |
| 107 | + run: | |
| 108 | + cd bindings/kotlin |
| 109 | + # Generate bindings using the Linux library (arbitrary choice) |
| 110 | + cargo run --bin iota_sdk_bindings -- generate --library "lib/libiota_sdk_ffi.so" --language kotlin --out-dir lib --no-format -c uniffi.toml |
| 111 | +
|
| 112 | + - name: Set version for release |
| 113 | + if: github.event_name == 'release' |
| 114 | + run: | |
| 115 | + cd bindings/kotlin |
| 116 | + sed -i "s/version = .*/version = \"${{ github.event.release.tag_name }}\"/" build.gradle.kts |
| 117 | +
|
| 118 | + - name: Set version for manual dispatch |
| 119 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' |
| 120 | + run: | |
| 121 | + cd bindings/kotlin |
| 122 | + sed -i "s/version = .*/version = \"${{ github.event.inputs.version }}\"/" build.gradle.kts |
| 123 | +
|
| 124 | + - name: Publish to Maven Central |
| 125 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'false') |
| 126 | + run: | |
| 127 | + cd bindings/kotlin |
| 128 | + ./gradlew publish --no-daemon --no-parallel |
| 129 | + env: |
| 130 | + ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }} |
| 131 | + ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }} |
| 132 | + ORG_GRADLE_PROJECT_SIGNING_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PASSWORD }} |
| 133 | + ORG_GRADLE_PROJECT_BASE64_ENCODED_ASCII_ARMORED_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_BASE64_ENCODED_ASCII_ARMORED_SIGNING_KEY }} |
| 134 | + |
| 135 | + - name: Dry run - Local publish only |
| 136 | + if: github.event_name != 'release' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry_run == 'true') |
| 137 | + run: | |
| 138 | + cd bindings/kotlin |
| 139 | + echo "Dry run: Publishing to local Maven repository only" |
| 140 | + ./gradlew publishToMavenLocal --no-daemon --no-parallel |
| 141 | + env: |
| 142 | + ORG_GRADLE_PROJECT_SIGNING_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PASSWORD }} |
| 143 | + ORG_GRADLE_PROJECT_BASE64_ENCODED_ASCII_ARMORED_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_BASE64_ENCODED_ASCII_ARMORED_SIGNING_KEY }} |
0 commit comments