[TEST] Try to cause the error of ktlint and detekt #77
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Testing | |
on: | |
pull_request: | |
branches: | |
- '*' | |
env: | |
emulator_name: "ci_emulator_33" | |
package_name: "com.jiachian.nbatoday" | |
jobs: | |
build: | |
name: Build Environment | |
runs-on: self-hosted | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
run_android_test: | |
name: Run AndroidTests | |
runs-on: self-hosted | |
needs: [ build ] | |
timeout-minutes: 20 | |
steps: | |
- name: Check emulator command is exists | |
run: | | |
if command -v emulator &> /dev/null; then | |
echo "emulator is in PATH." | |
else | |
echo "emulator is not in PATH. Adding it to PATH..." | |
echo "$ANDROID_HOME/emulator" >> $GITHUB_PATH | |
fi | |
- name: Check avdmanager command is exists | |
run: | | |
if command -v avdmanager &> /dev/null; then | |
echo "avdmanager is in PATH." | |
else | |
echo "avdmanager is not in PATH. Adding it to PATH..." | |
echo "$ANDROID_HOME/cmdline-tools/latest/bin" >> $GITHUB_PATH | |
fi | |
- name: Check adb command is exists | |
run: | | |
if command -v adb &> /dev/null; then | |
echo "adb is in PATH." | |
else | |
echo "adb is not in PATH. Adding it to PATH..." | |
echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH | |
fi | |
- name: Check if emulator is installed | |
run: | | |
echo $ANDROID_HOME | |
emulators=$(emulator -list-avds) | |
if grep -wq "${{ env.emulator_name }}" <<< "$emulators"; then | |
echo "emulator_found=true" >> $GITHUB_ENV | |
else | |
echo "emulator_found=false" >> $GITHUB_ENV | |
fi | |
- name: Enulator is not installed and Create it | |
if: env.emulator_found == 'false' | |
run: | | |
echo "Emulator not found. Creating and starting emulator..." | |
echo "no" | avdmanager create avd -n ${{ env.emulator_name }} -k "system-images;android-33;google_apis;arm64-v8a" --device "pixel_4" | |
- name: Emulator is already installed | |
if: env.emulator_found == 'true' | |
run: echo "Emulator is already installed." | |
- name: Wait for emulator to start | |
run: | | |
emulator -avd ${{ env.emulator_name }} -no-audio & | |
series_id="" | |
while true; do | |
devices=$(adb devices | grep "device$" | awk '{print $1}') | |
series_id="" | |
for device in $devices; do | |
emulator=$(adb -s $device emu avd name 2>&1 | grep -v "OK" | sed -e 's/[[:space:]]*$//') | |
if [ "$emulator" == ${{ env.emulator_name }} ]; then | |
echo "${{ env.emulator_name }} series id is $device" | |
series_id=$device | |
echo "emulator_series_id=$device" >> $GITHUB_ENV | |
break | |
fi | |
done | |
if [ -n "$series_id" ]; then | |
break | |
fi | |
sleep 5 | |
done | |
adb -s $series_id wait-for-device | |
- name: Run Android Tests | |
run: | | |
export ANDROID_SERIAL=${{ env.emulator_series_id }} | |
./gradlew connectedAndroidTest | |
- name: Archive Android Test Results | |
if: always() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: android-test-results | |
path: | | |
app/build/outputs/androidTest-results/connected/* | |
run_unit_test: | |
name: Run UnitTests | |
runs-on: self-hosted | |
needs: [ build ] | |
timeout-minutes: 15 | |
steps: | |
- name: Run Unit Tests | |
run: | | |
./gradlew test | |
- name: Archive Unit Test Results | |
if: always() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: unit-test-results | |
path: | | |
app/build/reports/tests/testDebugUnitTest/ | |
generate_code_coverage: | |
name: Generate combined code coverage report with AndroidTest and UnitTest | |
runs-on: self-hosted | |
needs: [ run_android_test, run_unit_test ] | |
timeout-minutes: 15 | |
steps: | |
- name: Generate combined code coverage report | |
run: ./gradlew generateJacocoTestReport | |
- name: Archive Code Coverage Report | |
uses: actions/upload-artifact@v2 | |
with: | |
name: code-coverage-report | |
path: | | |
app/build/reports/jacoco/withoutTest | |
generate_code_coverage_badge: | |
name: Generate code coverage report badge | |
runs-on: ubuntu-latest | |
needs: [ generate_code_coverage ] | |
timeout-minutes: 15 | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Download code coverage report | |
uses: actions/download-artifact@v2 | |
with: | |
name: code-coverage-report | |
- name: Generate JaCoCo Badge | |
id: jacoco_badge | |
uses: cicirello/jacoco-badge-generator@v2 | |
with: | |
jacoco-csv-file: jacoco.csv | |
- name: Log Coverage Percentage | |
run: | | |
echo "coverage = ${{ steps.jacoco_badge.outputs.coverage }}" | |
echo "branch coverage = ${{ steps.jacoco_badge.outputs.branches }}" | |
- name: Commit the badge (if it changed) | |
run: | | |
if git status --porcelain | grep -q "^ M .github/badges/"; then | |
git config --global user.name 'CodeCoverageBOT' | |
git config --global user.email '[email protected]' | |
git add .github/badges/jacoco.svg | |
git commit -m "Autogenerated JaCoCo coverage badge" | |
git push | |
fi |