bevy/.github/workflows/daily.yml
François 21dc3abe1b
daily job running mobile example on real devices (#8216)
# Objective

- Test mobile example on real devices

## Solution

- Use [BrowserStack](https://www.browserstack.com) to have access to
[real
devices](https://www.browserstack.com/list-of-browsers-and-platforms/app_automate)
- [App Automate](https://www.browserstack.com/app-automate) to run the
example
- [App Percy](https://www.browserstack.com/app-percy) to compare the
screenshot
- Added a daily/manual CI job that will build for iOS and Android, send
the apps to BrowserStack, run the app on one iOS device and one Android
device, capture a screenshot, send it for visual validation, and archive
it in the GitHub action

Example run: https://github.com/mockersf/bevy/actions/runs/4521883534

They currently have a bug with the settings to view snapshots, they
should be public. I'll raise it to them, and if they don't fix it in
time it's possible to work around for everyone to view the results
through their API.

@cart to get this to work, you'll need
- to set up an account on BrowserStack
- add the secrets `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`
to the Bevy repo
- create a project in Percy
- add the secret `PERCY_TOKEN` to the Bevy repo and modify the project
name line 122 in the `Daily.yml` file
2023-03-28 23:16:07 +00:00

124 lines
3.8 KiB
YAML

name: Daily Jobs
on:
schedule:
- cron: '0 12 * * *'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
NIGHTLY_TOOLCHAIN: nightly
jobs:
build-for-iOS:
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- 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@v3
- uses: dtolnay/rust-toolchain@stable
- name: Add Android targets
run: rustup target add 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"
nonce:
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
result: ${{ steps.nonce.outputs.result }}
steps:
- id: nonce
run: echo "result=${{ github.run_id }}-$(date +%s)" >> $GITHUB_OUTPUT
run:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [nonce, build-for-iOS, build-for-Android]
env:
PERCY_PARALLEL_NONCE: ${{ needs.nonce.outputs.result }}
PERCY_PARALLEL_TOTAL: ${{ strategy.job-total }}
strategy:
matrix:
include:
- device: "iPhone 13"
os_version: "15"
- device: "Samsung Galaxy S23"
os_version: "13.0"
steps:
- uses: actions/checkout@v3
- 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 }}
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
DEVICE: ${{ matrix.device }}
OS_VERSION: ${{ matrix.os_version }}
- name: Save screenshots
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: screenshots-${{ matrix.device }}-${{ matrix.os_version }}
path: .github/start-mobile-example/*.png
check-result:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [run]
steps:
- name: Wait for screenshots comparison
run: |
npm install -g @percy/cli@latest
npx percy build:wait --project dede4209/Bevy-Mobile-Example --commit ${{ github.sha }} --fail-on-changes --pass-if-approved
env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}