pipeline-segment-electron-test.yml 12 KB

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