Skip to content

Commit bbf4be5

Browse files
authored
chore: implement selective builds on GitHub Actions (#185)
1 parent 62e8618 commit bbf4be5

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

.github/workflows/android.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ jobs:
1313
uses: actions/setup-java@v1
1414
with:
1515
java-version: 1.8
16-
- name: Install NDK
17-
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;20.0.5594570" --sdk_root=${ANDROID_SDK_ROOT}
1816
- name: Check Snippets
1917
run: python scripts/checksnippets.py
20-
- name: Build with Gradle
18+
- name: Install NDK
19+
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;20.0.5594570" --sdk_root=${ANDROID_SDK_ROOT}
20+
- name: Build with Gradle (Pull Request)
21+
run: ./build_pull_request.sh
22+
if: github.event_name == 'pull_request'
23+
- name: Build with Gradle (Push)
2124
run: ./gradlew clean ktlint build
25+
if: github.event_name != 'pull_request'

build_pull_request.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# unshallow since GitHub actions does a shallow clone
7+
git fetch --unshallow
8+
git fetch origin
9+
10+
# Get all the modules that were changed
11+
while read line; do
12+
module_name=${line%%/*}
13+
if [[ ${MODULES} != *"${module_name}"* ]]; then
14+
MODULES="${MODULES} ${module_name}"
15+
fi
16+
done < <(git diff --name-only origin/$GITHUB_BASE_REF)
17+
changed_modules=$MODULES
18+
19+
# Get a list of all available gradle tasks
20+
AVAILABLE_TASKS=$(./gradlew tasks --all)
21+
22+
# Check if these modules have gradle tasks
23+
build_commands=""
24+
for module in $changed_modules
25+
do
26+
if [[ $AVAILABLE_TASKS =~ $module":app:" ]]; then
27+
build_commands=${build_commands}" :"${module}":app:assembleDebug :"${module}":app:check"
28+
fi
29+
done
30+
31+
# Build
32+
echo "Building Pull Request with"
33+
echo $build_commands
34+
eval "./gradlew clean ktlint ${build_commands}"

0 commit comments

Comments
 (0)