|
| 1 | +name: E2E iOS on demand |
| 2 | + |
| 3 | +# Runs the iOS Maestro E2E suites against a pull request when a maintainer |
| 4 | +# comments `@react-native-bot e2e-tests` on it. The apps come from the |
| 5 | +# artifacts a run of the pull request's head already built, the Maestro flows |
| 6 | +# from the pull request, and the workflows and scripts from the default branch. |
| 7 | + |
| 8 | +on: |
| 9 | + issue_comment: |
| 10 | + types: [created] |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: e2e-ios-on-demand-${{ github.event.issue.number }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + request: |
| 21 | + if: >- |
| 22 | + github.event.issue.pull_request != null && |
| 23 | + startsWith(github.event.comment.body, '@react-native-bot e2e-tests') && |
| 24 | + contains(fromJson('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + actions: read |
| 29 | + pull-requests: write |
| 30 | + outputs: |
| 31 | + head-sha: ${{ steps.find.outputs.head-sha }} |
| 32 | + run-id: ${{ steps.find.outputs.run-id }} |
| 33 | + steps: |
| 34 | + - name: Find the pull request's build |
| 35 | + id: find |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ github.token }} |
| 38 | + GH_REPO: ${{ github.repository }} |
| 39 | + PR: ${{ github.event.issue.number }} |
| 40 | + run: | |
| 41 | + set -euo pipefail |
| 42 | + sha=$(gh api "repos/$GH_REPO/pulls/$PR" --jq .head.sha) |
| 43 | + needed="RNTesterApp-NewArch-Debug RNTesterApp-NewArch-Release RNTestProject-Debug RNTestProject-Release react-native-package" |
| 44 | + run_id= |
| 45 | + for id in $(gh api "repos/$GH_REPO/actions/runs?head_sha=$sha&per_page=30" --jq '.workflow_runs[].id'); do |
| 46 | + have=$(gh api "repos/$GH_REPO/actions/runs/$id/artifacts?per_page=100" --jq '.artifacts[].name') |
| 47 | + missing= |
| 48 | + for name in $needed; do |
| 49 | + grep -qx "$name" <<<"$have" || missing="$missing $name" |
| 50 | + done |
| 51 | + if [ -z "$missing" ]; then |
| 52 | + run_id=$id |
| 53 | + break |
| 54 | + fi |
| 55 | + done |
| 56 | + if [ -z "$run_id" ]; then |
| 57 | + echo "::error::no run of $sha has built all of: $needed" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + echo "head-sha=$sha" >> "$GITHUB_OUTPUT" |
| 61 | + echo "run-id=$run_id" >> "$GITHUB_OUTPUT" |
| 62 | + - name: Acknowledge the request |
| 63 | + env: |
| 64 | + GH_TOKEN: ${{ github.token }} |
| 65 | + GH_REPO: ${{ github.repository }} |
| 66 | + COMMENT: ${{ github.event.comment.id }} |
| 67 | + run: gh api -X POST "repos/$GH_REPO/issues/comments/$COMMENT/reactions" -f content=rocket > /dev/null |
| 68 | + |
| 69 | + rntester: |
| 70 | + needs: request |
| 71 | + uses: ./.github/workflows/e2e-ios-rntester.yml |
| 72 | + permissions: |
| 73 | + contents: read |
| 74 | + actions: read |
| 75 | + id-token: write |
| 76 | + with: |
| 77 | + artifact-run-id: ${{ needs.request.outputs.run-id }} |
| 78 | + flows-ref: ${{ needs.request.outputs.head-sha }} |
| 79 | + fail-on-error: true |
| 80 | + |
| 81 | + templateapp: |
| 82 | + needs: request |
| 83 | + uses: ./.github/workflows/e2e-ios-templateapp.yml |
| 84 | + permissions: |
| 85 | + contents: read |
| 86 | + actions: read |
| 87 | + id-token: write |
| 88 | + with: |
| 89 | + artifact-run-id: ${{ needs.request.outputs.run-id }} |
| 90 | + flows-ref: ${{ needs.request.outputs.head-sha }} |
| 91 | + fail-on-error: true |
| 92 | + |
| 93 | + report: |
| 94 | + needs: [request, rntester, templateapp] |
| 95 | + if: always() |
| 96 | + runs-on: ubuntu-latest |
| 97 | + permissions: |
| 98 | + pull-requests: write |
| 99 | + steps: |
| 100 | + - name: Comment the results |
| 101 | + env: |
| 102 | + GH_TOKEN: ${{ secrets.REACT_NATIVE_BOT_GITHUB_TOKEN || github.token }} |
| 103 | + GH_REPO: ${{ github.repository }} |
| 104 | + PR: ${{ github.event.issue.number }} |
| 105 | + REQUEST: ${{ needs.request.result }} |
| 106 | + HEAD_SHA: ${{ needs.request.outputs.head-sha }} |
| 107 | + RNTESTER: ${{ needs.rntester.outputs.status }} |
| 108 | + TEMPLATEAPP: ${{ needs.templateapp.outputs.status }} |
| 109 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 110 | + run: | |
| 111 | + set -euo pipefail |
| 112 | + if [ "$REQUEST" != "success" ]; then |
| 113 | + body="iOS E2E: no run of the pull request's head has built the apps yet, see [the request]($RUN_URL)." |
| 114 | + else |
| 115 | + body="iOS E2E on ${HEAD_SHA:0:7} ([run]($RUN_URL)): RNTester **${RNTESTER:-skipped}**, template app **${TEMPLATEAPP:-skipped}**." |
| 116 | + fi |
| 117 | + gh api -X POST "repos/$GH_REPO/issues/$PR/comments" -f body="$body" > /dev/null |
0 commit comments