Skip to content

Commit 06ac6fa

Browse files
authored
Merge branch 'OWASP:master' into MASTG-TEST-0045
2 parents 4bce8c7 + f329f76 commit 06ac6fa

File tree

209 files changed

+3023
-1011
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+3023
-1011
lines changed

.github/workflows/build-android-demos.yml

+141-44
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- master
1313
paths:
1414
- 'demos/**'
15+
- '.github/workflows/build-android-demos.yml'
1516

1617
jobs:
1718
generate-matrix:
@@ -21,79 +22,175 @@ jobs:
2122
steps:
2223
- name: Checkout repository
2324
uses: actions/checkout@v4
25+
with:
26+
sparse-checkout: demos/android
27+
fetch-depth: 2 # Required for git diff in PRs
2428

2529
- name: Generate matrix
2630
id: set-matrix
2731
run: |
28-
demos=$(find demos/android -type d -name "MASTG-DEMO-*")
29-
matrix="{\"demo\":["
30-
for demo in $demos; do
31-
matrix="${matrix}\"$demo\","
32-
done
33-
matrix="${matrix%,}]}"
34-
echo "matrix=$matrix" >> $GITHUB_ENV
35-
echo "matrix=$matrix" >> $GITHUB_OUTPUT
32+
if [ "${{ github.event_name }}" = "pull_request" ]; then
33+
# Get list of changed files in demos/android/ directory
34+
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} HEAD -- 'demos/android/*')
35+
36+
echo "Changed files:"
37+
echo "$changed_files"
38+
39+
# Extract unique demo directories
40+
matrix=$(echo "$changed_files" | grep -oE 'demos/android/[^/]*/MASTG-DEMO-[^/]+' | sort -u | head -c -1 | tr '\n' ' ' | sed 's/ /","/g')
3641
42+
# If no changes, set empty matrix
43+
if [ -z "$matrix" ]; then
44+
echo "matrix={\"demo\":[]}" >> $GITHUB_OUTPUT
45+
else
46+
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
47+
fi
48+
else
49+
# Default behavior: include all demos for master branch
50+
matrix=$(echo demos/android/*/MASTG-DEMO-* | sed 's/ /","/g')
51+
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
52+
fi
53+
echo "Print matrix: $matrix"
3754
- name: Print matrix
3855
run: echo "${{ steps.set-matrix.outputs.matrix }}"
3956

57+
build-base-app:
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 10
60+
steps:
61+
- name: Get last commit hash of MASTestApp-Android
62+
id: get-mastestapp-hash
63+
run: |
64+
echo "MASTESTAPP_HASH=$(git ls-remote https://github.com/cpholguera/MASTestApp-Android.git HEAD | awk '{print $1}')" >> $GITHUB_ENV
65+
echo "MASTESTAPP_HASH=$MASTESTAPP_HASH" >> $GITHUB_OUTPUT
66+
67+
- name: Check if already cached
68+
id: cache-check
69+
uses: actions/cache/restore@v4
70+
with:
71+
lookup-only: true
72+
path: MASTestApp-Android/ # we're forced to write a path even if we don't need it
73+
key: base-app-${{ env.MASTESTAPP_HASH }}
74+
75+
- name: Set up JDK 17
76+
if: steps.cache-check.outputs.cache-hit != 'true'
77+
uses: actions/setup-java@v4
78+
with:
79+
java-version: '17'
80+
distribution: 'temurin'
81+
82+
- name: Setup Gradle
83+
if: steps.cache-check.outputs.cache-hit != 'true'
84+
uses: gradle/actions/setup-gradle@v4
85+
with:
86+
cache-read-only: false
87+
88+
- name: Clone MASTestApp-Android repository
89+
if: steps.cache-check.outputs.cache-hit != 'true'
90+
uses: actions/checkout@v4
91+
with:
92+
repository: cpholguera/MASTestApp-Android
93+
path: MASTestApp-Android
94+
ref: ${{ env.MASTESTAPP_HASH }}
95+
96+
- name: Build base app
97+
if: steps.cache-check.outputs.cache-hit != 'true'
98+
run: |
99+
cd MASTestApp-Android
100+
grep -q 'org.gradle.caching=true' gradle.properties || echo -en "\norg.gradle.caching=true\norg.gradle.configuration-cache=true\n" >> gradle.properties
101+
./gradlew assembleDebug --stacktrace || (
102+
echo "Build failed"
103+
exit 1
104+
)
105+
echo "Build succeeded"
106+
107+
- name: Saving cache
108+
if: steps.cache-check.outputs.cache-hit != 'true'
109+
uses: actions/cache/save@v4
110+
with:
111+
path: MASTestApp-Android/
112+
key: ${{ steps.cache-check.outputs.cache-primary-key }}
113+
40114
build:
41-
needs: generate-matrix
115+
needs: [generate-matrix, build-base-app]
42116
runs-on: ubuntu-latest
43-
timeout-minutes: 60 # Increase this value as needed
117+
timeout-minutes: 30 # Increase this value as needed
44118
strategy:
45119
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
46120
max-parallel: 3 # Limit the number of parallel jobs
47121

48122
steps:
49123
- name: Checkout repository
50124
uses: actions/checkout@v4
51-
52-
- name: Clone MASTestApp-Android repository
53-
run: git clone https://github.com/cpholguera/MASTestApp-Android.git
125+
with:
126+
sparse-checkout: demos/android
54127

55128
- name: Set up JDK 17
56-
uses: actions/setup-java@v3
129+
uses: actions/setup-java@v4
57130
with:
58131
java-version: '17'
59132
distribution: 'temurin'
60133

134+
- name: Setup Gradle
135+
uses: gradle/actions/setup-gradle@v4
136+
with:
137+
cache-read-only: true
138+
139+
- name: Restore cache
140+
id: cache-base-app
141+
uses: actions/cache/restore@v4
142+
with:
143+
path: MASTestApp-Android/
144+
key: base-app-${{ env.MASTESTAPP_HASH }}
145+
61146
- name: Replace files and build APK
62147
run: |
63148
demo="${{ matrix.demo }}"
64-
if [ -d "$demo" ]; then
65-
echo "Processing $demo"
66-
[ -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"
67-
[ -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"
68-
cd MASTestApp-Android
69-
echo "Building APK for $demo"
70-
./gradlew assembleDebug --stacktrace
71-
build_status=$?
72-
cd ..
73-
if [ $build_status -eq 0 ]; then
74-
echo "Build succeeded for $demo"
75-
apk_name="$(basename "$demo").apk"
76-
if [ -f "MASTestApp-Android/app/build/outputs/apk/debug/app-debug.apk" ]; then
77-
mv MASTestApp-Android/app/build/outputs/apk/debug/app-debug.apk "$apk_name"
78-
echo "APK for $demo moved to $apk_name"
79-
else
80-
echo "APK not found for $demo"
81-
fi
82-
else
83-
echo "Build failed for $demo"
84-
fi
85-
else
149+
[ -d "$demo" ] || (
86150
echo "Demo directory not found: $demo"
87-
fi
151+
exit 1
152+
)
88153
89-
- name: Set APK name variable
90-
id: set_apk_name
91-
run: echo "APK_NAME=$(basename ${{ matrix.demo }}).apk" >> $GITHUB_ENV
154+
echo "Processing $demo"
155+
cp -f "$demo/MastgTest.kt" MASTestApp-Android/app/src/main/java/org/owasp/mastestapp/MastgTest.kt 2>/dev/null \
156+
&& echo "Copied MastgTest.kt for $demo" \
157+
|| echo "No MastgTest.kt found for $demo"
158+
cp -f "$demo/MastgTestWebView.kt" MASTestApp-Android/app/src/main/java/org/owasp/mastestapp/MastgTestWebView.kt 2>/dev/null \
159+
&& echo "Copied MastgTestWebView.kt for $demo" \
160+
|| echo "No MastgTestWebView.kt found for $demo"
161+
cp -f "$demo/AndroidManifest.xml" MASTestApp-Android/app/src/main/AndroidManifest.xml 2>/dev/null \
162+
&& echo "Copied AndroidManifest.xml for $demo" \
163+
|| echo "No AndroidManifest.xml found for $demo"
164+
cp -f "$demo/filepaths.xml" MASTestApp-Android/app/src/main/res/xml/filepaths.xml 2>/dev/null \
165+
&& echo "Copied filepaths.xml for $demo" \
166+
|| echo "No filepaths.xml found for $demo"
167+
cp -f "$demo/network_security_config.xml" MASTestApp-Android/app/src/main/res/xml/network_security_config.xml 2>/dev/null \
168+
&& echo "Copied network_security_config.xml for $demo" \
169+
|| echo "No network_security_config.xml found for $demo"
170+
cp -f "$demo/backup_rules.xml" MASTestApp-Android/app/src/main/res/xml/backup_rules.xml 2>/dev/null \
171+
&& echo "Copied backup_rules.xml for $demo" \
172+
|| echo "No backup_rules.xml found for $demo"
173+
cp -f "$demo/data_extraction_rules.xml" MASTestApp-Android/app/src/main/res/xml/data_extraction_rules.xml 2>/dev/null \
174+
&& echo "Copied data_extraction_rules.xml for $demo" \
175+
|| echo "No data_extraction_rules.xml found for $demo"
176+
177+
echo "Building APK for $demo"
178+
cd MASTestApp-Android
179+
grep -q 'org.gradle.caching=true' gradle.properties || echo -en "\norg.gradle.caching=true\norg.gradle.configuration-cache=true\n" >> gradle.properties
180+
./gradlew assembleDebug --stacktrace || (
181+
echo "Build failed for $demo"
182+
exit 1
183+
)
184+
cd ..
185+
echo "Build succeeded for $demo"
92186
93-
- name: List generated APK
94-
run: |
95-
echo "Listing generated APK in demos/android directory:"
96-
ls -l "${{ env.APK_NAME }}" || echo "No APK found."
187+
apk_filename="$(basename "$demo").apk"
188+
mv MASTestApp-Android/app/build/outputs/apk/debug/app-debug.apk "$apk_filename" || (
189+
echo "APK not found for $demo"
190+
exit 1
191+
)
192+
echo "APK for $demo moved to $apk_filename"
193+
echo "APK_NAME=$apk_filename" >> $GITHUB_ENV
97194
98195
- name: Upload APK
99196
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)