Skip to content

Commit

Permalink
Run mobile on prs (#39)
Browse files Browse the repository at this point in the history
* update action

* can send mobile screenshots to percy eagle

* can run mobile on PR

* don't use latest --json

* limit depth of search

* switch condition around

* add os name

* correct folder to search screenshots in

* remove concurrency group

* change the directory for screenshots upload

* trigger comparison
  • Loading branch information
mockersf authored Apr 3, 2024
1 parent 6fd86be commit 20da964
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 27 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/example-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
windows_percy_project: ${{ steps.env.outputs.windows_percy_project }}
macos_percy_project: ${{ steps.env.outputs.macos_percy_project }}
mobile_percy_project: ${{ steps.env.outputs.mobile_percy_project }}
mobile_nonce: ${{ steps.env.outputs.mobile_nonce }}
pixeleagle_project: ${{ steps.env.outputs.pixeleagle_project }}
updated: ${{ steps.version-check.outputs.updated }}
steps:
- name: Checkout Bevy main branch
Expand All @@ -43,8 +43,8 @@ jobs:
echo "windows_percy_project=dede4209/Screenshots-Windows-DX12" >> $GITHUB_OUTPUT
echo "macos_percy_project=dede4209/Screenshots-macOS-Metal" >> $GITHUB_OUTPUT
echo "mobile_percy_project=dede4209/Bevy-Mobile-Example" >> $GITHUB_OUTPUT
echo "pixeleagle_project=B25A040A-A980-4602-B90C-D480AB84076D" >> $GITHUB_OUTPUT
echo "pages=`python -c \"import json; print(json.dumps([i for i in range($page_count)]))\"`" >> $GITHUB_OUTPUT
echo "mobile_nonce=${{ github.run_id }}-$(date +%s)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
ref: 'results'
Expand Down Expand Up @@ -530,8 +530,9 @@ jobs:
uses: ./.github/workflows/workflow-mobile.yml
with:
gitref: ${{ needs.get-environment.outputs.gitref }}
nonce: ${{ needs.get-environment.outputs.mobile_nonce }}
mobile_percy_project: ${{ needs.get-environment.outputs.mobile_percy_project }}
pixeleagle_project: ${{ needs.get-environment.outputs.pixeleagle_project }}
branch: "main"
secrets: inherit

send-to-pixel-eagle:
Expand Down Expand Up @@ -567,9 +568,7 @@ jobs:
- name: Send to Pixel Eagle
if: steps.gather-examples.outcome == 'success'
run: |
project="B25A040A-A980-4602-B90C-D480AB84076D"
run=`curl https://pixel-eagle.vleue.com/$project/runs --json '{"os":"${{ matrix.os }}", "gitref": "${{ needs.get-environment.outputs.gitref }}", "branch": "main"}' | jq '.id'`
run=`curl https://pixel-eagle.vleue.com/${{ needs.get-environment.outputs.pixeleagle_project }}/runs --json '{"os":"${{ matrix.os }}", "gitref": "${{ needs.get-environment.outputs.gitref }}", "branch": "main"}' | jq '.id'`
SAVEIFS=$IFS
Expand All @@ -592,19 +591,19 @@ jobs:
IFS=$SAVEIFS
# Upload screenshots with unknown hashes
curl https://pixel-eagle.vleue.com/$project/runs/$run/hashes --json "$hashes" | jq '.[]|[.name] | @tsv' |
curl https://pixel-eagle.vleue.com/${{ needs.get-environment.outputs.pixeleagle_project }}/runs/$run/hashes --json "$hashes" | jq '.[]|[.name] | @tsv' |
while IFS=$'\t' read -r name; do
name=`echo $name | tr -d '"'`
echo "Uploading $name"
curl https://pixel-eagle.vleue.com/$project/runs/$run/screenshots -F "data=@./$name" -F "screenshot=$name"
curl https://pixel-eagle.vleue.com/${{ needs.get-environment.outputs.pixeleagle_project }}/runs/$run/screenshots -F "data=@./$name" -F "screenshot=$name"
echo
done
IFS=$SAVEIFS
cd ..
curl https://pixel-eagle.vleue.com/$project/runs/$run/compare/auto --json '{"os":"<equal>", "branch": "main"}' | jq '{project_id: .project_id, from: .from, to: .to}' > pixeleagle-${{ matrix.os }}.json
curl https://pixel-eagle.vleue.com/${{ needs.get-environment.outputs.pixeleagle_project }}/runs/$run/compare/auto --json '{"os":"<equal>", "branch": "main"}' | jq '{project_id: .project_id, from: .from, to: .to}' > pixeleagle-${{ matrix.os }}.json
cat pixeleagle-${{ matrix.os }}.json
echo "created run $run"
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/run-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ on:
required: true
type: string

concurrency:
group: ${{ github.repository }}-example-report-PR

env:
PER_PAGE: 20

Expand All @@ -22,6 +19,7 @@ jobs:
pages: ${{ steps.env.outputs.pages }}
gitref: ${{ steps.env.outputs.gitref }}
date: ${{ steps.env.outputs.date }}
pixeleagle_project: ${{ steps.env.outputs.pixeleagle_project }}
steps:
- name: Checkout Bevy main branch
uses: actions/checkout@v4
Expand All @@ -40,6 +38,7 @@ jobs:
echo "gitref=`git rev-parse HEAD`" >> $GITHUB_OUTPUT
echo "date=`date +%Y%m%d%H%M`" >> $GITHUB_OUTPUT
echo "pages=`python -c \"import json; print(json.dumps([i for i in range($page_count)]))\"`" >> $GITHUB_OUTPUT
echo "pixeleagle_project=B25A040A-A980-4602-B90C-D480AB84076D" >> $GITHUB_OUTPUT
take-screenshots:
name: Take Screenshots
Expand Down Expand Up @@ -235,3 +234,12 @@ jobs:
cat pixeleagle-${{ matrix.os }}.json
echo "created run $run"
mobile-run:
needs: [get-environment]
uses: ./.github/workflows/workflow-mobile.yml
with:
gitref: ${{ needs.get-environment.outputs.gitref }}
pixeleagle_project: ${{ needs.get-environment.outputs.pixeleagle_project }}
branch: "PR-${{ inputs.pr }}"
secrets: inherit
80 changes: 65 additions & 15 deletions .github/workflows/workflow-mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ on:
gitref:
required: true
type: string
nonce:
mobile_percy_project:
required: false
type: string
pixeleagle_project:
required: true
type: string
mobile_percy_project:
branch:
required: true
type: string

Expand Down Expand Up @@ -78,32 +81,40 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [build-for-iOS, build-for-Android]
env:
PERCY_PARALLEL_NONCE: ${{ inputs.nonce }}
PERCY_PARALLEL_TOTAL: ${{ strategy.job-total }}
strategy:
matrix:
include:
- device: "iPhone 13"
- os: "iOS"
device: "iPhone 13"
os_version: "15"
- device: "iPhone 14"
- os: "iOS"
device: "iPhone 14"
os_version: "16"
- device: "iPhone 15"
- os: "iOS"
device: "iPhone 15"
os_version: "17"
- device: "Xiaomi Redmi Note 11"
- os: "Android"
device: "Xiaomi Redmi Note 11"
os_version: "11.0"
- device: "Google Pixel 6"
- os: "Android"
device: "Google Pixel 6"
os_version: "12.0"
- device: "Samsung Galaxy S23"
- os: "Android"
device: "Samsung Galaxy S23"
os_version: "13.0"
- device: "Google Pixel 8"
- os: "Android"
device: "Google Pixel 8"
os_version: "14.0"
steps:
- uses: actions/checkout@v4
with:
repository: 'bevyengine/bevy'
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
Expand All @@ -114,25 +125,64 @@ jobs:
BROWSERSTACK_APP_ID: ${{ github.run_id }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_MOBILE }}
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@v3
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.vleue.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.vleue.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.vleue.com/${{ inputs.pixeleagle_project }}/runs/$run/screenshots -F "data=@./$name" -F "screenshot=$name"
echo
done
IFS=$SAVEIFS
curl https://pixel-eagle.vleue.com/$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: [mobile-run]
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 }}
Expand Down

0 comments on commit 20da964

Please sign in to comment.