From 5527a9c6a6d7444be27d9db2eb99a6cdcd706c64 Mon Sep 17 00:00:00 2001 From: Mojtaba Shirkhani Date: Mon, 6 Jan 2025 15:04:08 +0330 Subject: [PATCH] Create BuildAndTest.yml --- .github/workflows/BuildAndTest.yml | 121 +++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .github/workflows/BuildAndTest.yml diff --git a/.github/workflows/BuildAndTest.yml b/.github/workflows/BuildAndTest.yml new file mode 100644 index 0000000..92c3a3d --- /dev/null +++ b/.github/workflows/BuildAndTest.yml @@ -0,0 +1,121 @@ +name: Build and Test +on: [ push ] +jobs: + + local_test_job: + name: Running Local Tests + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Set up JDK + with: + distribution: 'zulu' + java-version: '17' + uses: actions/setup-java@v4 + - name: Change wrapper permissions + run: chmod +x ./gradlew + - name: Restore Cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Run Debug Tests + run: ./gradlew testDebugUnitTest --continue + - name: Upload Test Reports + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: test-reports + path: '**/build/reports/tests/' + + android_test_job: + name: Android Tests + runs-on: macos-latest + continue-on-error: true + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up JDK + with: + distribution: 'zulu' + java-version: '17' + uses: actions/setup-java@v4 + - name: Change wrapper permissions + run: chmod +x ./gradlew + - name: Restore Cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Instrumentation Tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 29 + script: ./gradlew connectedAndroidTest + + - name: Upload Android Test Reports + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: android-test-reports + path: '**/build/reports/androidTests/' + + build_job: + name: Building the APK + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up JDK + with: + distribution: 'zulu' + java-version: '17' + uses: actions/setup-java@v4 + - name: Restore Cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Change wrapper permissions + run: chmod +x ./gradlew + - name: Assemble Debug + run: ./gradlew assembleDebug + + - name: Upload APK + uses: actions/upload-artifact@v2 + with: + name: apk + path: app/build/outputs/apk/debug/**.apk + + notification_job: + needs: [ local_test_job, android_test_job, build_job ] + name: Notify Workflow Results + runs-on: ubuntu-latest + steps: + - uses: technote-space/workflow-conclusion-action@v1 + - name: Send mail + if: failure() + uses: dawidd6/action-send-mail@v2 + with: + server_address: smtp.gmail.com + server_port: 465 + username: ${{ secrets.MAIL_USERNAME }} + password: ${{ secrets.MAIL_PASSWORD }} + subject: Github Actions Job result + body: Build job of ${{github.repository}} completed successfully! The Job worflow ${{ github.workflow }} of ${{ github.repository }} has result of ${{ env.WORKFLOW_CONCLUSION }} + to: mojtabashirkhani.nba@gmail.com + from: From Github Action