Skip to content

feat(push): decouple auto push tracking and token forwarding (MAGE-886) #101

feat(push): decouple auto push tracking and token forwarding (MAGE-886)

feat(push): decouple auto push tracking and token forwarding (MAGE-886) #101

# Workflow for running Android instrumented tests across multiple API levels
# Runs on master, release branches, and PRs with specific labels
name: Instrumented Tests
# Required permissions for label management
permissions:
contents: read
pull-requests: write
# Trigger conditions
on:
# Run on pushes to main branches
push:
branches:
- 'master'
- 'rel/*'
# Run on PRs when specific labels are added or when labeled PRs are updated
pull_request:
types: [ labeled ]
jobs:
# Main instrumented tests job
instrumented-tests:
name: Run
runs-on: ubuntu-22.04
# Run if: push to branches OR PR with test:all label
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'test:all'))
strategy:
fail-fast: false
matrix:
include:
- api-level: 23
arch: x86
- api-level: 36
arch: x86_64
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Setup Android Build Environment
uses: ./.github/actions/setup
with:
google-services-json: ${{secrets.GOOGLE_SERVICES_JSON}}
- name: Configure local.properties for instrumented tests
run: |
echo "klaviyoPublicApiKey=$INSTRUMENTED_TEST_PUBLIC_API_KEY" >> local.properties
env:
INSTRUMENTED_TEST_PUBLIC_API_KEY: ${{secrets.INSTRUMENTED_TEST_PUBLIC_API_KEY}}
- 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
- name: Set API Level and Architecture
id: api-setup
run: |
echo "api_level=${{ matrix.api-level }}" >> $GITHUB_OUTPUT
echo "arch=${{ matrix.arch }}" >> $GITHUB_OUTPUT
- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ steps.api-setup.outputs.api_level }}-${{ steps.api-setup.outputs.arch }}
- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ steps.api-setup.outputs.api_level }}
arch: ${{ steps.api-setup.outputs.arch }}
target: ${{ steps.api-setup.outputs.api_level >= 30 && 'google_apis' || 'default' }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: echo "Generated AVD snapshot for caching."
- name: Run instrumented tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ steps.api-setup.outputs.api_level }}
arch: ${{ steps.api-setup.outputs.arch }}
target: ${{ steps.api-setup.outputs.api_level >= 30 && 'google_apis' || 'default' }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: |
echo "Running instrumented tests on API ${{ steps.api-setup.outputs.api_level }}"
./gradlew :sample:connectedAndroidTest --stacktrace --no-daemon
echo "Instrumented tests completed"
- name: Upload test reports
uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports-api-${{ steps.api-setup.outputs.api_level }}-${{ steps.api-setup.outputs.arch }}
path: |
sample/build/reports/androidTests/connected/
sample/build/outputs/androidTest-results/
retention-days: 7
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-api-${{ steps.api-setup.outputs.api_level }}-${{ steps.api-setup.outputs.arch }}
path: sample/build/test-results/
retention-days: 7
- name: Send Slack notification on push failure
if: failure() && github.event_name == 'push'
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "🚨 Instrumented Tests Failed on ${{ github.event.pull_request.head.ref || github.ref_name }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "🚨 Instrumented Tests Failed\n"
- type: "section"
text:
type: "mrkdwn"
text: "*Repository:* ${{ github.repository }}\n*Branch:* `${{ github.event.pull_request.head.ref || github.ref_name }}`\n*API Level:* ${{ steps.api-setup.outputs.api_level }}\n*Architecture:* ${{ steps.api-setup.outputs.arch }}\n*Commit:* `${{ github.sha }}`\n*Author:* ${{ github.actor }}"
- type: "section"
text:
type: "mrkdwn"
text: "*Workflow Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>"
- name: Update PR labels on success
if: success() && github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr edit ${{ github.event.pull_request.number }} --remove-label "test:all"
- name: Update PR labels on failure
if: failure() && github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr edit ${{ github.event.pull_request.number }} --remove-label "test:all"