-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
102 lines (90 loc) · 3.29 KB
/
build-android-demos.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Build All Android Demos
on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'demos/**'
pull_request:
branches:
- master
paths:
- 'demos/**'
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate matrix
id: set-matrix
run: |
demos=$(find demos/android -type d -name "MASTG-DEMO-*")
matrix="{\"demo\":["
for demo in $demos; do
matrix="${matrix}\"$demo\","
done
matrix="${matrix%,}]}"
echo "matrix=$matrix" >> $GITHUB_ENV
echo "matrix=$matrix" >> $GITHUB_OUTPUT
- name: Print matrix
run: echo "${{ steps.set-matrix.outputs.matrix }}"
build:
needs: generate-matrix
runs-on: ubuntu-latest
timeout-minutes: 60 # Increase this value as needed
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
max-parallel: 3 # Limit the number of parallel jobs
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Clone MASTestApp-Android repository
run: git clone https://github.com/cpholguera/MASTestApp-Android.git
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Replace files and build APK
run: |
demo="${{ matrix.demo }}"
if [ -d "$demo" ]; then
echo "Processing $demo"
[ -f "$demo/MastgTest.kt" ] && cp -f "$demo/MastgTest.kt" MASTestApp-Android/app/src/main/java/org/owasp/mastestapp/MastgTest.kt && echo "Copied MastgTest.kt for $demo" || echo "No MastgTest.kt found for $demo"
[ -f "$demo/AndroidManifest.xml" ] && cp -f "$demo/AndroidManifest.xml" MASTestApp-Android/app/src/main/AndroidManifest.xml && echo "Copied AndroidManifest.xml for $demo" || echo "No AndroidManifest.xml found for $demo"
cd MASTestApp-Android
echo "Building APK for $demo"
./gradlew assembleDebug --stacktrace
build_status=$?
cd ..
if [ $build_status -eq 0 ]; then
echo "Build succeeded for $demo"
apk_name="$(basename "$demo").apk"
if [ -f "MASTestApp-Android/app/build/outputs/apk/debug/app-debug.apk" ]; then
mv MASTestApp-Android/app/build/outputs/apk/debug/app-debug.apk "$apk_name"
echo "APK for $demo moved to $apk_name"
else
echo "APK not found for $demo"
fi
else
echo "Build failed for $demo"
fi
else
echo "Demo directory not found: $demo"
fi
- name: Set APK name variable
id: set_apk_name
run: echo "APK_NAME=$(basename ${{ matrix.demo }}).apk" >> $GITHUB_ENV
- name: List generated APK
run: |
echo "Listing generated APK in demos/android directory:"
ls -l "${{ env.APK_NAME }}" || echo "No APK found."
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: ${{ env.APK_NAME }}
path: "${{ env.APK_NAME }}"