Skip to content

Commit 58c0020

Browse files
authored
Optimize CI/CD workflow
* [ci] migrate to matrix strategy for build jobs * [ci] map os to build in matrix
1 parent 05816bb commit 58c0020

File tree

5 files changed

+145
-99
lines changed

5 files changed

+145
-99
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,107 +12,66 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15-
buildAndroid:
16-
name: Build Android
17-
runs-on: ubuntu-latest
18-
if: github.event.pull_request.draft == false
15+
build:
16+
strategy:
17+
matrix:
18+
platform: [ android, ios, web, desktop ]
19+
include:
20+
- platform: android
21+
os: ubuntu-latest
22+
- platform: web
23+
os: ubuntu-latest
24+
- platform: ios
25+
os: macos-latest
26+
- platform: desktop
27+
os: macos-latest
28+
29+
runs-on: ${{ matrix.os }}
1930

2031
steps:
21-
# Code checkout
2232
- name: Checkout code
23-
id: checkout_code
2433
uses: actions/checkout@v4
2534

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

30-
# Grant execute permission for script
31-
- name: Grant execute permission for script
32-
id: grant_script_permission
33-
shell: bash
34-
run: chmod +x ./scripts/build_android.sh
35-
36-
# Build and verify Android
37-
- name: Build and verify Android
38-
run: ./scripts/build_android.sh
39-
40-
buildiOS:
41-
name: Build iOS
42-
runs-on: macos-latest
43-
if: github.event.pull_request.draft == false
44-
45-
steps:
46-
# Code checkout
47-
- name: Checkout code
48-
id: checkout_code
49-
uses: actions/checkout@v4
50-
51-
# Setup Java and Gradle
52-
- name: Java and Gradle set up
53-
uses: ./.github/workflows/setup/java-setup
54-
55-
# Grant execute permission for script
56-
- name: Grant execute permission for script
57-
id: grant_script_permission
58-
shell: bash
59-
run: chmod +x ./scripts/build_android.sh
60-
61-
# Setup iOS
6239
- name: iOS set up
40+
if: matrix.platform == 'ios'
6341
uses: ./.github/workflows/setup/ios-setup
6442

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

70-
buildWeb:
71-
name: Build Web
72-
runs-on: ubuntu-latest
73-
if: github.event.pull_request.draft == false
48+
- name: Build Android
49+
if: matrix.platform == 'android'
50+
run: ./scripts/build_android.sh
7451

75-
steps:
76-
# Code checkout
77-
- name: Checkout code
78-
id: checkout_code
79-
uses: actions/checkout@v4
52+
# iOS
53+
- name: Grant execute permission for iOS script
54+
if: matrix.platform == 'ios'
55+
run: chmod +x ./scripts/build_ios.sh
8056

81-
# Setup Java and Gradle
82-
- name: Java and Gradle set up
83-
uses: ./.github/workflows/setup/java-setup
57+
- name: Build iOS
58+
if: matrix.platform == 'ios'
59+
run: ./scripts/build_ios.sh
8460

85-
# Grant execute permission for script
86-
- name: Grant execute permission for script
87-
id: grant_script_permission
88-
shell: bash
61+
# Web
62+
- name: Grant execute permission for Web script
63+
if: matrix.platform == 'web'
8964
run: chmod +x ./scripts/build_web.sh
9065

91-
# Build and verify Web
92-
- name: Build and verify Web
66+
- name: Build Web
67+
if: matrix.platform == 'web'
9368
run: ./scripts/build_web.sh
9469

95-
buildMacOS:
96-
name: Build MacOS
97-
runs-on: macos-latest
98-
if: github.event.pull_request.draft == false
99-
100-
steps:
101-
# Code checkout
102-
- name: Checkout code
103-
id: checkout_code
104-
uses: actions/checkout@v4
105-
106-
# Setup Java and Gradle
107-
- name: Java and Gradle set up
108-
uses: ./.github/workflows/setup/java-setup
109-
110-
# Grant execute permission for script
111-
- name: Grant execute permission for script
112-
id: grant_script_permission
113-
shell: bash
70+
# MacOS
71+
- name: Grant execute permission for MacOS script
72+
if: matrix.platform == 'desktop'
11473
run: chmod +x ./scripts/build_macos.sh
11574

116-
# Build and verify MacOS
117-
- name: Build and verify MacOS
75+
- name: Build MacOS
76+
if: matrix.platform == 'desktop'
11877
run: ./scripts/build_macos.sh

scripts/build_android.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
#!/bin/bash
22

3+
# Exit the script on any error
4+
set -e
5+
36
# Navigate to the root directory of the project
47
cd "$(dirname "$0")/.." || exit
58

69
# Create distributions folder in the root directory (if not already present)
7-
mkdir -p distributions
10+
mkdir -p distributions/android
811

912
# Build Android App
1013
echo "Building Android App 📱"
11-
./gradlew :sample:composeApp:assembleDebug
14+
./gradlew :sample:composeApp:assembleDebug --console=plain --stacktrace
15+
16+
# Check if the build was successful
17+
if [ $? -eq 0 ]; then
18+
echo "Android build successful."
19+
20+
# Verify and copy the APK to the distributions folder
21+
APK_PATH="sample/composeApp/build/outputs/apk/debug/composeApp-debug.apk"
1222

13-
# Verify and copy the APK to the distributions folder
14-
echo "Verifying Android App"
15-
cp sample/composeApp/build/outputs/apk/debug/composeApp-debug.apk distributions/jetlime-sample-android.apk
23+
if [ -f "$APK_PATH" ]; then
24+
cp "$APK_PATH" distributions/android/jetlime-sample-android.apk
25+
echo "Android APK copied to distributions/android/jetlime-sample-android.apk"
26+
else
27+
echo "APK not found at expected path: $APK_PATH"
28+
exit 1
29+
fi
30+
else
31+
echo "Android build failed."
32+
exit 1
33+
fi

scripts/build_ios.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Navigate to the root directory of the project
4+
cd "$(dirname "$0")/.." || exit
5+
6+
# Build iOS app using xcodebuild
7+
xcodebuild build \
8+
-workspace sample/iosApp/iosApp.xcworkspace \
9+
-configuration Debug \
10+
-scheme iosApp \
11+
-sdk iphonesimulator \
12+
-verbose
13+
14+
# Check if the build was successful
15+
if [ $? -eq 0 ]; then
16+
echo "iOS build successful."
17+
18+
# Create distributions directory if it doesn't exist
19+
mkdir -p distributions/ios
20+
21+
# Copy the generated iOS build products to the distributions/ directory
22+
BUILD_DIR=$(xcodebuild -workspace sample/iosApp/iosApp.xcworkspace \
23+
-scheme iosApp -configuration Debug -sdk iphonesimulator -showBuildSettings | grep -m1 " BUILT_PRODUCTS_DIR" | awk '{print $3}')
24+
25+
if [ -d "$BUILD_DIR" ]; then
26+
cp -R "$BUILD_DIR"/* distributions/ios/
27+
echo "iOS build copied to distributions/ios/ directory."
28+
else
29+
echo "Build directory not found!"
30+
exit 1
31+
fi
32+
else
33+
echo "iOS build failed."
34+
exit 1
35+
fi

scripts/build_macos.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
#!/bin/bash
22

3+
# Exit the script on any error
4+
set -e
5+
36
# Navigate to the root directory of the project
47
cd "$(dirname "$0")/.." || exit
58

69
# Create distributions folder in the root directory (if not already present)
7-
mkdir -p distributions
10+
mkdir -p distributions/macos
811

912
# Build Mac Desktop App
1013
echo "Building Mac Desktop App 🖥️"
11-
./gradlew :sample:composeApp:packageUberJarForCurrentOS
14+
./gradlew :sample:composeApp:packageUberJarForCurrentOS --console=plain --stacktrace
15+
16+
# Check if the build was successful
17+
if [ $? -eq 0 ]; then
18+
echo "Mac Desktop build successful."
1219

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

17-
echo "Mac Desktop app build and copied to distributions/jetlime-sample-macos-x64.jar"
23+
if [ -f "$JAR_PATH" ]; then
24+
cp "$JAR_PATH" distributions/macos/jetlime-sample-macos-x64.jar
25+
echo "Mac Desktop app copied to distributions/macos/jetlime-sample-macos-x64.jar"
26+
else
27+
echo "JAR not found at expected path: $JAR_PATH"
28+
exit 1
29+
fi
30+
else
31+
echo "Mac Desktop build failed."
32+
exit 1
33+
fi

scripts/build_web.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
#!/bin/bash
22

3+
# Exit the script on any error
4+
set -e
5+
36
# Navigate to the root directory of the project
47
cd "$(dirname "$0")/.." || exit
58

69
# Build Web App
710
echo "Building Web App 🌎"
8-
./gradlew :sample:composeApp:wasmJsBrowserDistribution
11+
./gradlew :sample:composeApp:wasmJsBrowserDistribution --console=plain --stacktrace
12+
13+
# Check if the build was successful
14+
if [ $? -eq 0 ]; then
15+
echo "Web build successful."
916

10-
# Create the distributions/jetlime-web folder in the root directory
11-
mkdir -p distributions/jetlime-web
17+
# Create the distributions/jetlime-web folder in the root directory
18+
mkdir -p distributions/web
1219

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

16-
echo "Web app build and copied to distributions/jetlime-web"
23+
# Verify and copy the production executable to the distributions folder
24+
if [ -d "$WEB_EXECUTABLE_PATH" ]; then
25+
cp -r "$WEB_EXECUTABLE_PATH" distributions/web/
26+
echo "Web app copied to distributions/web"
27+
else
28+
echo "Web build output not found at expected path: $WEB_EXECUTABLE_PATH"
29+
exit 1
30+
fi
31+
else
32+
echo "Web build failed."
33+
exit 1
34+
fi

0 commit comments

Comments
 (0)