Skip to content

Commit

Permalink
Merge pull request #34 from tangem/feature/IOS-6122_build_scripts
Browse files Browse the repository at this point in the history
iOS-6122: Add iOS build scripts
  • Loading branch information
m3g0byt3 authored Sep 27, 2024
2 parents b40d9b3 + 3e75007 commit cd1b123
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 98 deletions.
31 changes: 31 additions & 0 deletions .github/actions/install_dependencies_composite_action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Install dependencies'
runs:
using: "composite"
steps:
- name: Install system dependencies
shell: bash
run: |
tools/install-sys-dependencies-mac
- name: Cache internal dependencies
id: internal_cache
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}

- name: Install internal dependencies
shell: bash
run: |
tools/install-dependencies
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
workspaces: |
rust
- name: Install Rust dependencies
shell: bash
run: |
tools/install-rust-dependencies
4 changes: 2 additions & 2 deletions .github/workflows/tangem-check-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Read version.properties file
uses: BrycensRanch/read-properties-action@v1
uses: BrycensRanch/read-properties-action@6b75d8ab70d5abeb5211f96b660c45c911732b6e # v1.0.4
id: version
with:
file: version.properties
Expand Down
216 changes: 170 additions & 46 deletions .github/workflows/tangem-publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Tangem - Publish

run-name: Publish new release with changes from commit '${{ github.event.head_commit.message }}' (${{ github.sha }})
on:
push:
branches:
Expand All @@ -10,79 +10,203 @@ env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_DVELOPMENT_ANDROID }}

jobs:
publish:
name: Create tag and publish
runs-on: macos-13
create_tag_and_release:
name: Create tag and release
runs-on: macos-latest
outputs:
publish_version: ${{ steps.version.outputs.tangem }}
swift_protobuf_publish_version: ${{ steps.swift_protobuf_version.outputs.version_tag }}-${{ steps.swift_protobuf_version.outputs.tangem_suffix }}
concurrency:
group: ${{ github.ref }}_create_tag_and_release
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v2

- name: set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'
uses: actions/checkout@v4

- name: Read version.properties file
uses: BrycensRanch/read-properties-action@v1
uses: BrycensRanch/read-properties-action@6b75d8ab70d5abeb5211f96b660c45c911732b6e # v1.0.4
id: version
with:
file: version.properties
property: tangem
default: 0.0.1-tangem1

- name: Echo version.properties
run: echo ${{ steps.version.outputs.tangem }}
- name: Read swift-protobuf-version.properties file
uses: BrycensRanch/read-properties-action@6b75d8ab70d5abeb5211f96b660c45c911732b6e # v1.0.4
id: swift_protobuf_version
with:
file: swift-protobuf-version.properties
all: true

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Echo versions
run: |
echo 'Publishing WalletCore version ${{ steps.version.outputs.tangem }}'
echo 'Publishing SwiftProtobuf version ${{ steps.swift_protobuf_version.outputs.version_tag }}-${{ steps.swift_protobuf_version.outputs.tangem_suffix }}'
- name: Install system dependencies
- name: Create tag and release
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2.0.5
with:
name: ${{ steps.version.outputs.tangem }}
tag_name: ${{ steps.version.outputs.tangem }}
token: ${{ secrets.GITHUB_TOKEN }}
generate_release_notes: true

publish_ios:
name: Publish iOS
runs-on: macos-latest
outputs:
should_update_swift_protobuf: ${{ env.SHOULD_UPDATE_SWIFT_PROTOBUF }}
concurrency:
group: ${{ github.ref }}_publish_ios
cancel-in-progress: true
needs: create_tag_and_release
steps:
- name: Select Xcode version
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
xcode-version: '15.4'

- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true # Required otherwise git can't describe the repo; Doesn't actually work w/o 'fetch-depth', see https://github.com/actions/checkout/issues/1471
fetch-depth: 0

- name: Remove unused files
run: rm -rf include/TrustWalletCore/TWAnySignerTangem.h # This header is not used on iOS and causes a compilation error

- name: Check if SwiftProtobuf binary must be updated
run: tools/check_if_swift_protobuf_should_be_updated "https://github.com/tangem/swift-protobuf-binaries.git" "${{ needs.create_tag_and_release.outputs.swift_protobuf_publish_version }}"

- name: Install dependencies
uses: ./.github/actions/install_dependencies_composite_action

- name: Generate files
run: tools/generate-files ios

- name: Build XCFramework
run: tools/ios-xcframework

- name: Prepare artefacts
run: |
tools/install-sys-dependencies-mac
- name: Install Android Dependencies
run: tools/install-android-dependencies
mkdir -p output/artefacts/wallet-core
mkdir -p output/artefacts/swift-protobuf
mv swift/build/WalletCore.xcframework output/artefacts/wallet-core/
mv swift/build/SwiftProtobuf.xcframework output/artefacts/swift-protobuf/
- name: Cache Rust
uses: Swatinem/rust-cache@v2
- name: Upload WalletCore artefacts
uses: actions/upload-artifact@v4
with:
workspaces: |
rust
- name: Install Rust dependencies
name: wallet-core-binary-artefacts-${{ github.sha }}
path: output/artefacts/wallet-core/

- name: Upload SwiftProtobuf artefacts
uses: actions/upload-artifact@v4
with:
name: swift-protobuf-binary-artefacts-${{ github.sha }}
path: output/artefacts/swift-protobuf/

- name: Upload DSYMs
env:
FB_IOS_APP_ID: ${{ secrets.FB_IOS_APP_ID_PROD }}
run: |
tools/install-rust-dependencies
# We don't want to have Firebase as a dependency, so we download and use the `upload-symbols` script manually
curl -fsSL https://raw.githubusercontent.com/firebase/firebase-ios-sdk/main/Crashlytics/upload-symbols -o upload-symbols
chmod +x upload-symbols
# The `upload-symbols` script indeed accepts a list of paths to upload, but using it in the foreach loop like this is just a dead-simple approach
find swift/build -type d -name "*.dSYM" -exec ./upload-symbols --platform ios --app-id $FB_IOS_APP_ID {} \;
upload_wallet_core_binaries_ios:
name: Upload WalletCore binaries iOS
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}_upload_wallet_core_binaries_ios
cancel-in-progress: true
needs:
- publish_ios
- create_tag_and_release
steps:
- name: Download artefacts
uses: actions/download-artifact@v4
with:
name: wallet-core-binary-artefacts-${{ github.sha }}
path: output

- name: Cache internal dependencies
id: internal_cache
uses: actions/cache@v3
- name: Update wallet-core-binaries-ios repo
uses: cpina/github-action-push-to-another-repository@07c4d7b3def0a8ebe788a8f2c843a4e1de4f6900 # v.1.7.2
env:
SSH_DEPLOY_KEY: ${{ secrets.WALLET_CORE_BINARIES_IOS_SSH_DEPLOY_KEY }}
with:
path: build/local
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}
source-directory: 'output/WalletCore.xcframework'
destination-github-username: 'tangem'
destination-repository-name: 'wallet-core-binaries-ios'
target-branch: 'main'
target-directory: 'WalletCore.xcframework'
commit-message: 'Update from ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} (${{ needs.create_tag_and_release.outputs.publish_version }})'

- name: Install internal dependencies
run: tools/install-dependencies
if: steps.internal_cache.outputs.cache-hit != 'true'
upload_swift_protobuf_binaries_ios:
name: Upload SwiftProtobuf binaries iOS
if: needs.publish_ios.outputs.should_update_swift_protobuf == 1
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}_upload_swift_protobuf_binaries_ios
cancel-in-progress: true
needs:
- publish_ios
- create_tag_and_release
steps:
- name: Download artefacts
uses: actions/download-artifact@v4
with:
name: swift-protobuf-binary-artefacts-${{ github.sha }}
path: output

- name: Create tag
uses: actions/github-script@v3
- name: Update swift-protobuf-binaries repo
uses: cpina/github-action-push-to-another-repository@07c4d7b3def0a8ebe788a8f2c843a4e1de4f6900 # v.1.7.2
env:
SSH_DEPLOY_KEY: ${{ secrets.SWIFT_PROTOBUF_BINARIES_SSH_DEPLOY_KEY }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.version.outputs.tangem }}",
sha: context.sha
})
source-directory: 'output/SwiftProtobuf.xcframework'
destination-github-username: 'tangem'
destination-repository-name: 'swift-protobuf-binaries'
target-branch: 'main'
target-directory: 'SwiftProtobuf.xcframework'
commit-message: 'Update from ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} (${{ needs.create_tag_and_release.outputs.swift_protobuf_publish_version }})'

publish_android:
name: Publish Android
runs-on: macos-13
concurrency:
group: ${{ github.ref }}_publish_android
cancel-in-progress: true
needs: create_tag_and_release
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install_dependencies_composite_action

- name: Setup JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Install Android Dependencies
run: tools/install-android-dependencies

- name: Generate files
run: tools/generate-files android

- name: Build and publish
- name: Build and publish Android
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
run: |
cd android/
echo sdk.dir = $ANDROID_HOME > local.properties
GITHUB_USER=${{ secrets.GITHUB_ACTOR }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ./gradlew build assembleRelease publish -Pversion=${{ steps.version.outputs.tangem }}
GITHUB_USER=${{ secrets.GITHUB_ACTOR }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ./gradlew build assembleRelease publish -Pversion=${{ needs.create_tag_and_release.outputs.publish_version }}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ If you want to add support for a new blockchain also see [Adding Support for a N
Thanks to all the people who contribute.
<a href="https://github.com/trustwallet/wallet-core/graphs/contributors"><img src="https://opencollective.com/wallet-core/contributors.svg?width=890&button=false" /></a>

# Contributing (Tangem specific)

- Before opening a pull-request, bump **WalletCore** library version in the `./version.properties` file
- [Optional] To update **SwiftProtobuf** library (only if necessary):
* Make sure that the new version of the **SwiftProtobuf** library is compatible with other consumers of a binary artifact (`grpc-swift`, `hedera-sdk-swift`, `SwiftBinanceChain`, `blockchain-sdk-swift`, and so on)
* Set a new version in the `./swift-protobuf-version.properties` file
* Set a new version in the `./swift/Podfile` file

# Disclaimer

The Wallet Core project is led and managed by Trust Wallet with a large contributor community and actively used in several projects. Our goal at Wallet Core is to give other wallets an easy way to add chain support.
Expand Down
2 changes: 1 addition & 1 deletion include/TrustWalletCore/TWAnySignerTangem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
#include "TWString.h"

// TANGEM
extern TWData *_Nonnull TWAnySignerSignExternally(TWData* _Nonnull data, enum TWCoinType coin, TWData *_Nonnull publicKey, std::function<const TWData *_Nonnull(const TWData *_Nonnull)> externalSigner);
extern TWData *_Nonnull TWAnySignerSignExternally(TWData* _Nonnull data, enum TWCoinType coin, TWData *_Nonnull publicKey, std::function<const TWData *_Nonnull(const TWData *_Nonnull)> externalSigner); // Not used on iOS
7 changes: 6 additions & 1 deletion src/interface/TWAnySigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// Copyright © 2017 Trust Wallet.

#include <TrustWalletCore/TWAnySigner.h>
#include <TrustWalletCore/TWAnySignerTangem.h>

#if defined(IS_IOS_BINARIES)
#include <functional>
#else
#include <TrustWalletCore/TWAnySignerTangem.h> // This header file is not used on iOS
#endif // defined(IS_IOS_BINARIES)

#include "Coin.h"

Expand Down
9 changes: 9 additions & 0 deletions swift-protobuf-version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Version tag from https://github.com/apple/swift-protobuf/releases
#
# 1. The SwiftProtobuf library version must match the version specified in the `swift/Podfile` file.
# 2. Before upgrading, make sure that the new version of the SwiftProtobuf library is compatible with other consumers
# of the binary artifact (`grpc-swift`, `hedera-sdk-swift`, `SwiftBinanceChain`, `blockchain-sdk-swift` and so on).
version_tag=1.25.2

# Additional suffix for Tangem-specifc intermediate builds
tangem_suffix=tangem1
4 changes: 4 additions & 0 deletions swift/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ project 'TrustWalletCore.xcodeproj'
target 'WalletCore' do
use_frameworks!

# 1. The SwiftProtobuf library version must match the version specified in the `swift-protobuf-version.properties` file
# (`version_tag` property in this file).
# 2. Before upgrading, make sure that the new version of the SwiftProtobuf library is compatible with other consumers
# of the binary artifact (`grpc-swift`, `hedera-sdk-swift`, `SwiftBinanceChain`, `blockchain-sdk-swift` and so on).
pod 'SwiftProtobuf', '=1.25.2'

target 'WalletCoreTests'
Expand Down
2 changes: 1 addition & 1 deletion swift/common-xcframework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ targets:
INFOPLIST_FILE: 'Info.plist'
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION: YES_ERROR
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER: $(inherited) false
OTHER_CFLAGS: $(inherited) -Wno-comma
OTHER_CFLAGS: $(inherited) -Wno-comma -DIS_IOS_BINARIES

trezor-crypto:
type: library.static
Expand Down
2 changes: 1 addition & 1 deletion swift/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ targets:
INFOPLIST_FILE: 'Info.plist'
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION: YES_ERROR
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER: $(inherited) false
OTHER_CFLAGS: $(inherited) -Wno-comma -DNDEBUG
OTHER_CFLAGS: $(inherited) -Wno-comma -DNDEBUG -DIS_IOS_BINARIES
postCompileScripts:
- script: |
export PATH=/opt/homebrew/bin:$PATH;
Expand Down
12 changes: 12 additions & 0 deletions tools/check_if_swift_protobuf_should_be_updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

repo_url=$1
repo_tag=$2

if git ls-remote --tags $repo_url | grep -q "refs/tags/$repo_tag"; then
echo "Should update SwiftProtobuf: false"
echo "SHOULD_UPDATE_SWIFT_PROTOBUF=0" >> $GITHUB_ENV
else
echo "Should update SwiftProtobuf: true"
echo "SHOULD_UPDATE_SWIFT_PROTOBUF=1" >> $GITHUB_ENV
fi
Loading

0 comments on commit cd1b123

Please sign in to comment.