Add SonarCloud to CI/CD #12
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: Android CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
test: | |
name: Run Unit and UI Tests | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Step 2: Set up JDK 17 (or another version your app uses) | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
# Step 3: Set up Android SDK | |
- name: Set up Android SDK | |
uses: android-actions/setup-android@v2 | |
with: | |
api-level: 34 | |
build-tools: '34.0.0' | |
target: 'android-34' | |
# Step 4: Install Android Emulator system image for API 33 | |
- name: Install Android System Image | |
run: sdkmanager "system-images;android-34;google_apis;x86_64" | |
env: | |
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk | |
# Step 5: Create Android Emulator | |
- name: Create Android Emulator | |
run: echo "no" | avdmanager create avd -n test -k "system-images;android-34;google_apis;x86_64" | |
env: | |
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk | |
# Step 6: Grant execute permission for gradlew | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
working-directory: GPAi | |
# Step 7: Build the app | |
- name: Build with Gradle | |
run: ./gradlew build | |
working-directory: GPAi | |
# Step 9: Run Unit Tests | |
- name: Run Unit Tests | |
run: ./gradlew test | |
working-directory: GPAi | |
# Step 11: Archive test reports (Optional) | |
- name: Upload Test Results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-results | |
path: GPAi/app/build/reports/tests/ |