pipeline-segment-electron-test.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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, win 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. defaults:
  40. run:
  41. shell: bash
  42. runs-on: ${{ inputs.test-runs-on }}
  43. container: ${{ fromJSON(inputs.test-container) }}
  44. strategy:
  45. fail-fast: false
  46. matrix:
  47. build-type: ${{ inputs.target-platform == 'macos' && fromJSON('["darwin","mas"]') || (inputs.target-platform == 'win' && fromJSON('["win"]') || fromJSON('["linux"]')) }}
  48. shard: ${{ inputs.target-platform == 'linux' && fromJSON('[1, 2, 3]') || fromJSON('[1, 2]') }}
  49. env:
  50. BUILD_TYPE: ${{ matrix.build-type }}
  51. TARGET_ARCH: ${{ inputs.target-arch }}
  52. ARTIFACT_KEY: ${{ matrix.build-type }}_${{ inputs.target-arch }}
  53. steps:
  54. - name: Fix node20 on arm32 runners
  55. if: ${{ inputs.target-arch == 'arm' && inputs.target-platform == 'linux' }}
  56. run: |
  57. cp $(which node) /mnt/runner-externals/node20/bin/
  58. - name: Install Git on Windows arm64 runners
  59. if: ${{ inputs.target-arch == 'arm64' && inputs.target-platform == 'win' }}
  60. shell: powershell
  61. run: |
  62. Set-ExecutionPolicy Bypass -Scope Process -Force
  63. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
  64. iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  65. choco install -y --no-progress git.install --params "'/GitAndUnixToolsOnPath'"
  66. choco install -y --no-progress git
  67. choco install -y --no-progress python --version 3.11.9
  68. choco install -y --no-progress visualstudio2022-workload-vctools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.ARM64"
  69. echo "C:\Program Files\Git\cmd" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  70. echo "C:\Program Files\Git\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  71. echo "C:\Python311" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  72. - name: Setup Node.js/npm
  73. if: ${{ inputs.target-platform == 'win' }}
  74. uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6
  75. with:
  76. node-version: 20.11.x
  77. - name: Add TCC permissions on macOS
  78. if: ${{ inputs.target-platform == 'macos' }}
  79. run: |
  80. configure_user_tccdb () {
  81. local values=$1
  82. local dbPath="$HOME/Library/Application Support/com.apple.TCC/TCC.db"
  83. local sqlQuery="INSERT OR REPLACE INTO access VALUES($values);"
  84. sqlite3 "$dbPath" "$sqlQuery"
  85. }
  86. configure_sys_tccdb () {
  87. local values=$1
  88. local dbPath="/Library/Application Support/com.apple.TCC/TCC.db"
  89. local sqlQuery="INSERT OR REPLACE INTO access VALUES($values);"
  90. sudo sqlite3 "$dbPath" "$sqlQuery"
  91. }
  92. userValuesArray=(
  93. "'kTCCServiceMicrophone','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159"
  94. "'kTCCServiceCamera','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159"
  95. "'kTCCServiceBluetoothAlways','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159"
  96. )
  97. for values in "${userValuesArray[@]}"; do
  98. # Sonoma and higher have a few extra values
  99. # Ref: https://github.com/actions/runner-images/blob/main/images/macos/scripts/build/configure-tccdb-macos.sh
  100. if [ "$OSTYPE" = "darwin23" ]; then
  101. configure_user_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
  102. configure_sys_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
  103. else
  104. configure_user_tccdb "$values"
  105. configure_sys_tccdb "$values"
  106. fi
  107. done
  108. - name: Checkout Electron
  109. uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
  110. with:
  111. path: src/electron
  112. fetch-depth: 0
  113. ref: ${{ github.event.pull_request.head.sha }}
  114. - name: Install Dependencies
  115. uses: ./src/electron/.github/actions/install-dependencies
  116. - name: Get Depot Tools
  117. timeout-minutes: 5
  118. run: |
  119. git config --global core.filemode false
  120. git config --global core.autocrlf false
  121. git config --global branch.autosetuprebase always
  122. git clone --filter=tree:0 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  123. # Ensure depot_tools does not update.
  124. test -d depot_tools && cd depot_tools
  125. touch .disable_auto_update
  126. - name: Add Depot Tools to PATH
  127. run: echo "$(pwd)/depot_tools" >> $GITHUB_PATH
  128. - name: Load ASan specific environment variables
  129. if: ${{ inputs.is-asan == true }}
  130. run: |
  131. echo "ARTIFACT_KEY=${{ matrix.build-type }}_${{ inputs.target-arch }}_asan" >> $GITHUB_ENV
  132. echo "DISABLE_CRASH_REPORTER_TESTS=true" >> $GITHUB_ENV
  133. echo "IS_ASAN=true" >> $GITHUB_ENV
  134. - name: Download Generated Artifacts
  135. uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
  136. with:
  137. name: generated_artifacts_${{ env.ARTIFACT_KEY }}
  138. path: ./generated_artifacts_${{ matrix.build-type }}_${{ inputs.target-arch }}
  139. - name: Download Src Artifacts
  140. uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
  141. with:
  142. name: src_artifacts_${{ env.ARTIFACT_KEY }}
  143. path: ./src_artifacts_${{ matrix.build-type }}_${{ inputs.target-arch }}
  144. - name: Restore Generated Artifacts
  145. run: ./src/electron/script/actions/restore-artifacts.sh
  146. - name: Unzip Dist, Mksnapshot & Chromedriver (win)
  147. if: ${{ inputs.target-platform == 'win' }}
  148. shell: powershell
  149. run: |
  150. Set-ExecutionPolicy Bypass -Scope Process -Force
  151. cd src/out/Default
  152. Expand-Archive -Force dist.zip -DestinationPath ./
  153. Expand-Archive -Force chromedriver.zip -DestinationPath ./
  154. Expand-Archive -Force mksnapshot.zip -DestinationPath ./
  155. - name: Unzip Dist, Mksnapshot & Chromedriver (unix)
  156. if: ${{ inputs.target-platform != 'win' }}
  157. run: |
  158. cd src/out/Default
  159. unzip -:o dist.zip
  160. unzip -:o chromedriver.zip
  161. unzip -:o mksnapshot.zip
  162. - name: Import & Trust Self-Signed Codesigning Cert on MacOS
  163. if: ${{ inputs.target-platform == 'macos' && inputs.target-arch == 'x64' }}
  164. run: |
  165. sudo security authorizationdb write com.apple.trust-settings.admin allow
  166. cd src/electron
  167. ./script/codesign/generate-identity.sh
  168. - name: Install Datadog CLI
  169. run: |
  170. cd src/electron
  171. node script/yarn global add @datadog/datadog-ci
  172. - name: Run Electron Tests
  173. shell: bash
  174. env:
  175. MOCHA_REPORTER: mocha-multi-reporters
  176. MOCHA_MULTI_REPORTERS: mocha-junit-reporter, tap
  177. ELECTRON_DISABLE_SECURITY_WARNINGS: 1
  178. ELECTRON_SKIP_NATIVE_MODULE_TESTS: true
  179. DISPLAY: ':99.0'
  180. NPM_CONFIG_MSVS_VERSION: '2022'
  181. run: |
  182. cd src/electron
  183. export ELECTRON_TEST_RESULTS_DIR=`pwd`/junit
  184. # Get which tests are on this shard
  185. tests_files=$(node script/split-tests ${{ matrix.shard }} ${{ inputs.target-platform == 'linux' && 3 || 2 }})
  186. # Run tests
  187. if [ "${{ inputs.target-platform }}" != "linux" ]; then
  188. echo "About to start tests"
  189. if [ "${{ inputs.target-platform }}" = "win" ]; then
  190. if [ "${{ inputs.target-arch }}" = "x86" ]; then
  191. export npm_config_arch="ia32"
  192. fi
  193. if [ "${{ inputs.target-arch }}" = "arm64" ]; then
  194. export ELECTRON_FORCE_TEST_SUITE_EXIT="true"
  195. fi
  196. fi
  197. node script/yarn test --runners=main --trace-uncaught --enable-logging --files $tests_files
  198. else
  199. chown :builduser .. && chmod g+w ..
  200. chown -R :builduser . && chmod -R g+w .
  201. chmod 4755 ../out/Default/chrome-sandbox
  202. runuser -u builduser -- git config --global --add safe.directory $(pwd)
  203. if [ "${{ inputs.is-asan }}" == "true" ]; then
  204. cd ..
  205. ASAN_SYMBOLIZE="$PWD/tools/valgrind/asan/asan_symbolize.py --executable-path=$PWD/out/Default/electron"
  206. export ASAN_OPTIONS="symbolize=0 handle_abort=1"
  207. export G_SLICE=always-malloc
  208. export NSS_DISABLE_ARENA_FREE_LIST=1
  209. export NSS_DISABLE_UNLOAD=1
  210. export LLVM_SYMBOLIZER_PATH=$PWD/third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer
  211. export MOCHA_TIMEOUT=180000
  212. echo "Piping output to ASAN_SYMBOLIZE ($ASAN_SYMBOLIZE)"
  213. cd electron
  214. runuser -u builduser -- xvfb-run script/actions/run-tests.sh script/yarn test --runners=main --trace-uncaught --enable-logging --files $tests_files | $ASAN_SYMBOLIZE
  215. else
  216. runuser -u builduser -- xvfb-run script/actions/run-tests.sh script/yarn test --runners=main --trace-uncaught --enable-logging --files $tests_files
  217. fi
  218. fi
  219. - name: Upload Test results to Datadog
  220. env:
  221. DD_ENV: ci
  222. DD_SERVICE: electron
  223. DD_API_KEY: ${{ secrets.DD_API_KEY }}
  224. DD_CIVISIBILITY_LOGS_ENABLED: true
  225. DD_TAGS: "os.architecture:${{ inputs.target-arch }},os.family:${{ inputs.target-platform }},os.platform:${{ inputs.target-platform }},asan:${{ inputs.is-asan }}"
  226. run: |
  227. if ! [ -z $DD_API_KEY ] && [ -f src/electron/junit/test-results-main.xml ]; then
  228. export DATADOG_PATH=`node src/electron/script/yarn global bin`
  229. $DATADOG_PATH/datadog-ci junit upload src/electron/junit/test-results-main.xml
  230. fi
  231. if: always() && !cancelled()
  232. - name: Wait for active SSH sessions
  233. if: always() && !cancelled()
  234. shell: bash
  235. run: |
  236. while [ -f /var/.ssh-lock ]
  237. do
  238. sleep 60
  239. done