Automate Android benchmark running / data processing (#2991)
This commit is contained in:
139
.github/actions/aws-device-farm-run/action.yml
vendored
139
.github/actions/aws-device-farm-run/action.yml
vendored
@@ -1,139 +0,0 @@
|
||||
name: 'aws-device-farm-run'
|
||||
description: 'Run device test on AWS Device Farm'
|
||||
inputs:
|
||||
name:
|
||||
description: 'Name of the test'
|
||||
required: true
|
||||
appType:
|
||||
description: 'Type of upload for app'
|
||||
required: true
|
||||
appFile:
|
||||
description: 'Application file to be uploaded'
|
||||
required: false
|
||||
testFile:
|
||||
description: 'Application file to be uploaded'
|
||||
required: false
|
||||
testPackageType:
|
||||
description: 'e.g. INSTRUMENTATION_TEST_PACKAGE, XCTEST_TEST_PACKAGE'
|
||||
required: true
|
||||
testType:
|
||||
description: 'e.g. INSTRUMENTATION, XCTEST'
|
||||
required: true
|
||||
testFilter:
|
||||
description: 'Filter tests'
|
||||
required: false
|
||||
externalData:
|
||||
description: 'ARN of external data package'
|
||||
required: false
|
||||
AWS_ACCESS_KEY_ID:
|
||||
description: "AWS_ACCESS_KEY_ID"
|
||||
required: true
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
description: "AWS_SECRET_ACCESS_KEY"
|
||||
required: true
|
||||
AWS_ROLE_TO_ASSUME:
|
||||
description: "AWS_ROLE_TO_ASSUME"
|
||||
required: true
|
||||
AWS_DEVICE_FARM_PROJECT_ARN:
|
||||
description: "AWS_DEVICE_FARM_PROJECT_ARN"
|
||||
required: true
|
||||
AWS_DEVICE_FARM_DEVICE_POOL_ARN:
|
||||
description: "AWS_DEVICE_FARM_DEVICE_POOL_ARN"
|
||||
required: true
|
||||
testSpecArn:
|
||||
description: "ARN of test spec"
|
||||
required: false
|
||||
outputs:
|
||||
runArn:
|
||||
description: ARN of run
|
||||
value: ${{ steps.schedule_run.outputs.runArn }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-region: us-west-2
|
||||
role-to-assume: ${{ inputs.AWS_ROLE_TO_ASSUME }}
|
||||
role-session-name: ${{ github.run_id }}
|
||||
role-duration-seconds: 14400
|
||||
|
||||
- name: Create upload app
|
||||
shell: bash
|
||||
run: |
|
||||
response=$(aws devicefarm create-upload --type ${{ inputs.appType }} --name ${{ inputs.appFile }} --project-arn ${{ inputs.AWS_DEVICE_FARM_PROJECT_ARN }})
|
||||
echo "$response"
|
||||
arn="$(jq -r '.upload.arn' <<< "$response")"
|
||||
url="$(jq -r '.upload.url' <<< "$response")"
|
||||
echo "app_arn=$arn" >> "$GITHUB_ENV"
|
||||
echo "app_url=$url" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Create upload test package
|
||||
shell: bash
|
||||
run: |
|
||||
response=$(aws devicefarm create-upload --type ${{ inputs.testPackageType }} --name ${{ inputs.testFile }} --project-arn ${{ inputs.AWS_DEVICE_FARM_PROJECT_ARN }})
|
||||
echo "$response"
|
||||
arn="$(jq -r '.upload.arn' <<< "$response")"
|
||||
url="$(jq -r '.upload.url' <<< "$response")"
|
||||
echo "test_package_arn=$arn" >> "$GITHUB_ENV"
|
||||
echo "test_package_url=$url" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Upload ${{ inputs.appFile }}, ${{ inputs.testFile }}
|
||||
shell: bash
|
||||
run: |
|
||||
curl -T ${{ inputs.appFile }} "${{ env.app_url }}"
|
||||
curl -T ${{ inputs.testFile }} "${{ env.test_package_url }}"
|
||||
|
||||
max_checks=10
|
||||
sleep_time=5
|
||||
|
||||
check_status() {
|
||||
aws devicefarm get-upload --arn "$1" | jq -r '.upload.status'
|
||||
}
|
||||
|
||||
while ((max_checks--)); do
|
||||
status_app="$(check_status "${{ env.app_arn }}")"
|
||||
status_test_package="$(check_status "${{ env.test_package_arn }}")"
|
||||
|
||||
echo status_app="$status_app"
|
||||
echo status_test_package="$status_test_package"
|
||||
|
||||
if [[ "$status_app" == "SUCCEEDED" && "$status_test_package" == "SUCCEEDED" ]]; then
|
||||
exit 0
|
||||
elif ((max_checks == 0)); then
|
||||
echo "App or test package failed to upload"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep $sleep_time
|
||||
done
|
||||
|
||||
- name: Schedule test run
|
||||
id: schedule_run
|
||||
shell: bash
|
||||
run: |
|
||||
arn="$(aws devicefarm schedule-run \
|
||||
--project-arn ${{ inputs.AWS_DEVICE_FARM_PROJECT_ARN }} \
|
||||
--name "MapLibre Native ${{ inputs.name }}" \
|
||||
--app-arn ${{ env.app_arn }} \
|
||||
--device-pool-arn ${{ inputs.AWS_DEVICE_FARM_DEVICE_POOL_ARN }} \
|
||||
--test type=${{ inputs.testType }},testPackageArn=${{ env.test_package_arn }}${{ inputs.testFilter && ',filter=' }}${{ inputs.testFilter }}${{ inputs.testSpecArn && ',testSpecArn=' }}${{ inputs.testSpecArn }} \
|
||||
${{ inputs.externalData && '--configuration extraDataPackageArn=' }}${{ inputs.externalData }} \
|
||||
--execution-configuration videoCapture=false \
|
||||
--output text --query "run.arn")"
|
||||
|
||||
echo "runArn=$arn" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# wait until result is not PENDING
|
||||
# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/devicefarm/get-run.html#output
|
||||
while true; do
|
||||
sleep 30
|
||||
result="$(aws devicefarm get-run --arn "$arn" --output text --query "run.result")"
|
||||
case $result in
|
||||
FAILED|ERRORED|STOPPED) echo "Run $result" && exit 1 ;;
|
||||
SKIPPED|PASSED) echo "Run $result" && exit 0 ;;
|
||||
PENDING) continue ;;
|
||||
*) echo "Unexpected run result $result" && exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
60
.github/workflows/android-device-test.yml
vendored
60
.github/workflows/android-device-test.yml
vendored
@@ -70,6 +70,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: '.nvmrc'
|
||||
|
||||
- id: parent_workflow
|
||||
run: |
|
||||
conclusion=$(curl ${{ github.event.workflow_run.jobs_url }} | jq -r '.jobs[] | select(.name == "android-build").conclusion')
|
||||
@@ -130,33 +134,25 @@ jobs:
|
||||
aws-region: us-west-2
|
||||
role-to-assume: ${{ vars.OIDC_AWS_ROLE_TO_ASSUME }}
|
||||
role-session-name: ${{ github.run_id }}
|
||||
|
||||
- name: Upload external data
|
||||
if: env.run_device_test == 'true'
|
||||
|
||||
- name: Run ${{ matrix.test.name }} on AWS Device Farm
|
||||
run: |
|
||||
export RESULTS_API=${{ secrets.MLN_RESULTS_API }}
|
||||
export AWS_DEVICE_FARM_PROJECT_ARN=${{ vars.AWS_DEVICE_FARM_PROJECT_ARN }}
|
||||
upload_arn="$(.github/workflows/android-device-test/upload-external-data.sh)"
|
||||
echo external_data_arn="$upload_arn" >> "$GITHUB_ENV"
|
||||
export name="${{ matrix.test.name }}"
|
||||
export appType=ANDROID_APP
|
||||
export appFile="${{ matrix.test.appFile }}"
|
||||
export testFile="${{ matrix.test.testFile }}"
|
||||
export testPackageType=INSTRUMENTATION_TEST_PACKAGE
|
||||
export testType=INSTRUMENTATION
|
||||
export testFilter="${{ matrix.test.testFilter }}"
|
||||
export AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}"
|
||||
export AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}"
|
||||
export AWS_ROLE_TO_ASSUME="${{ vars.OIDC_AWS_ROLE_TO_ASSUME }}"
|
||||
export AWS_DEVICE_FARM_PROJECT_ARN="${{ vars.AWS_DEVICE_FARM_PROJECT_ARN }}"
|
||||
export AWS_DEVICE_FARM_DEVICE_POOL_ARN="${{ matrix.test.devicePool }}"
|
||||
export testSpecArn="${{ matrix.test.testSpecArn }}"
|
||||
export wait_for_completion=true
|
||||
|
||||
- uses: ./.github/actions/aws-device-farm-run
|
||||
id: aws_device_farm_run
|
||||
if: env.run_device_test == 'true'
|
||||
with:
|
||||
name: ${{ matrix.test.name }}
|
||||
appType: ANDROID_APP
|
||||
appFile: ${{ matrix.test.appFile }}
|
||||
testFile: ${{ matrix.test.testFile }}
|
||||
testPackageType: INSTRUMENTATION_TEST_PACKAGE
|
||||
testType: INSTRUMENTATION
|
||||
testFilter: ${{ matrix.test.testFilter }}
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
AWS_ROLE_TO_ASSUME: ${{ vars.OIDC_AWS_ROLE_TO_ASSUME }}
|
||||
AWS_DEVICE_FARM_PROJECT_ARN: ${{ vars.AWS_DEVICE_FARM_PROJECT_ARN }}
|
||||
AWS_DEVICE_FARM_DEVICE_POOL_ARN: ${{ matrix.test.devicePool }}
|
||||
externalData: ${{ env.external_data_arn }}
|
||||
testSpecArn: ${{ matrix.test.testSpecArn }}
|
||||
echo run_arn="$(./scripts/aws-device-farm/aws-device-farm-run.sh)" > "$GITHUB_ENV"
|
||||
|
||||
- name: Store Test Artifacts
|
||||
if: (matrix.test.name == 'Android Benchmark' || failure()) && env.run_device_test == 'true'
|
||||
@@ -164,19 +160,15 @@ jobs:
|
||||
npm install
|
||||
results_dir="$(mktemp -d)"
|
||||
echo results_dir="$results_dir" >> "$GITHUB_ENV"
|
||||
node scripts/aws-device-farm/store-test-artifacts.mjs --runArn ${{ steps.aws_device_farm_run.outputs.runArn }} --outputDir "$results_dir"
|
||||
zip -r test_artifacts.zip ${{ env.results_dir }}
|
||||
node scripts/aws-device-farm/store-test-artifacts.mjs --runArn ${{ env.run_arn }} --outputDir "$results_dir"
|
||||
zip -r test_artifacts.zip "$results_dir"
|
||||
|
||||
- name: Store Benchmark Results
|
||||
if: matrix.test.name == 'Android Benchmark' && env.run_device_test == 'true'
|
||||
run: |
|
||||
for zipfile in ${{ env.results_dir }}/*.zip; do
|
||||
unzip "$zipfile" -d "${zipfile%.zip}"
|
||||
done
|
||||
|
||||
find "${{ env.results_dir }}" -name 'benchmark_results.json' | while read -r benchmark_json; do
|
||||
aws s3 cp "$benchmark_json" "s3://maplibre-native/android-benchmark-render/$(uuidgen).json"
|
||||
done
|
||||
benchmark_results_dir="$(mktemp -d)"
|
||||
node scripts/aws-device-farm/collect-benchmark-outputs.mjs --inputDir "${{ env.results_dir }}" --outputDir "$benchmark_results_dir"
|
||||
node scripts/aws-device-farm/upload-benchmark-outputs-to-s3.mjs --dir "$benchmark_results_dir"
|
||||
|
||||
- name: Upload Test Artifacts
|
||||
if: (matrix.test.name == 'Android Benchmark' || failure()) && env.run_device_test == 'true'
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Check if the required variables are defined
|
||||
if [ -z "$RESULTS_API" ] || [ -z "$AWS_DEVICE_FARM_PROJECT_ARN" ]; then
|
||||
echo "Error: Missing required variables."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$(mktemp -d)"
|
||||
|
||||
cat << EOF > instrumentation-test-input.json
|
||||
{
|
||||
"styleNames": ["Facebook Light", "MapTiler Basic", "Americana"],
|
||||
"styleURLs": [
|
||||
"https://external.xx.fbcdn.net/maps/vt/style/canterbury_1_0/?locale=en_US",
|
||||
"https://api.maptiler.com/maps/basic-v2/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL",
|
||||
"https://americanamap.org/style.json"
|
||||
],
|
||||
"resultsAPI": "$RESULTS_API",
|
||||
"apiKey": "get_your_own_OpIi9ZULNHzrESv6T2vL"
|
||||
}
|
||||
EOF
|
||||
|
||||
>&2 zip instrumentation-test-input.zip instrumentation-test-input.json
|
||||
upload_json="$(aws devicefarm create-upload --project-arn "$AWS_DEVICE_FARM_PROJECT_ARN" --type EXTERNAL_DATA --name instrumentation-test-input.zip --output json)"
|
||||
upload_url="$(echo "$upload_json" | jq -r '.upload.url')"
|
||||
upload_arn="$(echo "$upload_json" | jq -r '.upload.arn')"
|
||||
curl -T instrumentation-test-input.zip "$upload_url"
|
||||
|
||||
retries=5
|
||||
while true; do
|
||||
upload_status="$(aws devicefarm get-upload --arn "$upload_arn" --output text --query upload.status)"
|
||||
>&2 echo "Upload $upload_status"
|
||||
sleep 1
|
||||
if [[ "$upload_status" == "SUCCEEDED" ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
if (( --retries == 0 )); then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$upload_arn"
|
||||
29
.github/workflows/ios-device-test.yml
vendored
29
.github/workflows/ios-device-test.yml
vendored
@@ -49,20 +49,23 @@ jobs:
|
||||
with:
|
||||
files: "${{ matrix.test.xcTestFile }}, ${{ matrix.test.ipaFile }}"
|
||||
|
||||
- uses: ./.github/actions/aws-device-farm-run
|
||||
- name: Run ${{ matrix.test.name }} on AWS Device Farm
|
||||
if: steps.check_files.outputs.files_exists == 'true'
|
||||
with:
|
||||
name: ${{ matrix.test.name }}
|
||||
appType: IOS_APP
|
||||
appFile: ${{ matrix.test.ipaFile }}
|
||||
testFile: ${{ matrix.test.xcTestFile }}
|
||||
testPackageType: XCTEST_TEST_PACKAGE
|
||||
testType: XCTEST
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
AWS_ROLE_TO_ASSUME: ${{ vars.OIDC_AWS_ROLE_TO_ASSUME }}
|
||||
AWS_DEVICE_FARM_PROJECT_ARN: ${{ vars.AWS_DEVICE_FARM_PROJECT_ARN }}
|
||||
AWS_DEVICE_FARM_DEVICE_POOL_ARN: ${{ vars.AWS_DEVICE_FARM_IPHONE_DEVICE_POOL_ARN }}
|
||||
run: |
|
||||
export name="${{ matrix.test.name }}"
|
||||
export appType=IOS_APP
|
||||
export appFile="${{ matrix.test.ipaFile }}"
|
||||
export testFile="${{ matrix.test.xcTestFile }}"
|
||||
export testPackageType=XCTEST_TEST_PACKAGE
|
||||
export testType=XCTEST
|
||||
export AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}"
|
||||
export AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}"
|
||||
export AWS_ROLE_TO_ASSUME="${{ vars.OIDC_AWS_ROLE_TO_ASSUME }}"
|
||||
export AWS_DEVICE_FARM_PROJECT_ARN="${{ vars.AWS_DEVICE_FARM_PROJECT_ARN }}"
|
||||
export AWS_DEVICE_FARM_DEVICE_POOL_ARN="${{ vars.AWS_DEVICE_FARM_IPHONE_DEVICE_POOL_ARN }}"
|
||||
export wait_for_completion=true
|
||||
|
||||
./scripts/aws-device-farm/aws-device-farm-run.sh
|
||||
|
||||
- uses: LouisBrunner/checks-action@v2.0.0
|
||||
if: always()
|
||||
|
||||
Reference in New Issue
Block a user