Build and Release Yttrium Dart #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release Yttrium Dart | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to release (e.g. 0.0.1)' | |
required: true | |
env: | |
CARGO_TERM_COLOR: always | |
VERSION: ${{ github.event.inputs.version || '0.0.1' }} | |
TARGET_BRANCH: ${{ github.ref_name }} | |
permissions: | |
contents: write | |
jobs: | |
install-dependencies: | |
runs-on: macos-latest-xlarge | |
steps: | |
# Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Cache Flutter dependencies | |
- name: Cache Flutter dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.pub-cache | |
key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-flutter- | |
# Install Rust toolchain | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
components: rust-src | |
# Cache Cargo dependencies | |
- name: Cache Cargo dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cargo | |
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.toml') }} | |
restore-keys: | | |
${{ runner.os }}-cargo- | |
# Install Java 17 | |
- name: Install Java 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
architecture: x86_64 | |
cache: 'gradle' | |
# Cache Gradle | |
- name: Cache Gradle | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# Install Flutter | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: '3.24.5' | |
# Install flutter_rust_bridge_codegen | |
- name: Install flutter_rust_bridge_codegen | |
run: | | |
cargo install flutter_rust_bridge_codegen | |
# Get package dependencies | |
- name: Get package dependencies | |
shell: bash | |
working-directory: crates/yttrium_dart | |
run: | | |
flutter pub get | |
# Generate Dart Bindings | |
- name: Generate Dart Bindings | |
shell: bash | |
working-directory: crates/yttrium_dart | |
run: | | |
flutter_rust_bridge_codegen generate --config-file flutter_rust_bridge.yaml | |
build-android-artifacts: | |
needs: install-dependencies | |
runs-on: macos-latest-xlarge | |
steps: | |
# Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Install cargo-ndk | |
- name: Install cargo-ndk | |
run: | | |
cargo install cargo-ndk | |
# Build Native Android libraries | |
- name: Build Native Android libraries | |
shell: bash | |
working-directory: crates/yttrium_dart/rust | |
run: | | |
rustup target add armv7-linux-androideabi aarch64-linux-android | |
cargo ndk -t armeabi-v7a -t arm64-v8a build --release | |
# Prepare Android artifacts | |
- name: Prepare Android artifacts | |
shell: bash | |
run: | | |
mkdir -p jniLibs/arm64-v8a | |
mkdir -p jniLibs/armeabi-v7a | |
cp target/aarch64-linux-android/release/libyttrium_dart.so jniLibs/arm64-v8a/libyttrium_dart.so | |
cp target/armv7-linux-androideabi/release/libyttrium_dart.so jniLibs/armeabi-v7a/libyttrium_dart.so | |
# Upload Android artifacts | |
- name: Upload Android artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: artifacts | |
path: jniLibs/ | |
build-ios-artifacts: | |
needs: install-dependencies | |
runs-on: macos-latest-xlarge | |
steps: | |
# Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Build Native iOS libraries | |
- name: Build Native iOS libraries | |
shell: bash | |
working-directory: crates/yttrium_dart/rust | |
run: | | |
rustup target add aarch64-apple-ios x86_64-apple-ios | |
cargo build --manifest-path Cargo.toml --target aarch64-apple-ios --release | |
cargo build --manifest-path Cargo.toml --target x86_64-apple-ios --release | |
# Prepare iOS artifacts | |
- name: Prepare iOS artifacts | |
shell: bash | |
run: | | |
mkdir -p universal | |
lipo -create target/aarch64-apple-ios/release/libyttrium_dart.dylib target/x86_64-apple-ios/release/libyttrium_dart.dylib -output universal/libyttrium_dart_universal.dylib | |
install_name_tool -id @rpath/libyttrium_dart_universal.dylib universal/libyttrium_dart_universal.dylib | |
codesign --force --sign - universal/libyttrium_dart_universal.dylib | |
# Upload iOS artifacts | |
- name: Upload iOS artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: artifacts | |
path: universal/ | |
create-github-release: | |
needs: [build-android-artifacts, build-ios-artifacts] | |
runs-on: macos-latest-xlarge | |
steps: | |
# Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Download Android artifacts | |
- name: Download Android artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: artifacts | |
path: jniLibs/ | |
# Download iOS artifacts | |
- name: Download iOS artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: artifacts | |
path: universal/ | |
# Create artifacts zip | |
- name: Create artifacts zip | |
run: | | |
zip -r android-artifacts.zip jniLibs/ | |
zip -r ios-artifacts.zip universal/ | |
# Create GitHub Release | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: Yttrium ${{ env.VERSION }} | |
draft: false | |
prerelease: false | |
# Upload Android Release Assets | |
- name: Upload Android Release Assets | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: android-artifacts.zip | |
asset_name: android-artifacts.zip | |
asset_content_type: application/zip | |
# Upload iOS Release Assets | |
- name: Upload iOS Release Assets | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ios-artifacts.zip | |
asset_name: ios-artifacts.zip | |
asset_content_type: application/zip | |
# Launch locally | |
# act --container-architecture linux/amd64 -P macos-latest-xlarge=-self-hosted --secret-file .github/workflows/.env.secret -W .github/workflows/release-dart.yml workflow_dispatch --input version=0.4.2 |