pipeline-segment-electron-build.yml 8.7 KB

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