Workflow - Tests on Mobile #20
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
| name: Workflow - Tests on Mobile | |
| on: | |
| workflow_call: | |
| inputs: | |
| repository: | |
| required: true | |
| type: string | |
| default: 'bevyengine/bevy' | |
| gitref: | |
| required: true | |
| type: string | |
| mobile_percy_project: | |
| required: false | |
| type: string | |
| pixeleagle_project: | |
| required: true | |
| type: string | |
| branch: | |
| required: true | |
| type: string | |
| default: 'B25A040A-A980-4602-B90C-D480AB84076D' | |
| workflow_dispatch: | |
| inputs: | |
| repository: | |
| required: true | |
| type: string | |
| default: 'bevyengine/bevy' | |
| gitref: | |
| required: true | |
| type: string | |
| mobile_percy_project: | |
| required: false | |
| type: string | |
| pixeleagle_project: | |
| required: true | |
| type: string | |
| default: 'B25A040A-A980-4602-B90C-D480AB84076D' | |
| branch: | |
| required: true | |
| type: string | |
| jobs: | |
| build-for-iOS: | |
| runs-on: macos-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ inputs.repository }} | |
| ref: ${{ inputs.gitref }} | |
| - uses: dtolnay/rust-toolchain@stable | |
| - name: Add iOS targets | |
| run: rustup target add aarch64-apple-ios x86_64-apple-ios | |
| - name: Build app for iOS | |
| run: | | |
| cd examples/mobile | |
| make xcodebuild-iphone | |
| mkdir Payload | |
| mv build/Build/Products/Debug-iphoneos/bevy_mobile_example.app Payload | |
| zip -r bevy_mobile_example.zip Payload | |
| mv bevy_mobile_example.zip bevy_mobile_example.ipa | |
| - name: Upload to Browser Stack | |
| run: | | |
| curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \ | |
| -X POST "https://api-cloud.browserstack.com/app-automate/upload" \ | |
| -F "file=@examples/mobile/bevy_mobile_example.ipa" \ | |
| -F "custom_id=$GITHUB_RUN_ID" | |
| build-for-Android: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ inputs.repository }} | |
| ref: ${{ inputs.gitref }} | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: x86_64-unknown-linux-gnu,aarch64-linux-android,armv7-linux-androideabi | |
| - name: Install Cargo APK | |
| run: cargo install --force cargo-apk | |
| - name: Build app for Android | |
| run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy_mobile_example | |
| env: | |
| # This will reduce the APK size from 1GB to ~200MB | |
| CARGO_PROFILE_DEV_DEBUG: false | |
| - name: Upload to Browser Stack | |
| run: | | |
| curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \ | |
| -X POST "https://api-cloud.browserstack.com/app-automate/upload" \ | |
| -F "file=@target/debug/apk/bevyexample.apk" \ | |
| -F "custom_id=$GITHUB_RUN_ID" | |
| take-screenshots: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| needs: [build-for-iOS, build-for-Android] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: "iOS" | |
| device: "iPhone 13" | |
| os_version: "15" | |
| - os: "iOS" | |
| device: "iPhone 14" | |
| os_version: "16" | |
| - os: "iOS" | |
| device: "iPhone 15" | |
| os_version: "17" | |
| - os: "Android" | |
| device: "Xiaomi Redmi Note 11" | |
| os_version: "11.0" | |
| - os: "Android" | |
| device: "Google Pixel 6" | |
| os_version: "12.0" | |
| - os: "Android" | |
| device: "Samsung Galaxy S23" | |
| os_version: "13.0" | |
| - os: "Android" | |
| device: "Google Pixel 8" | |
| os_version: "14.0" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ inputs.repository }} | |
| ref: ${{ inputs.gitref }} | |
| - name: Set Percy Token if needed | |
| if: "${{ inputs.mobile_percy_project != '' }}" | |
| run: echo "PERCY_TOKEN=${{ secrets.PERCY_TOKEN_MOBILE }}" >> $GITHUB_ENV | |
| - name: Run Example | |
| run: | | |
| cd .github/start-mobile-example | |
| npm install | |
| npm install -g @percy/cli@latest | |
| npx percy app:exec --parallel -- npm run mobile | |
| env: | |
| BROWSERSTACK_APP_ID: ${{ github.run_id }} | |
| BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} | |
| BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | |
| DEVICE: ${{ matrix.device }} | |
| OS_VERSION: ${{ matrix.os_version }} | |
| PERCY_COMMIT: ${{ inputs.gitref }} | |
| PERCY_PARALLEL_NONCE: ${{ github.run_id }} | |
| PERCY_PARALLEL_TOTAL: ${{ strategy.job-total }} | |
| - name: Save screenshots | |
| if: ${{ always() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: screenshots-${{ matrix.device }}-${{ matrix.os_version }} | |
| path: .github/start-mobile-example/*.png | |
| - name: Send to Pixel Eagle | |
| run: | | |
| run=`curl https://pixel-eagle.com/${{ inputs.pixeleagle_project }}/runs -H 'Content-Type: application/json' -d '{"device":"${{ matrix.device }}", "os":"${{ matrix.os }}-${{ matrix.os_version }}", "gitref": "${{ inputs.gitref }}", "branch": "${{ inputs.branch }}"}' | jq '.id'` | |
| SAVEIFS=$IFS | |
| IFS=$'\n' | |
| cd .github/start-mobile-example | |
| # Build a json array of screenshots and their hashes | |
| hashes='['; | |
| for screenshot in $(find . -type f -maxdepth 1 -name "*.png"); | |
| do | |
| name=${screenshot:2} | |
| echo $name | |
| hash=`shasum -a 256 $screenshot | awk '{print $1}'` | |
| hashes="$hashes [\"$name\",\"$hash\"]," | |
| done | |
| hashes=`echo $hashes | rev | cut -c 2- | rev` | |
| hashes="$hashes]" | |
| IFS=$SAVEIFS | |
| # Upload screenshots with unknown hashes | |
| curl https://pixel-eagle.com/${{ inputs.pixeleagle_project }}/runs/$run/hashes -H 'Content-Type: application/json' -d "$hashes" | jq '.[]|[.name] | @tsv' | | |
| while IFS=$'\t' read -r name; do | |
| name=`echo $name | tr -d '"'` | |
| echo "Uploading $name" | |
| curl https://pixel-eagle.com/${{ inputs.pixeleagle_project }}/runs/$run/screenshots -F "data=@./$name" -F "screenshot=$name" -H "Authorization: Bearer ${{ secrets.PIXELEAGLE }}" | |
| echo | |
| done | |
| IFS=$SAVEIFS | |
| curl https://pixel-eagle.com/${{ inputs.pixeleagle_project }}/runs/$run/compare/auto -H 'Content-Type: application/json' -d '{"os":"<equal>", "device":"<equal>", "branch": "main"}' | |
| mobile-check-result: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| needs: [take-screenshots] | |
| if: always() | |
| steps: | |
| - name: Wait for screenshots comparison | |
| if: ${{ inputs.mobile_percy_project != '' }} | |
| run: | | |
| npm install -g @percy/cli@latest | |
| npx percy build:wait --project ${{ inputs.mobile_percy_project }} --commit ${{ inputs.gitref }} | |
| env: | |
| PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_MOBILE }} |