pipeline-segment-electron-build.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. name: Pipeline Segment - Electron Build
  2. on:
  3. workflow_call:
  4. inputs:
  5. environment:
  6. description: using the production or testing environment
  7. required: false
  8. type: string
  9. target-platform:
  10. type: string
  11. description: 'Platform to run on, can be macos or linux'
  12. required: true
  13. target-arch:
  14. type: string
  15. description: 'Arch to build for, can be x64, arm64 or arm'
  16. required: true
  17. target-variant:
  18. type: string
  19. description: 'Variant to build for, no effect on non-macOS target platforms. Can be darwin, mas or all.'
  20. default: all
  21. build-runs-on:
  22. type: string
  23. description: 'What host to run the build'
  24. required: true
  25. build-container:
  26. type: string
  27. description: 'JSON container information for aks runs-on'
  28. required: false
  29. default: '{"image":null}'
  30. is-release:
  31. description: 'Whether this build job is a release job'
  32. required: true
  33. type: boolean
  34. default: false
  35. gn-build-type:
  36. description: 'The gn build type - testing or release'
  37. required: true
  38. type: string
  39. default: testing
  40. generate-symbols:
  41. description: 'Whether or not to generate symbols'
  42. required: true
  43. type: boolean
  44. default: false
  45. upload-to-storage:
  46. description: 'Whether or not to upload build artifacts to external storage'
  47. required: true
  48. type: string
  49. default: '0'
  50. strip-binaries:
  51. description: 'Strip the binaries before release (Linux only)'
  52. required: false
  53. type: boolean
  54. default: false
  55. is-asan:
  56. description: 'Building the Address Sanitizer (ASan) Linux build'
  57. required: false
  58. type: boolean
  59. default: false
  60. concurrency:
  61. group: electron-build-${{ inputs.target-platform }}-${{ inputs.target-arch }}-${{ inputs.target-variant }}-${{ inputs.is-asan }}-${{ github.ref }}
  62. cancel-in-progress: ${{ github.ref != 'refs/heads/main' && !endsWith(github.ref, '-x-y') }}
  63. env:
  64. ELECTRON_ARTIFACTS_BLOB_STORAGE: ${{ secrets.ELECTRON_ARTIFACTS_BLOB_STORAGE }}
  65. ELECTRON_RBE_JWT: ${{ secrets.ELECTRON_RBE_JWT }}
  66. SUDOWOODO_EXCHANGE_URL: ${{ secrets.SUDOWOODO_EXCHANGE_URL }}
  67. SUDOWOODO_EXCHANGE_TOKEN: ${{ secrets.SUDOWOODO_EXCHANGE_TOKEN }}
  68. GCLIENT_EXTRA_ARGS: ${{ inputs.target-platform == 'macos' && '--custom-var=checkout_mac=True --custom-var=host_os=mac' || '--custom-var=checkout_arm=True --custom-var=checkout_arm64=True' }}
  69. ELECTRON_OUT_DIR: Default
  70. jobs:
  71. build:
  72. runs-on: ${{ inputs.build-runs-on }}
  73. container: ${{ fromJSON(inputs.build-container) }}
  74. environment: ${{ inputs.environment }}
  75. env:
  76. TARGET_ARCH: ${{ inputs.target-arch }}
  77. steps:
  78. - name: Create src dir
  79. run: mkdir src
  80. - name: Checkout Electron
  81. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  82. with:
  83. path: src/electron
  84. fetch-depth: 0
  85. - name: Free up space (macOS)
  86. if: ${{ inputs.target-platform == 'macos' }}
  87. uses: ./src/electron/.github/actions/free-space-macos
  88. - name: Check disk space after freeing up space
  89. if: ${{ inputs.target-platform == 'macos' }}
  90. run: df -h
  91. - name: Setup Node.js/npm
  92. if: ${{ inputs.target-platform == 'macos' }}
  93. uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
  94. with:
  95. node-version: 20.11.x
  96. cache: yarn
  97. cache-dependency-path: src/electron/yarn.lock
  98. - name: Install Dependencies
  99. run: |
  100. cd src/electron
  101. node script/yarn install --frozen-lockfile
  102. - name: Install AZCopy
  103. if: ${{ inputs.target-platform == 'macos' }}
  104. run: brew install azcopy
  105. - name: Set GN_EXTRA_ARGS for Linux
  106. if: ${{ inputs.target-platform == 'linux' }}
  107. run: |
  108. if [ "${{ inputs.target-arch }}" = "arm" ]; then
  109. if [ "${{ inputs.is-release }}" = true ]; then
  110. GN_EXTRA_ARGS='target_cpu="arm" build_tflite_with_xnnpack=false symbol_level=1'
  111. else
  112. GN_EXTRA_ARGS='target_cpu="arm" build_tflite_with_xnnpack=false'
  113. fi
  114. elif [ "${{ inputs.target-arch }}" = "arm64" ]; then
  115. GN_EXTRA_ARGS='target_cpu="arm64" fatal_linker_warnings=false enable_linux_installer=false'
  116. elif [ "${{ inputs.is-asan }}" = true ]; then
  117. GN_EXTRA_ARGS='is_asan=true'
  118. fi
  119. echo "GN_EXTRA_ARGS=$GN_EXTRA_ARGS" >> $GITHUB_ENV
  120. - name: Get Depot Tools
  121. timeout-minutes: 5
  122. run: |
  123. git clone --filter=tree:0 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  124. SEDOPTION="-i"
  125. if [ "`uname`" = "Darwin" ]; then
  126. SEDOPTION="-i ''"
  127. fi
  128. # remove ninjalog_uploader_wrapper.py from autoninja since we don't use it and it causes problems
  129. sed $SEDOPTION '/ninjalog_uploader_wrapper.py/d' ./depot_tools/autoninja
  130. # Ensure depot_tools does not update.
  131. test -d depot_tools && cd depot_tools
  132. if [ "`uname`" = "Linux" ]; then
  133. git apply --3way ../src/electron/.github/workflows/config/gclient.diff
  134. fi
  135. touch .disable_auto_update
  136. - name: Add Depot Tools to PATH
  137. run: echo "$(pwd)/depot_tools" >> $GITHUB_PATH
  138. - name: Generate DEPS Hash
  139. run: |
  140. node src/electron/script/generate-deps-hash.js && cat src/electron/.depshash-target
  141. DEPSHASH=v1-src-cache-$(shasum src/electron/.depshash | cut -f1 -d' ')
  142. echo "DEPSHASH=$DEPSHASH" >> $GITHUB_ENV
  143. echo "CACHE_PATH=$DEPSHASH.tar" >> $GITHUB_ENV
  144. - name: Restore src cache via AZCopy
  145. if: ${{ inputs.target-platform == 'macos' }}
  146. uses: ./src/electron/.github/actions/restore-cache-azcopy
  147. - name: Restore src cache via AKS
  148. if: ${{ inputs.target-platform == 'linux' }}
  149. uses: ./src/electron/.github/actions/restore-cache-aks
  150. - name: Checkout Electron
  151. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  152. with:
  153. path: src/electron
  154. fetch-depth: 0
  155. - name: Install Build Tools
  156. uses: ./src/electron/.github/actions/install-build-tools
  157. - name: Init Build Tools
  158. run: |
  159. e init -f --root=$(pwd) --out=Default ${{ inputs.gn-build-type }} --import ${{ inputs.gn-build-type }} --target-cpu ${{ inputs.target-arch }}
  160. - name: Run Electron Only Hooks
  161. run: |
  162. gclient runhooks --spec="solutions=[{'name':'src/electron','url':None,'deps_file':'DEPS','custom_vars':{'process_deps':False},'managed':False}]"
  163. - name: Regenerate DEPS Hash
  164. run: |
  165. (cd src/electron && git checkout .) && node src/electron/script/generate-deps-hash.js && cat src/electron/.depshash-target
  166. echo "DEPSHASH=$(shasum src/electron/.depshash | cut -f1 -d' ')" >> $GITHUB_ENV
  167. - name: Add CHROMIUM_BUILDTOOLS_PATH to env
  168. run: echo "CHROMIUM_BUILDTOOLS_PATH=$(pwd)/src/buildtools" >> $GITHUB_ENV
  169. - name: Fix Sync (macOS)
  170. if: ${{ inputs.target-platform == 'macos' }}
  171. uses: ./src/electron/.github/actions/fix-sync-macos
  172. - name: Setup Number of Ninja Processes
  173. run: |
  174. echo "NUMBER_OF_NINJA_PROCESSES=${{ inputs.target-platform == 'linux' && '300' || '200' }}" >> $GITHUB_ENV
  175. - name: Free up space (macOS)
  176. if: ${{ inputs.target-platform == 'macos' }}
  177. uses: ./src/electron/.github/actions/free-space-macos
  178. - name: Build Electron
  179. if: ${{ inputs.target-platform != 'macos' || (inputs.target-variant == 'all' || inputs.target-variant == 'darwin') }}
  180. uses: ./src/electron/.github/actions/build-electron
  181. with:
  182. target-arch: ${{ inputs.target-arch }}
  183. target-platform: ${{ inputs.target-platform }}
  184. artifact-platform: ${{ inputs.target-platform == 'linux' && 'linux' || 'darwin' }}
  185. is-release: '${{ inputs.is-release }}'
  186. generate-symbols: '${{ inputs.generate-symbols }}'
  187. strip-binaries: '${{ inputs.strip-binaries }}'
  188. upload-to-storage: '${{ inputs.upload-to-storage }}'
  189. is-asan: '${{ inputs.is-asan }}'
  190. - name: Set GN_EXTRA_ARGS for MAS Build
  191. if: ${{ inputs.target-platform == 'macos' && (inputs.target-variant == 'all' || inputs.target-variant == 'mas') }}
  192. run: |
  193. echo "MAS_BUILD=true" >> $GITHUB_ENV
  194. GN_EXTRA_ARGS='is_mas_build=true'
  195. echo "GN_EXTRA_ARGS=$GN_EXTRA_ARGS" >> $GITHUB_ENV
  196. - name: Build Electron (MAS)
  197. if: ${{ inputs.target-platform == 'macos' && (inputs.target-variant == 'all' || inputs.target-variant == 'mas') }}
  198. uses: ./src/electron/.github/actions/build-electron
  199. with:
  200. target-arch: ${{ inputs.target-arch }}
  201. target-platform: ${{ inputs.target-platform }}
  202. artifact-platform: 'mas'
  203. is-release: '${{ inputs.is-release }}'
  204. generate-symbols: '${{ inputs.generate-symbols }}'
  205. upload-to-storage: '${{ inputs.upload-to-storage }}'
  206. step-suffix: '(mas)'