pipeline-segment-electron-test.yml 9.0 KB

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