pipeline-segment-electron-test.yml 11 KB

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