Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize CI/CD workflow #41

Merged
merged 8 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 41 additions & 82 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,66 @@ concurrency:
cancel-in-progress: true

jobs:
buildAndroid:
name: Build Android
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
build:
strategy:
matrix:
platform: [ android, ios, web, desktop ]
include:
- platform: android
os: ubuntu-latest
- platform: web
os: ubuntu-latest
- platform: ios
os: macos-latest
- platform: desktop
os: macos-latest

runs-on: ${{ matrix.os }}

steps:
# Code checkout
- name: Checkout code
id: checkout_code
uses: actions/checkout@v4

# Setup Java and Gradle
- name: Java and Gradle set up
if: matrix.platform != 'ios'
uses: ./.github/workflows/setup/java-setup

# Grant execute permission for script
- name: Grant execute permission for script
id: grant_script_permission
shell: bash
run: chmod +x ./scripts/build_android.sh

# Build and verify Android
- name: Build and verify Android
run: ./scripts/build_android.sh

buildiOS:
name: Build iOS
runs-on: macos-latest
if: github.event.pull_request.draft == false

steps:
# Code checkout
- name: Checkout code
id: checkout_code
uses: actions/checkout@v4

# Setup Java and Gradle
- name: Java and Gradle set up
uses: ./.github/workflows/setup/java-setup

# Grant execute permission for script
- name: Grant execute permission for script
id: grant_script_permission
shell: bash
run: chmod +x ./scripts/build_android.sh

# Setup iOS
- name: iOS set up
if: matrix.platform == 'ios'
uses: ./.github/workflows/setup/ios-setup

# Build iOS app
- name: Build iOS app
id: build_ios_debug
run: xcodebuild build -workspace sample/iosApp/iosApp.xcworkspace -configuration Debug -scheme iosApp -sdk iphonesimulator -verbose
# Android
- name: Grant execute permission for Android script
if: matrix.platform == 'android'
run: chmod +x ./scripts/build_android.sh

buildWeb:
name: Build Web
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
- name: Build Android
if: matrix.platform == 'android'
run: ./scripts/build_android.sh

steps:
# Code checkout
- name: Checkout code
id: checkout_code
uses: actions/checkout@v4
# iOS
- name: Grant execute permission for iOS script
if: matrix.platform == 'ios'
run: chmod +x ./scripts/build_ios.sh

# Setup Java and Gradle
- name: Java and Gradle set up
uses: ./.github/workflows/setup/java-setup
- name: Build iOS
if: matrix.platform == 'ios'
run: ./scripts/build_ios.sh

# Grant execute permission for script
- name: Grant execute permission for script
id: grant_script_permission
shell: bash
# Web
- name: Grant execute permission for Web script
if: matrix.platform == 'web'
run: chmod +x ./scripts/build_web.sh

# Build and verify Web
- name: Build and verify Web
- name: Build Web
if: matrix.platform == 'web'
run: ./scripts/build_web.sh

buildMacOS:
name: Build MacOS
runs-on: macos-latest
if: github.event.pull_request.draft == false

steps:
# Code checkout
- name: Checkout code
id: checkout_code
uses: actions/checkout@v4

# Setup Java and Gradle
- name: Java and Gradle set up
uses: ./.github/workflows/setup/java-setup

# Grant execute permission for script
- name: Grant execute permission for script
id: grant_script_permission
shell: bash
# MacOS
- name: Grant execute permission for MacOS script
if: matrix.platform == 'desktop'
run: chmod +x ./scripts/build_macos.sh

# Build and verify MacOS
- name: Build and verify MacOS
- name: Build MacOS
if: matrix.platform == 'desktop'
run: ./scripts/build_macos.sh
28 changes: 23 additions & 5 deletions scripts/build_android.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
#!/bin/bash

# Exit the script on any error
set -e

# Navigate to the root directory of the project
cd "$(dirname "$0")/.." || exit

# Create distributions folder in the root directory (if not already present)
mkdir -p distributions
mkdir -p distributions/android

# Build Android App
echo "Building Android App 📱"
./gradlew :sample:composeApp:assembleDebug
./gradlew :sample:composeApp:assembleDebug --console=plain --stacktrace

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Android build successful."

# Verify and copy the APK to the distributions folder
APK_PATH="sample/composeApp/build/outputs/apk/debug/composeApp-debug.apk"

# Verify and copy the APK to the distributions folder
echo "Verifying Android App"
cp sample/composeApp/build/outputs/apk/debug/composeApp-debug.apk distributions/jetlime-sample-android.apk
if [ -f "$APK_PATH" ]; then
cp "$APK_PATH" distributions/android/jetlime-sample-android.apk
echo "Android APK copied to distributions/android/jetlime-sample-android.apk"
else
echo "APK not found at expected path: $APK_PATH"
exit 1
fi
else
echo "Android build failed."
exit 1
fi
35 changes: 35 additions & 0 deletions scripts/build_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Navigate to the root directory of the project
cd "$(dirname "$0")/.." || exit

# Build iOS app using xcodebuild
xcodebuild build \
-workspace sample/iosApp/iosApp.xcworkspace \
-configuration Debug \
-scheme iosApp \
-sdk iphonesimulator \
-verbose

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "iOS build successful."

# Create distributions directory if it doesn't exist
mkdir -p distributions/ios

# Copy the generated iOS build products to the distributions/ directory
BUILD_DIR=$(xcodebuild -workspace sample/iosApp/iosApp.xcworkspace \
-scheme iosApp -configuration Debug -sdk iphonesimulator -showBuildSettings | grep -m1 " BUILT_PRODUCTS_DIR" | awk '{print $3}')

if [ -d "$BUILD_DIR" ]; then
cp -R "$BUILD_DIR"/* distributions/ios/
echo "iOS build copied to distributions/ios/ directory."
else
echo "Build directory not found!"
exit 1
fi
else
echo "iOS build failed."
exit 1
fi
28 changes: 22 additions & 6 deletions scripts/build_macos.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
#!/bin/bash

# Exit the script on any error
set -e

# Navigate to the root directory of the project
cd "$(dirname "$0")/.." || exit

# Create distributions folder in the root directory (if not already present)
mkdir -p distributions
mkdir -p distributions/macos

# Build Mac Desktop App
echo "Building Mac Desktop App 🖥️"
./gradlew :sample:composeApp:packageUberJarForCurrentOS
./gradlew :sample:composeApp:packageUberJarForCurrentOS --console=plain --stacktrace

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Mac Desktop build successful."

# Verify and copy the JAR to the distributions folder
echo "Verifying Mac Desktop App"
cp "sample/composeApp/build/compose/jars/JetLime Samples-macos-arm64-1.0.0.jar" distributions/jetlime-sample-macos-x64.jar
# Verify and copy the JAR to the distributions folder
JAR_PATH="sample/composeApp/build/compose/jars/JetLime Samples-macos-arm64-1.0.0.jar"

echo "Mac Desktop app build and copied to distributions/jetlime-sample-macos-x64.jar"
if [ -f "$JAR_PATH" ]; then
cp "$JAR_PATH" distributions/macos/jetlime-sample-macos-x64.jar
echo "Mac Desktop app copied to distributions/macos/jetlime-sample-macos-x64.jar"
else
echo "JAR not found at expected path: $JAR_PATH"
exit 1
fi
else
echo "Mac Desktop build failed."
exit 1
fi
30 changes: 24 additions & 6 deletions scripts/build_web.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
#!/bin/bash

# Exit the script on any error
set -e

# Navigate to the root directory of the project
cd "$(dirname "$0")/.." || exit

# Build Web App
echo "Building Web App 🌎"
./gradlew :sample:composeApp:wasmJsBrowserDistribution
./gradlew :sample:composeApp:wasmJsBrowserDistribution --console=plain --stacktrace

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Web build successful."

# Create the distributions/jetlime-web folder in the root directory
mkdir -p distributions/jetlime-web
# Create the distributions/jetlime-web folder in the root directory
mkdir -p distributions/web

# Copy the production executable to the distributions folder
cp -r sample/composeApp/build/dist/wasmJs/productionExecutable/ distributions/jetlime-web/
# Path to the production executable
WEB_EXECUTABLE_PATH="sample/composeApp/build/dist/wasmJs/productionExecutable/"

echo "Web app build and copied to distributions/jetlime-web"
# Verify and copy the production executable to the distributions folder
if [ -d "$WEB_EXECUTABLE_PATH" ]; then
cp -r "$WEB_EXECUTABLE_PATH" distributions/web/
echo "Web app copied to distributions/web"
else
echo "Web build output not found at expected path: $WEB_EXECUTABLE_PATH"
exit 1
fi
else
echo "Web build failed."
exit 1
fi
Loading