Skip to content

Commit

Permalink
Swift Code Cov in CI (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX authored Mar 22, 2024
1 parent 37f45f7 commit a144677
Show file tree
Hide file tree
Showing 41 changed files with 262 additions and 112 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
CARGO_TERM_COLOR: always
RUST_TOOLCHAIN: nightly-2024-01-11
RUST_COMPONENTS: "rust-std"
SWIFT_CODE_COV_REPORT_PATH: ".build/artifacts/info.lcov" # chosen
jobs:

# typos
Expand Down Expand Up @@ -122,7 +123,16 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
rustup target add aarch64-apple-darwin
sh ./scripts/ios/test.sh
sh ./scripts/ios/test.sh --codecov ${{ env.SWIFT_CODE_COV_REPORT_PATH }}
- name: Upload to CodeCov.io
uses: RDXWorks-actions/codecov-action@main
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ${{ env.SWIFT_CODE_COV_REPORT_PATH }}
name: codecov-swift
flags: swift

# Kotlin test run on JVM on macOS (Apple Silicon)
test-kotlin:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ tarpaulin-report.html
build_rs_cov.profraw
cobertura.xml
jna-*.jar
.swiftpm/*
.swiftpm/*
default.profraw
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ repos:
name: swift tests
language: system
types_or: [rust, swift]
entry: ./scripts/ios/test.sh
entry: ./scripts/ios/test.sh --testonly # no code coverage
pass_filenames: false

- id: kotlin tests
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let package = Package(
.target(name: "Sargon"),
.product(name: "CustomDump", package: "swift-custom-dump"),
],
path: "apple/Tests/SargonTests"
path: "apple/Tests"
),
]
)
116 changes: 90 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
**Sargon is library for sharing code between Radix iOS/Android wallets.**

> [!IMPORTANT]
> This library is intended for **internal use only** in the official iOS and Android wallets.
> This library is intended for **internal use only** in the official iOS and Android wallets.
> Interfaces will be changing regularly, and we do not recommend other developers integrate the library or align with these standards.
## Etymology

Named after [Sargon of Akkad](https://en.wikipedia.org/wiki/Sargon_of_Akkad) the first ruler of the Akkadian Empire, the first empire of Mesopotamia. Babylon was a city in southern Mesopotamia, and of course the name of the Radix milestone with which the Radix wallets was launched.

# Development
Expand Down Expand Up @@ -40,13 +41,16 @@ brew install kotlin
```

#### JNA

> [!IMPORTANT]
> To run tests in Kotlin you also need to download [JNA](https://mvnrepository.com/artifact/net.java.dev.jna/jna) (currently tested under version `5.13.0`)
> ``` sh
> To run tests in Kotlin you also need to download [JNA](https://mvnrepository.com/artifact/net.java.dev.jna/jna) (currently tested under version `5.13.0`)
>
> ```sh
> curl https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar --output jna-5.13.0.jar
> ```
### `direnv`
Install [`direnv`](https://direnv.net/) in order to automatically load `CLASSPATH` and `JAVA_OPTS` in [`.envrc`](.envrc), so that you can run Kotlin bindgen tests from cli using the command in the bottom of this document - i.e. without having to export `CLASSPATH``.
### `pre-commit`
Expand Down Expand Up @@ -98,36 +102,76 @@ cargo nextest run
### Prerequisites
#### Rust targets for iOS
```sh
rustup target add aarch64-apple-ios aarch64-apple-ios-sim
```
#### Rust targets (macOS)
```sh
rustup target add aarch64-apple-darwin
```
### Build
Find [script here](scripts/ios/build-sargon.sh)
```sh
./scripts/build-ios.sh
./scripts/ios/build-ios.sh
```
## Test Swift
Find [script here](scripts/ios/test.sh)
### Code coverage
#### Details
```sh
./scripts/ios/test.sh
```
#### Summary
```sh
./scripts/ios/test.sh --summary
```
### Test only
```sh
./scripts/ios/test.sh --testonly
```
### Export code coverage
If you change `lcov` format in `export_code.cov.sh` please use an updated file name.
```sh
./scripts/ios/test.sh --codecov swift_code_cov.lcov
```
Alternatively if you wanna skip code cove
## Android
### Prerequisites
#### Install `jenv`
```sh
brew install jenv
```
Dont forget to add to eval to zsh
```sh
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
```
(or similar)
#### Install Java (openjdk@17)
Expand All @@ -141,32 +185,39 @@ brew install openjdk@17
```sh
jenv add /opt/homebrew/Cellar/openjdk@17/17.0.10/libexec/openjdk.jdk/Contents/Home/
```
(or similar)
#### `ktlint`
```sh
brew install ktlint
```
#### `cargo-ndk`
```sh
cargo install cargo-ndk
```
#### Rust targets (Android)
```sh
rustup target add aarch64-linux-android armv7-linux-androideabi
```
#### Rust targets (Desktop Binaries)
```sh
rustup target add aarch64-apple-darwin
```
#### NDK
Download the latest NDK from android studio
Then make sure that you have added these in your path
```
export ANDROID_HOME=<path-to-your-sdk>
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/<version>
Expand All @@ -175,12 +226,13 @@ export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/<version>
export SDKROOT="`xcrun --show-sdk-path`"
```
Then you can build both libraries as a usual
Then you can build both libraries as a usual
```sh
cd jvm
# For android library (Debug)
./gradlew sargon-android:assembleDebug
./gradlew sargon-android:assembleDebug
# For android library (Release)
./gradlew sargon-android:assembleRelease
Expand All @@ -196,7 +248,8 @@ cd jvm
# Release
## iOS
## iOS
### Locally
#### Prerequisites
Expand All @@ -211,18 +264,21 @@ brew install gh
```
##### Github PAT
Create a Github Personal Access Token (PAT) labeled "Classic" and give it these permissions:
`write:packages`
`admin:org -> read:org`
#### Manually release
For the first time, you must:
```sh
gh auth login
```
Do this:
```sh
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
Expand All @@ -234,54 +290,62 @@ The minimum required scopes are 'repo', 'read:org'.
```
If successful you should see:
```sh
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Logged in as <YOUR_GH_USERNAME>
```
Find [script here](scripts/ios/release.sh)
```sh
./scripts/ios/release.sh
```
### CD
See [`.github/workflows/release.yml`](.github/workflows/release.yml)
See [`.github/workflows/release.yml`](.github/workflows/release.yml)
## Android
Two modules are published in [Github's maven](https://github.com/radixdlt/sargon/packages/).
* `sargon-android`
(See [`.github/workflows/release-android.yml`](.github/workflows/release-android.yml))
- `sargon-android`
(See [`.github/workflows/release-android.yml`](.github/workflows/release-android.yml))
Contains the generated UniFFi Kotlin code and the runtime sargon binaries, in different architectures. It also contains the JNA dependency.
Contains the generated UniFFi Kotlin code and the runtime sargon binaries, in different architectures. It also contains the JNA dependency.
Import with:
```
implementation("com.radixdlt.sargon:sargon-android:<version>")
```
Import with:
* `sargon-desktop-bins`
(See [`.github/workflows/release-desktop-bins.yml`](.github/workflows/release-desktop-bins.yml))
```
implementation("com.radixdlt.sargon:sargon-android:<version>")
```
Contains only the runtime sargon binaries, built for desktop. Used when running Unit tests.

Import with:
```
testRuntimeOnly("com.radixdlt.sargon:sargon-desktop-bins:<version>")
```
- `sargon-desktop-bins`
(See [`.github/workflows/release-desktop-bins.yml`](.github/workflows/release-desktop-bins.yml))
Contains only the runtime sargon binaries, built for desktop. Used when running Unit tests.
Import with:
```
testRuntimeOnly("com.radixdlt.sargon:sargon-desktop-bins:<version>")
```
> [!IMPORTANT]
> Currently only supporting `aarch64-apple-darwin` (apple silicon). So when running Unit tests for your client app, make sure to run them on an apple silicon machine. In the future we will try to add more target architectures.
# Example apps
## iOS
See iOS example app in [examples/iOS](examples/iOS)
## Android
Import the `/jvm` directory in Android Studio and run the `app` configuration.
[vscodeext]: https://github.com/radixdlt/radix-transaction-manifest-extension
[vscodeext]: https://github.com/radixdlt/radix-transaction-manifest-extension
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ extension Decimal192: Numeric {
}

public init?<T>(exactly source: T) where T: BinaryInteger {
if let i64 = Int64(exactly: source) {
self = Self(i64)
} else if let u64 = UInt64(exactly: source) {
if let u64 = UInt64(exactly: source) {
self = Self(u64)
} else if let i64 = Int64(exactly: source) {
self = Self(i64)
} else {
return nil
}
Expand Down
Loading

0 comments on commit a144677

Please sign in to comment.