Skip to content

chore: implement selective builds on GitHub Actions #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install NDK
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;20.0.5594570" --sdk_root=${ANDROID_SDK_ROOT}
- name: Check Snippets
run: python scripts/checksnippets.py
- name: Build with Gradle
- name: Install NDK
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;20.0.5594570" --sdk_root=${ANDROID_SDK_ROOT}
- name: Build with Gradle (Pull Request)
run: ./build_pull_request.sh
if: github.event_name == 'pull_request'
- name: Build with Gradle (Push)
run: ./gradlew clean ktlint build
if: github.event_name != 'pull_request'
34 changes: 34 additions & 0 deletions build_pull_request.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Exit on error
set -e

# unshallow since GitHub actions does a shallow clone
git fetch --unshallow
git fetch origin

# Get all the modules that were changed
while read line; do
module_name=${line%%/*}
if [[ ${MODULES} != *"${module_name}"* ]]; then
MODULES="${MODULES} ${module_name}"
fi
done < <(git diff --name-only origin/$GITHUB_BASE_REF)
changed_modules=$MODULES

# Get a list of all available gradle tasks
AVAILABLE_TASKS=$(./gradlew tasks --all)

# Check if these modules have gradle tasks
build_commands=""
for module in $changed_modules
do
if [[ $AVAILABLE_TASKS =~ $module":app:" ]]; then
build_commands=${build_commands}" :"${module}":app:assembleDebug :"${module}":app:check"
fi
done

# Build
echo "Building Pull Request with"
echo $build_commands
eval "./gradlew clean ktlint ${build_commands}"