From 633d38b2a8364353aeeeacb41b5edd14a1b56709 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Thu, 29 Feb 2024 17:49:19 +0100 Subject: [PATCH] Update CI workflow to be more efficient --- .github/workflows/archive.yml | 19 -- .github/workflows/build.yml | 19 -- .github/workflows/emulator.yml | 38 ---- .../workflows/firebase-app-distribution.yml | 38 ---- .github/workflows/test.yml | 20 -- .github/workflows/validate.yml | 180 ++++++++++++++++++ 6 files changed, 180 insertions(+), 134 deletions(-) delete mode 100644 .github/workflows/archive.yml delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/emulator.yml delete mode 100644 .github/workflows/firebase-app-distribution.yml delete mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/validate.yml diff --git a/.github/workflows/archive.yml b/.github/workflows/archive.yml deleted file mode 100644 index b04392ac3..000000000 --- a/.github/workflows/archive.yml +++ /dev/null @@ -1,19 +0,0 @@ -# archive creates and publishes an apk for testing -name: archive -on: [push] -jobs: - build: - runs-on: macos-latest - steps: - - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'temurin' - - name: checkout - uses: actions/checkout@v2 - - run: ./gradlew clean assembleDevFullRelease - - name: uploads dev apk - uses: actions/upload-artifact@v3 - with: - name: dev-apk - path: app/build/outputs/apk/devFull/release diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 46f49645d..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,19 +0,0 @@ -# build checks whether the project builds -name: build -on: [push] -jobs: - build: - runs-on: macos-latest - strategy: - matrix: - version: - - "StableFullRelease" - - "StableFdroidRelease" - steps: - - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'temurin' - - name: checkout - uses: actions/checkout@v2 - - run: ./gradlew build${{ matrix.version }} && ./gradlew clean diff --git a/.github/workflows/emulator.yml b/.github/workflows/emulator.yml deleted file mode 100644 index de92c9393..000000000 --- a/.github/workflows/emulator.yml +++ /dev/null @@ -1,38 +0,0 @@ -# emulator runs tests inside the android emulator -name: emulator -on: - push: - branches: - - master - pull_request: - schedule: - - cron: "0 2 * * */2" -jobs: - test: - runs-on: macos-latest - strategy: - matrix: - api-level: [29] - target: [google_apis] - steps: - - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'temurin' - - name: checkout - uses: actions/checkout@v2 - - name: run tests - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ matrix.api-level }} - target: ${{ matrix.target }} - arch: x86_64 - profile: Nexus 6 - ram-size: 2048M - script: ./gradlew connectedStableFullDebugAndroidTest - - name: uploads test results - uses: actions/upload-artifact@v2 - if: failure() - with: - name: emulator-test-results - path: app/build/reports/androidTests/connected/flavors/stableFullDebugAndroidTest diff --git a/.github/workflows/firebase-app-distribution.yml b/.github/workflows/firebase-app-distribution.yml deleted file mode 100644 index c55cc486c..000000000 --- a/.github/workflows/firebase-app-distribution.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Build & upload to Firebase App Distribution - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Resolve PR number - uses: jwalton/gh-find-current-pr@v1 - id: findPr - with: - # Can be "open", "closed", or "all". Defaults to "open". - state: open - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - name: Build `DevFullDebug` variant - if: success() && steps.findPr.outputs.number - run: ./gradlew clean assembleDevFullDebug - env: - PR_NUMBER: ${{ steps.findPr.outputs.pr }} - - name: Upload artifact to Firebase App Distribution - uses: wzieba/Firebase-Distribution-Github-Action@v1.7.0 - id: uploadArtifact - with: - appId: ${{secrets.FIREBASE_APP_ID}} - serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} - groups: testers - file: app/build/outputs/apk/devFull/debug/app-dev-full-debug.apk - - name: Write Summary - run: | - echo "View this release in the Firebase console: ${{ steps.uploadArtifact.outputs.FIREBASE_CONSOLE_URI }}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index f743fca58..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,20 +0,0 @@ -# test runs unit tests using the JVM -name: test -on: [push] -jobs: - test: - runs-on: macos-latest - steps: - - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'temurin' - - name: checkout - uses: actions/checkout@v2 - - run: ./gradlew testStableFullRelease - - name: uploads test results - uses: actions/upload-artifact@v2 - if: failure() - with: - name: test-results - path: app/build/test-results/testStableFullDebugUnitTest diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 000000000..a16aa1846 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,180 @@ +# This workflow is triggered on push events to the repository +# It runs the following jobs: +# - build: Ensure the code builds +# - unit-test: Run unit tests +# - instrumented-test: Run instrumented tests +# - assemble-archive: Archive APKs +# - distribute: Upload artifact to Firebase App Distribution +name: Validate +on: [ push ] +jobs: + build: + name: Ensure the code builds + runs-on: ubuntu-latest + + strategy: + matrix: + version: + - "StableFullRelease" + - "StableFdroidRelease" + + steps: + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: checkout + uses: actions/checkout@v4 + + - name: Build `StableFullRelease` and `StableFdroidRelease` variants + run: ./gradlew build${{ matrix.version }} && ./gradlew clean + + unit-test: + name: Run unit tests + runs-on: ubuntu-latest + needs: [ build ] + + steps: + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: checkout + uses: actions/checkout@v4 + + - name: Run unit tests + run: ./gradlew testStableFullRelease + + - name: Uploads test reports + uses: actions/upload-artifact@v4 + if: failure() + with: + name: test-report + path: app/build/test-results/testStableFullDebugUnitTest + + instrumented-test: + name: Run instrumented tests + runs-on: ubuntu-latest + needs: [ build ] + + strategy: + matrix: + api-level: [ 29 ] + target: [ google_apis ] + + steps: + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: checkout + uses: actions/checkout@v4 + + - name: Run instrumented tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: ${{ matrix.target }} + arch: x86_64 + profile: pixel_3_xl + ram-size: 4096M + disable-animations: true + script: ./gradlew connectedStableFullDebugAndroidTest + + - name: uploads test reports + uses: actions/upload-artifact@v4 + if: failure() + with: + name: emulator-test-reports + path: app/build/reports/androidTests/connected/debug/flavors/stableFull/ + + assemble-archive: + name: Archive APKs + runs-on: ubuntu-latest + + strategy: + matrix: + version: + - "StableFullDebug" + - "StableFdroidDebug" + - "DevFullDebug" + - "DevFullDebugAndroidTest" + needs: [ build ] + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: Get issue number + uses: actions/github-script@v6 + id: get_issue_number + with: + script: | + if (context.issue.number) { + // Return issue number if present + return context.issue.number; + } else { + // Otherwise return issue number from commit + return ( + await github.rest.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: context.sha, + owner: context.repo.owner, + repo: context.repo.repo, + }) + ).data[0].number; + } + result-encoding: string + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Assemble APKs + if: success() && steps.get_issue_number.outputs.result + run: ./gradlew assemble${{ matrix.version }} + env: + PR_NUMBER: ${{ steps.get_issue_number.outputs.result }} + + - name: uploads dev apk + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.version }}Apk + path: | + app/build/outputs/apk/devFull/debug/app-dev-full-debug.apk + app/build/outputs/apk/androidTest/devFull/debug/app-dev-full-debug-androidTest.apk + app/build/outputs/apk/stableFull/debug/app-stable-full-debug.apk + app/build/outputs/apk/stableFdroid/debug/app-stable-fdroid-debug.apk + + distribute: + name: Upload artifact to Firebase App Distribution + runs-on: ubuntu-latest + needs: [ assemble-archive ] + steps: + + - name: checkout + uses: actions/checkout@v4 + + - name: Download app APK + uses: actions/download-artifact@v4 + with: + name: DevFullDebugApk + + - name: Upload artifact to Firebase App Distribution + uses: wzieba/Firebase-Distribution-Github-Action@v1.7.0 + id: uploadArtifact + with: + appId: ${{secrets.FIREBASE_APP_ID}} + serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} + groups: testers + file: devFull/debug/app-dev-full-debug.apk + - name: Write Summary + run: | + echo "View this release in the Firebase console: ${{ steps.uploadArtifact.outputs.FIREBASE_CONSOLE_URI }}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file