Skip to content

Commit c2501f6

Browse files
authored
Merge pull request #140 from ryanaidilp/feature/workflow-improvement
feat(ci): enhance workflows with smart detection, size analysis, and caching
2 parents e869efa + 990eb86 commit c2501f6

15 files changed

+1357
-353
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
name: Build Develop APK
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-develop-apk:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Get commit info
23+
id: commit_info
24+
run: |
25+
COMMIT_SHA="${{ github.sha }}"
26+
SHORT_SHA="${COMMIT_SHA:0:7}"
27+
28+
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
29+
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
30+
echo "Building APK for develop branch at commit $SHORT_SHA"
31+
32+
- name: Setup Java
33+
uses: actions/setup-java@v5
34+
with:
35+
distribution: 'zulu'
36+
java-version: '17'
37+
cache: 'gradle'
38+
39+
- name: Setup Flutter
40+
uses: subosito/flutter-action@v2
41+
with:
42+
channel: 'stable'
43+
cache: true
44+
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
45+
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'
46+
47+
- name: Cache Flutter dependencies
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
~/.pub-cache
52+
app/example/.dart_tool
53+
packages/stadata_flutter_sdk/.dart_tool
54+
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}-${{ hashFiles('**/pubspec.lock') }}
55+
restore-keys: |
56+
${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}-
57+
${{ runner.os }}-pub-
58+
59+
- name: Cache build_runner outputs
60+
uses: actions/cache@v4
61+
with:
62+
path: |
63+
app/example/lib/**/*.g.dart
64+
app/example/lib/**/*.gr.dart
65+
app/example/lib/**/*.config.dart
66+
app/example/.dart_tool/build
67+
key: ${{ runner.os }}-build-runner-${{ hashFiles('app/example/pubspec.yaml') }}-${{ hashFiles('app/example/lib/**/*.dart', '!app/example/lib/**/*.g.dart', '!app/example/lib/**/*.gr.dart', '!app/example/lib/**/*.config.dart') }}-${{ hashFiles('app/example/build.yaml') }}
68+
restore-keys: |
69+
${{ runner.os }}-build-runner-${{ hashFiles('app/example/pubspec.yaml') }}-
70+
${{ runner.os }}-build-runner-
71+
72+
- name: Get Flutter dependencies
73+
working-directory: app/example
74+
run: |
75+
echo "📦 Getting Flutter dependencies..."
76+
flutter pub get
77+
echo "✅ Dependencies ready"
78+
79+
- name: Setup .env file
80+
working-directory: app/example
81+
env:
82+
ENV_BASE64: ${{ secrets.ENV_BASE64 }}
83+
run: |
84+
if [ -n "$ENV_BASE64" ]; then
85+
echo "Decoding .env file from secret..."
86+
echo "$ENV_BASE64" | base64 -d > .env
87+
echo "✅ .env file created successfully"
88+
else
89+
echo "⚠️ Warning: ENV_BASE64 secret not found, creating empty .env"
90+
touch .env
91+
fi
92+
93+
- name: Run build_runner
94+
working-directory: app/example
95+
run: |
96+
echo "🔨 Running build_runner to generate code..."
97+
flutter pub run build_runner build --delete-conflicting-outputs
98+
echo "✅ Code generation completed"
99+
100+
- name: Build APK with Size Analysis
101+
working-directory: app/example
102+
run: |
103+
echo "Building APK for develop branch with size analysis..."
104+
105+
# Clean build directory
106+
flutter clean
107+
108+
# Build APK with size analysis
109+
flutter build apk --analyze-size --target-platform android-arm64
110+
111+
# Check if APK was built
112+
APK_PATH="build/app/outputs/flutter-apk/app-release.apk"
113+
114+
if [ -f "$APK_PATH" ]; then
115+
# Rename APK
116+
NEW_APK_NAME="Stadata_Example_Develop_${{ steps.commit_info.outputs.short_sha }}.apk"
117+
mv "$APK_PATH" "build/app/outputs/flutter-apk/$NEW_APK_NAME"
118+
echo "apk_path=app/example/build/app/outputs/flutter-apk/$NEW_APK_NAME" >> $GITHUB_OUTPUT
119+
echo "apk_name=$NEW_APK_NAME" >> $GITHUB_OUTPUT
120+
echo "✅ APK built successfully: $NEW_APK_NAME"
121+
122+
# Get APK size
123+
APK_SIZE=$(du -h "build/app/outputs/flutter-apk/$NEW_APK_NAME" | cut -f1)
124+
echo "apk_size=$APK_SIZE" >> $GITHUB_OUTPUT
125+
126+
# Check for size analysis JSON
127+
echo "🔍 Searching for size analysis JSON..."
128+
chmod +x ../../scripts/ci/find_size_analysis_json.sh
129+
SIZE_JSON=$(../../scripts/ci/find_size_analysis_json.sh . || echo "")
130+
131+
if [ -n "$SIZE_JSON" ]; then
132+
echo "✅ Found size analysis JSON: $(basename $SIZE_JSON)"
133+
else
134+
echo "⚠️ Size analysis JSON not found"
135+
fi
136+
137+
if [ -n "$SIZE_JSON" ]; then
138+
# Copy to a known location with descriptive name
139+
mkdir -p build/size-analysis
140+
COMMIT_HASH="${{ steps.commit_info.outputs.short_sha }}"
141+
cp "$SIZE_JSON" "build/size-analysis/size_analysis_develop_${COMMIT_HASH}.json"
142+
echo "size_json=app/example/build/size-analysis/size_analysis_develop_${COMMIT_HASH}.json" >> $GITHUB_OUTPUT
143+
echo "✅ Size analysis saved as: size_analysis_develop_${COMMIT_HASH}.json"
144+
else
145+
echo "⚠️ Size analysis JSON not found"
146+
fi
147+
else
148+
echo "❌ APK build failed - file not found"
149+
exit 1
150+
fi
151+
id: build_apk
152+
153+
- name: Upload Develop APK
154+
uses: actions/upload-artifact@v4
155+
with:
156+
name: develop-apk-latest
157+
path: ${{ steps.build_apk.outputs.apk_path }}
158+
retention-days: 30
159+
overwrite: true
160+
161+
- name: Upload Size Analysis JSON
162+
if: steps.build_apk.outputs.size_json != ''
163+
uses: actions/upload-artifact@v4
164+
with:
165+
name: develop-size-analysis-latest
166+
path: ${{ steps.build_apk.outputs.size_json }}
167+
retention-days: 30
168+
overwrite: true
169+
170+
- name: Build summary
171+
if: always()
172+
run: |
173+
echo "## 📱 Develop APK Build Summary" >> $GITHUB_STEP_SUMMARY
174+
echo "" >> $GITHUB_STEP_SUMMARY
175+
echo "### 📋 Build Information" >> $GITHUB_STEP_SUMMARY
176+
echo "- **Branch**: develop" >> $GITHUB_STEP_SUMMARY
177+
echo "- **Commit**: ${{ steps.commit_info.outputs.short_sha }}" >> $GITHUB_STEP_SUMMARY
178+
echo "- **APK Name**: ${{ steps.build_apk.outputs.apk_name }}" >> $GITHUB_STEP_SUMMARY
179+
echo "" >> $GITHUB_STEP_SUMMARY
180+
181+
if [ "${{ job.status }}" = "success" ]; then
182+
echo "### ✅ Build Status" >> $GITHUB_STEP_SUMMARY
183+
echo "APK built successfully and cached for size comparison!" >> $GITHUB_STEP_SUMMARY
184+
echo "- **Size**: ${{ steps.build_apk.outputs.apk_size }}" >> $GITHUB_STEP_SUMMARY
185+
echo "- **Artifact**: develop-apk-latest" >> $GITHUB_STEP_SUMMARY
186+
echo "- **Retention**: 30 days" >> $GITHUB_STEP_SUMMARY
187+
echo "" >> $GITHUB_STEP_SUMMARY
188+
echo "ℹ️ This APK will be used for size comparison in PR builds." >> $GITHUB_STEP_SUMMARY
189+
else
190+
echo "### ❌ Build Status" >> $GITHUB_STEP_SUMMARY
191+
echo "APK build failed!" >> $GITHUB_STEP_SUMMARY
192+
fi

.github/workflows/codecov.yaml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
name: Code Coverage
22

3-
concurrency:
4-
group: ${{ github.workflow }}-${{ github.ref }}
5-
cancel-in-progress: true
6-
73
on:
84
push:
9-
branches:
10-
- develop
11-
- main
12-
pull_request:
135
branches:
146
- main
157
- develop
168

9+
permissions:
10+
contents: read
11+
1712
jobs:
18-
coverage:
13+
upload-coverage:
1914
runs-on: ubuntu-latest
2015
defaults:
2116
run:
2217
working-directory: packages/stadata_flutter_sdk
18+
2319
steps:
2420
- name: 📚 Git Checkout
2521
uses: actions/checkout@v5
22+
2623
- name: 🐦 Setup Flutter
2724
uses: subosito/flutter-action@v2
2825
with:
2926
channel: "stable"
3027
cache: true
3128
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
29+
3230
- name: 📦 Install Dependencies
3331
run: |
3432
flutter pub global activate very_good_cli
3533
very_good packages get --recursive
36-
- name: Run Tests
34+
35+
- name: Run Tests with Coverage
3736
run: |
38-
very_good test -j 4 --optimization --coverage --test-randomize-ordering-seed random
37+
very_good test -j 4 --optimization --coverage --test-randomize-ordering-seed random
38+
3939
- name: Setup Lcov
4040
uses: hrishikesh-kadam/setup-lcov@v1
41-
- name: Cleaning lcov.info
41+
42+
- name: Clean lcov.info
4243
run: |
4344
lcov --ignore-errors unused --remove ./coverage/lcov.info \
4445
"**/base_entity_*.dart" \
@@ -59,9 +60,18 @@ jobs:
5960
"**/usecase.dart" \
6061
"**/injector.dart" \
6162
"**/*_injector.dart" \
62-
-o ./coverage/lcov.info
63-
- name: Upload coverage reports to Codecov
63+
-o ./coverage/lcov_cleaned.info
64+
65+
- name: Upload cleaned coverage artifact
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: coverage-report-cleaned
69+
path: packages/stadata_flutter_sdk/coverage/lcov_cleaned.info
70+
retention-days: 30
71+
72+
- name: Upload coverage to Codecov
6473
uses: codecov/codecov-action@v5
6574
with:
66-
files: "./coverage/lcov.info"
75+
files: "./packages/stadata_flutter_sdk/coverage/lcov_cleaned.info"
6776
token: ${{ secrets.CODECOV_TOKEN }}
77+
fail_ci_if_error: false

0 commit comments

Comments
 (0)