Test and Deploy #43
This file contains hidden or 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
| ## 1 | |
| name: Test and Deploy | |
| ## Actions that will be executed when you push code currently none | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| semver: | |
| description: 'Release Semantic Versioning (e.g. 4.15.2)' | |
| required: true | |
| track: | |
| description: 'Track' | |
| required: true | |
| default: internal | |
| type: choice | |
| options: | |
| - internal | |
| - alpha | |
| - beta | |
| - production | |
| ## 2 | |
| jobs: | |
| ## 3 | |
| unit_tests: | |
| name: Unit tests | |
| runs-on: [ubuntu-latest] | |
| timeout-minutes: 20 | |
| env: | |
| TERM: dumb | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: 17.0.6 | |
| - name: Copy CI gradle.properties | |
| run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | |
| - name: Restore google-services.json | |
| run: | | |
| mkdir -p app | |
| echo "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" | base64 --decode > app/google-services.json | |
| - name: Build | |
| uses: gradle/gradle-build-action@v2 | |
| with: | |
| arguments: assembleDebug -PsaveBuildLogToFile=true | |
| - name: Unit tests | |
| uses: gradle/gradle-build-action@v2 | |
| with: | |
| arguments: testDebugUnitTest | |
| ## 4 | |
| instrumentation_tests: | |
| name: Instrumentation tests | |
| # Android emulators require hardware acceleration (HAXM on Mac & Windows, QEMU on Linux) from the host to run fast. | |
| # The macOS VM provided by GitHub Actions is the only one that currently supports it. | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| env: | |
| JAVA_TOOL_OPTIONS: -Xmx4g | |
| TERM: dumb | |
| strategy: | |
| # Allow tests to continue on other devices if they fail on one device. | |
| fail-fast: false | |
| matrix: | |
| api-level: [28, 31] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Enable KVM group perms | |
| run: | | |
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | |
| sudo udevadm control --reload-rules | |
| sudo udevadm trigger --name-match=kvm | |
| ls /dev/kvm | |
| - name: Copy CI gradle.properties | |
| run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: 17.0.6 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| - name: Accept Android licenses | |
| run: yes | "$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --licenses || true | |
| - name: Restore google-services.json | |
| run: | | |
| mkdir -p app | |
| echo "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" | base64 --decode > app/google-services.json | |
| - name: Run Espresso tests on Pixel6 Api${{ matrix.api-level }} AOSP | |
| run: ./gradlew pixel6Api${{ matrix.api-level }}aospDebugAndroidTest | |
| -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true | |
| -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" | |
| --max-workers=1 | |
| build: | |
| needs: [unit_tests, instrumentation_tests] | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1 | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: 17.0.6 | |
| - name: Create release tag | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| github.rest.git.createRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: "refs/tags/${{ github.event.inputs.semver }}", | |
| sha: context.sha | |
| }) | |
| - name: Workaround to fetch the tag # Is there a better way to do it? | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Restore google-services.json | |
| run: | | |
| mkdir -p app | |
| echo "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" | base64 --decode > app/google-services.json | |
| # 2 | |
| - name: Generate Release APK | |
| run: ./gradlew assembleRelease | |
| # 3 | |
| - name: Sign APK | |
| uses: r0adkll/sign-android-release@v1 | |
| # ID used to access action output | |
| id: sign_app | |
| with: | |
| releaseDirectory: app/build/outputs/apk/release | |
| signingKeyBase64: ${{ secrets.SIGNING_STORE_PASSWORD }} | |
| alias: ${{ secrets.SIGNING_KEY_ALIAS }} | |
| keyStorePassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
| keyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
| env: | |
| BUILD_TOOLS_VERSION: '34.0.0' | |
| # 4 | |
| - name: Upload | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Build Artifacts | |
| path: app/build/outputs/ | |
| - name: Delete release tag | |
| if: ${{ failure() || cancelled() }} | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| github.rest.git.deleteRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: "tags/${{ github.event.inputs.semver }}" | |
| }) |