pipeline-segment-electron-test.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. name: Pipeline Segment - Electron Test
  2. on:
  3. workflow_call:
  4. inputs:
  5. target-platform:
  6. type: string
  7. description: 'Platform to run on, can be macos or linux'
  8. required: true
  9. target-arch:
  10. type: string
  11. description: 'Arch to build for, can be x64, arm64 or arm'
  12. required: true
  13. test-runs-on:
  14. type: string
  15. description: 'What host to run the tests on'
  16. required: true
  17. test-container:
  18. type: string
  19. description: 'JSON container information for aks runs-on'
  20. required: false
  21. default: '{"image":null}'
  22. is-asan:
  23. description: 'Building the Address Sanitizer (ASan) Linux build'
  24. required: false
  25. type: boolean
  26. default: false
  27. concurrency:
  28. group: electron-test-${{ inputs.target-platform }}-${{ inputs.target-arch }}-${{ inputs.is-asan }}-${{ github.ref }}
  29. cancel-in-progress: ${{ github.ref != 'refs/heads/main' && !endsWith(github.ref, '-x-y') }}
  30. permissions:
  31. contents: read
  32. issues: read
  33. pull-requests: read
  34. env:
  35. ELECTRON_OUT_DIR: Default
  36. ELECTRON_RBE_JWT: ${{ secrets.ELECTRON_RBE_JWT }}
  37. ELECTRON_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  38. jobs:
  39. test:
  40. runs-on: ${{ inputs.test-runs-on }}
  41. container: ${{ fromJSON(inputs.test-container) }}
  42. strategy:
  43. fail-fast: false
  44. matrix:
  45. build-type: ${{ inputs.target-platform == 'macos' && fromJSON('["darwin","mas"]') || fromJSON('["linux"]') }}
  46. shard: ${{ inputs.target-platform == 'macos' && fromJSON('[1, 2]') || fromJSON('[1, 2, 3]') }}
  47. env:
  48. BUILD_TYPE: ${{ matrix.build-type }}
  49. TARGET_ARCH: ${{ inputs.target-arch }}
  50. ARTIFACT_KEY: ${{ matrix.build-type }}_${{ inputs.target-arch }}
  51. steps:
  52. - name: Fix node20 on arm32 runners
  53. if: ${{ inputs.target-arch == 'arm' }}
  54. run: |
  55. cp $(which node) /mnt/runner-externals/node20/bin/
  56. - name: Add TCC permissions on macOS
  57. if: ${{ inputs.target-platform == 'macos' }}
  58. run: |
  59. configure_user_tccdb () {
  60. local values=$1
  61. local dbPath="$HOME/Library/Application Support/com.apple.TCC/TCC.db"
  62. local sqlQuery="INSERT OR REPLACE INTO access VALUES($values);"
  63. sqlite3 "$dbPath" "$sqlQuery"
  64. }
  65. configure_sys_tccdb () {
  66. local values=$1
  67. local dbPath="/Library/Application Support/com.apple.TCC/TCC.db"
  68. local sqlQuery="INSERT OR REPLACE INTO access VALUES($values);"
  69. sudo sqlite3 "$dbPath" "$sqlQuery"
  70. }
  71. userValuesArray=(
  72. "'kTCCServiceMicrophone','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159"
  73. "'kTCCServiceCamera','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159"
  74. "'kTCCServiceBluetoothAlways','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159"
  75. )
  76. for values in "${userValuesArray[@]}"; do
  77. # Sonoma and higher have a few extra values
  78. # Ref: https://github.com/actions/runner-images/blob/main/images/macos/scripts/build/configure-tccdb-macos.sh
  79. if [ "$OSTYPE" = "darwin23" ]; then
  80. configure_user_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
  81. configure_sys_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
  82. else
  83. configure_user_tccdb "$values"
  84. configure_sys_tccdb "$values"
  85. fi
  86. done
  87. - name: Checkout Electron
  88. uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
  89. with:
  90. path: src/electron
  91. fetch-depth: 0
  92. - name: Install Dependencies
  93. run: |
  94. cd src/electron
  95. node script/yarn install --frozen-lockfile
  96. - name: Get Depot Tools
  97. timeout-minutes: 5
  98. run: |
  99. git clone --filter=tree:0 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  100. # Ensure depot_tools does not update.
  101. test -d depot_tools && cd depot_tools
  102. if [ "`uname`" = "Darwin" ]; then
  103. # remove ninjalog_uploader_wrapper.py from autoninja since we don't use it and it causes problems
  104. sed -i '' '/ninjalog_uploader_wrapper.py/d' ./autoninja
  105. else
  106. sed -i '/ninjalog_uploader_wrapper.py/d' ./autoninja
  107. # Remove swift-format dep from cipd on macOS until we send a patch upstream.
  108. git apply --3way ../src/electron/.github/workflows/config/gclient.diff
  109. fi
  110. touch .disable_auto_update
  111. - name: Add Depot Tools to PATH
  112. run: echo "$(pwd)/depot_tools" >> $GITHUB_PATH
  113. - name: Load ASan specific environment variables
  114. if: ${{ inputs.is-asan == true }}
  115. run: |
  116. echo "ARTIFACT_KEY=${{ matrix.build-type }}_${{ inputs.target-arch }}_asan" >> $GITHUB_ENV
  117. echo "DISABLE_CRASH_REPORTER_TESTS=true" >> $GITHUB_ENV
  118. echo "IS_ASAN=true" >> $GITHUB_ENV
  119. - name: Download Generated Artifacts
  120. uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
  121. with:
  122. name: generated_artifacts_${{ env.ARTIFACT_KEY }}
  123. path: ./generated_artifacts_${{ matrix.build-type }}_${{ inputs.target-arch }}
  124. - name: Download Src Artifacts
  125. uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
  126. with:
  127. name: src_artifacts_${{ env.ARTIFACT_KEY }}
  128. path: ./src_artifacts_${{ matrix.build-type }}_${{ inputs.target-arch }}
  129. - name: Restore Generated Artifacts
  130. run: ./src/electron/script/actions/restore-artifacts.sh
  131. - name: Unzip Dist, Mksnapshot & Chromedriver
  132. run: |
  133. cd src/out/Default
  134. unzip -:o dist.zip
  135. unzip -:o chromedriver.zip
  136. unzip -:o mksnapshot.zip
  137. - name: Import & Trust Self-Signed Codesigning Cert on MacOS
  138. if: ${{ inputs.target-platform == 'macos' && inputs.target-arch == 'x64' }}
  139. run: |
  140. sudo security authorizationdb write com.apple.trust-settings.admin allow
  141. cd src/electron
  142. ./script/codesign/generate-identity.sh
  143. - name: Run Electron Tests
  144. shell: bash
  145. env:
  146. MOCHA_REPORTER: mocha-multi-reporters
  147. ELECTRON_TEST_RESULTS_DIR: junit
  148. MOCHA_MULTI_REPORTERS: mocha-junit-reporter, tap
  149. ELECTRON_DISABLE_SECURITY_WARNINGS: 1
  150. ELECTRON_SKIP_NATIVE_MODULE_TESTS: true
  151. DISPLAY: ':99.0'
  152. run: |
  153. cd src/electron
  154. # Get which tests are on this shard
  155. tests_files=$(node script/split-tests ${{ matrix.shard }} ${{ inputs.target-platform == 'macos' && 2 || 3 }})
  156. # Run tests
  157. if [ "`uname`" = "Darwin" ]; then
  158. echo "About to start tests"
  159. node script/yarn test --runners=main --trace-uncaught --enable-logging --files $tests_files
  160. else
  161. chown :builduser .. && chmod g+w ..
  162. chown -R :builduser . && chmod -R g+w .
  163. chmod 4755 ../out/Default/chrome-sandbox
  164. runuser -u builduser -- git config --global --add safe.directory $(pwd)
  165. if [ "${{ inputs.is-asan }}" == "true" ]; then
  166. cd ..
  167. ASAN_SYMBOLIZE="$PWD/tools/valgrind/asan/asan_symbolize.py --executable-path=$PWD/out/Default/electron"
  168. export ASAN_OPTIONS="symbolize=0 handle_abort=1"
  169. export G_SLICE=always-malloc
  170. export NSS_DISABLE_ARENA_FREE_LIST=1
  171. export NSS_DISABLE_UNLOAD=1
  172. export LLVM_SYMBOLIZER_PATH=$PWD/third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer
  173. export MOCHA_TIMEOUT=180000
  174. echo "Piping output to ASAN_SYMBOLIZE ($ASAN_SYMBOLIZE)"
  175. cd electron
  176. runuser -u builduser -- xvfb-run script/actions/run-tests.sh script/yarn test --runners=main --trace-uncaught --enable-logging --files $tests_files | $ASAN_SYMBOLIZE
  177. else
  178. runuser -u builduser -- xvfb-run script/actions/run-tests.sh script/yarn test --runners=main --trace-uncaught --enable-logging --files $tests_files
  179. fi
  180. fi
  181. - name: Upload Test Artifacts
  182. if: always() && !cancelled()
  183. uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
  184. with:
  185. name: test_artifacts_${{ env.ARTIFACT_KEY }}
  186. path: src/electron/spec/artifacts
  187. if-no-files-found: ignore
  188. - name: Wait for active SSH sessions
  189. if: always() && !cancelled()
  190. run: |
  191. while [ -f /var/.ssh-lock ]
  192. do
  193. sleep 60
  194. done