Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into add_e2e_android
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfaraazkhan committed Jun 4, 2024
2 parents 34c5342 + f46ddb4 commit d57f2f0
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fie
- [ ] Has UI changes
- [ ] Includes text changes and localization file updates
- [ ] Have tested against the 5 core themes to ensure consistency between them.
- [ ] Have run E2E tests by adding label `E2E iOS tests for PR`.

#### Device Information
This PR was tested on: <!-- Device name(s), OS version(s) -->
Expand Down
8 changes: 8 additions & 0 deletions .github/actions/prepare-mobile-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ runs:
echo "::endgroup::"
working-directory: ./fastlane

- name: Cache Ruby gems
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: ci/prepare-node-deps
uses: ./.github/actions/prepare-node-deps
300 changes: 300 additions & 0 deletions .github/workflows/e2e-detox-ci-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
name: Detox E2E Tests Template

on:
workflow_call:
inputs:
run-ios-tests:
description: 'Run iOS tests'
required: true
type: boolean
run-android-tests:
description: 'Run Android tests'
required: true
type: boolean
remove-pr-label:
description: 'Remove PR label'
required: false
type: boolean
default: false
status_check_context:
type: string
required: true
commit_sha:
type: string
required: true
run-type:
type: string
required: false
default: 'PR'
testcase_failure_fatal:
description: 'Should failures be considered fatal'
required: false
type: boolean
default: false

env:
AWS_REGION: 'us-east-1'
ADMIN_EMAIL: ${{ secrets.MM_MOBILE_E2E_ADMIN_EMAIL }}
ADMIN_USERNAME: ${{ secrets.MM_MOBILE_E2E_ADMIN_USERNAME }}
ADMIN_PASSWORD: ${{ secrets.MM_MOBILE_E2E_ADMIN_PASSWORD }}
BRANCH: ${{ github.head_ref || github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
DETOX_AWS_S3_BUCKET: 'mattermost-detox-report'
DETOX_AWS_ACCESS_KEY_ID: ${{ secrets.MM_MOBILE_DETOX_AWS_ACCESS_KEY_ID }}
DETOX_AWS_SECRET_ACCESS_KEY: ${{ secrets.MM_MOBILE_DETOX_AWS_SECRET_ACCESS_KEY }}
HEADLESS: 'true'
TYPE: ${{ inputs.run-type }}
PULL_REQUEST: 'https://github.com/mattermost/mattermost-mobile/pull/${{ github.event.number }}'
SITE_1_URL: ${{ secrets.MM_MOBILE_E2E_SITE_1_URL }}
SITE_2_URL: ${{ secrets.MM_MOBILE_E2E_SITE_2_URL }}
SITE_3_URL: ${{ secrets.MM_MOBILE_E2E_SITE_3_URL }}
ZEPHYR_ENABLE: false
JIRA_PROJECT_KEY: 'MM'
ZEPHYR_API_KEY: ${{ secrets.MM_MOBILE_E2E_ZEPHYR_API_KEY }}
ZEPHYR_FOLDER_ID: '3233873'
TEST_CYCLE_LINK_PREFIX: ${{ secrets.MM_MOBILE_E2E_TEST_CYCLE_LINK_PREFIX }}
WEBHOOK_URL: ${{ secrets.MM_MOBILE_E2E_WEBHOOK_URL }}
FAILURE_MESSAGE: "Something has failed"

jobs:
update-initial-status:
runs-on: ubuntu-22.04
steps:
- uses: mattermost/actions/delivery/update-commit-status@main
env:
GITHUB_TOKEN: ${{ github.token }}
with:
repository_full_name: ${{ github.repository }}
commit_sha: ${{ inputs.commit_sha }}
context: ${{ inputs.status_check_context }}
description: Detox tests for mattermost mobile app
status: pending

generate-specs:
needs: update-initial-status
runs-on: ubuntu-22.04
if: ${{ inputs.run-ios-tests || inputs.run-android-tests }}
outputs:
specs: ${{ steps.generate-specs.outputs.specs }}
build_id: ${{ env.BUILD_ID }}
device_name: ${{ env.DEVICE_NAME }}
device_os_version: ${{ env.DEVICE_OS_VERSION }}
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set Build ID
id: resolve-device
run: |
cd detox
DEVICE_NAME=$(node -p "require('./.detoxrc').devices['ios.simulator'].device.type")
DEVICE_OS_VERSION=$(node -p "require('./.detoxrc').devices['ios.simulator'].device.os")
BUILD_ID="${{ github.run_id }}-$DEVICE_NAME-$DEVICE_OS_VERSION"
echo "BUILD_ID=$(echo ${BUILD_ID} | sed 's/ /_/g')" >> $GITHUB_ENV
echo "DEVICE_NAME=$(echo ${DEVICE_NAME})" >> $GITHUB_ENV
echo "DEVICE_OS_VERSION=$(echo ${DEVICE_OS_VERSION})" >> $GITHUB_ENV
- name: Generate Test Specs
id: generate-specs
uses: ./.github/actions/generate-specs
with:
parallelism: 10
search_path: detox/e2e/test
device_name: ${{ env.DEVICE_NAME }}
device_os_version: ${{env.DEVICE_OS_VERSION}}

build-ios-simulator:
needs: update-initial-status
runs-on: macos-14-large
if: ${{ inputs.run-ios-tests }}
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Prepare iOS Build
uses: ./.github/actions/prepare-ios-build

- name: Build iOS Simulator
env:
TAG: "${{ github.ref_name }}"
AWS_ACCESS_KEY_ID: "${{ secrets.MM_MOBILE_BETA_AWS_ACCESS_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.MM_MOBILE_BETA_AWS_SECRET_ACCESS_KEY }}"
GITHUB_TOKEN: "${{ secrets.MM_MOBILE_GITHUB_TOKEN }}"
run: bundle exec fastlane ios simulator --env ios.simulator
working-directory: ./fastlane

- name: Upload iOS Simulator Build
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ios-build-simulator-${{ github.run_id }}
path: Mattermost-simulator-x86_64.app.zip

e2e-ios:
continue-on-error: true
env:
IOS: true
runs-on: macos-14-large
name: ios-detox-e2e-${{ matrix.runId }}-${{ matrix.deviceName }}-${{ matrix.deviceOsVersion }}
if: ${{ inputs.run-ios-tests }}
timeout-minutes: 40
needs:
- generate-specs
- build-ios-simulator
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate-specs.outputs.specs) }}
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: ci/prepare-node-deps
uses: ./.github/actions/prepare-node-deps

- name: Install Homebrew Dependencies
run: |
brew tap wix/brew
brew install applesimutils
- name: Download iOS Simulator Build
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: ios-build-simulator-${{ github.run_id }}
path: mobile-artifacts

- name: Unzip iOS Simulator Build
run: unzip -o mobile-artifacts/*.zip -d mobile-artifacts/

- name: Start React Native Metro Server
run: npm run start &

- name: Install Detox Dependencies
run: cd detox && npm i

- name: Run Detox E2E Tests
continue-on-error: true # Label might have been removed manually
run: cd detox && npm run e2e:ios-test -- ${{ matrix.specs }}

- name: Upload iOS Test Report
if: always()
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ios-results-${{ matrix.runId }}
path: detox/artifacts/

download-e2e-results:
runs-on: ubuntu-22.04
if: ${{ inputs.run-ios-tests || inputs.run-android-tests }}
needs:
- generate-specs
- e2e-ios
outputs:
failures: "${{ steps.calculate-failures.outputs.failures }}"
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: ci/prepare-node-deps
uses: ./.github/actions/prepare-node-deps

- name: Create artifacts directory
run: mkdir -p detox/artifacts/

- name: Download All Artifacts
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
path: detox/artifacts/
pattern: ios-results-*

- name: Save report Detox Dependencies
id: report-link
run: |
cd detox
npm ci
npm run e2e:save-report
env:
IOS: ${{ inputs.run-ios-tests }}
BUILD_ID: ${{ needs.generate-specs.outputs.build_id }}
DEVICE_NAME: ${{ needs.generate-specs.outputs.device_name }}
DEVICE_OS_VERSION: ${{ needs.generate-specs.outputs.device_os_version }}

- name: Calculate failures
id: calculate-failures
run: |
FAILURES=$(find detox/artifacts/ -name 'summary.json' | xargs -l jq -r '.stats.failures' | jq -s add)
echo "failures=${FAILURES}" >> $GITHUB_OUTPUT
echo "Detox run completed with $FAILURES failures"
update-final-status:
runs-on: ubuntu-22.04
needs:
- generate-specs
- download-e2e-results
steps:
- name: Set Target URL
id: set-url
run: |
s3Folder="${{ env.BUILD_ID }}-${{ env.COMMIT_HASH }}-${{ env.BRANCH }}"
s3Folder=$(echo "$s3Folder" | sed 's/\./-/g')
if ${{ inputs.run-ios-tests }}; then
echo "TARGET_URL=https://${{ env.DETOX_AWS_S3_BUCKET }}.s3.amazonaws.com/${s3Folder}/jest-stare/ios-report.html" >> $GITHUB_ENV
else
echo "TARGET_URL=https://${{ env.DETOX_AWS_S3_BUCKET }}.s3.amazonaws.com/${s3Folder}/jest-stare/android-report.html" >> $GITHUB_ENV
fi
env:
BUILD_ID: ${{ needs.generate-specs.outputs.build_id }}

- name: Determine Status
id: determine-status
run: |
if [[ ${{ needs.download-e2e-results.outputs.failures }} -gt 0 && "${{ inputs.testcase_failure_fatal }}" == "true" ]]; then
echo "status=failure" >> $GITHUB_ENV
else
echo "status=success" >> $GITHUB_ENV
fi
- uses: mattermost/actions/delivery/update-commit-status@main
env:
GITHUB_TOKEN: ${{ github.token }}
with:
repository_full_name: ${{ github.repository }}
commit_sha: ${{ inputs.commit_sha }}
context: ${{ inputs.status_check_context }}
description: |
Completed with ${{ needs.download-e2e-results.outputs.failures }} failures
status: ${{ env.status }}
target_url: ${{ env.TARGET_URL }}

e2e-remove-label:
if: ${{ inputs.remove-pr-label }}
needs:
- download-e2e-results
runs-on: ubuntu-22.04
steps:
- name: e2e/remove-label-from-pr
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
continue-on-error: true # Label might have been removed manually
with:
script: |
const iosLabel = 'E2E iOS tests for PR';
const androidLabel = 'E2E Android tests for PR';
const labels = context.payload.pull_request.labels.map(label => label.name);
if (labels.includes(iosLabel)) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: iosLabel,
});
}

if (labels.includes(androidLabel)) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: androidLabel,
});
}
1 change: 0 additions & 1 deletion .github/workflows/e2e-detox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
pull_request:
branches:
- 'main'
- 'ios_detox_job' # remove before merge
types:
- labeled
workflow_dispatch:
Expand Down

0 comments on commit d57f2f0

Please sign in to comment.