action.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. name: 'Checkout'
  2. description: 'Checks out Electron and stores it in the AKS Cache'
  3. inputs:
  4. generate-sas-token:
  5. description: 'Whether to generate and persist a SAS token for the item in the cache'
  6. required: false
  7. default: 'false'
  8. runs:
  9. using: "composite"
  10. steps:
  11. - name: Set GIT_CACHE_PATH to make gclient to use the cache
  12. shell: bash
  13. run: |
  14. echo "GIT_CACHE_PATH=$(pwd)/git-cache" >> $GITHUB_ENV
  15. - name: Install Dependencies
  16. shell: bash
  17. run: |
  18. cd src/electron
  19. node script/yarn install --frozen-lockfile
  20. - name: Get Depot Tools
  21. shell: bash
  22. run: |
  23. git clone --depth=1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  24. sed -i '/ninjalog_uploader_wrapper.py/d' ./depot_tools/autoninja
  25. # Remove swift-format dep from cipd on macOS until we send a patch upstream.
  26. cd depot_tools
  27. git apply --3way ../src/electron/.github/workflows/config/gclient.diff
  28. # Ensure depot_tools does not update.
  29. test -d depot_tools && cd depot_tools
  30. touch .disable_auto_update
  31. - name: Add Depot Tools to PATH
  32. shell: bash
  33. run: echo "$(pwd)/depot_tools" >> $GITHUB_PATH
  34. - name: Generate DEPS Hash
  35. shell: bash
  36. run: |
  37. node src/electron/script/generate-deps-hash.js && cat src/electron/.depshash-target
  38. echo "DEPSHASH=v1-src-cache-$(shasum src/electron/.depshash | cut -f1 -d' ')" >> $GITHUB_ENV
  39. - name: Generate SAS Key
  40. if: ${{ inputs.generate-sas-token == 'true' }}
  41. shell: bash
  42. run: |
  43. curl --unix-socket /var/run/sas/sas.sock --fail "http://foo/$DEPSHASH.tar" > sas-token
  44. - name: Save SAS Key
  45. if: ${{ inputs.generate-sas-token == 'true' }}
  46. uses: actions/cache/save@v4
  47. with:
  48. path: |
  49. sas-token
  50. key: sas-key-${{ github.run_number }}-${{ github.run_attempt }}
  51. - name: Check If Cache Exists
  52. id: check-cache
  53. shell: bash
  54. run: |
  55. cache_path=/mnt/cross-instance-cache/$DEPSHASH.tar
  56. echo "Using cache key: $DEPSHASH"
  57. echo "Checking for cache in: $cache_path"
  58. if [ ! -f "$cache_path" ]; then
  59. echo "cache_exists=false" >> $GITHUB_OUTPUT
  60. echo "Cache Does Not Exist for $DEPSHASH"
  61. else
  62. echo "cache_exists=true" >> $GITHUB_OUTPUT
  63. echo "Cache Already Exists for $DEPSHASH, Skipping.."
  64. fi
  65. - name: Gclient Sync
  66. if: steps.check-cache.outputs.cache_exists == 'false'
  67. shell: bash
  68. run: |
  69. gclient config \
  70. --name "src/electron" \
  71. --unmanaged \
  72. ${GCLIENT_EXTRA_ARGS} \
  73. "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
  74. ELECTRON_USE_THREE_WAY_MERGE_FOR_PATCHES=1 gclient sync --with_branch_heads --with_tags -vvvvv
  75. if [ "${{ inputs.is-release }}" != "true" ]; then
  76. # Re-export all the patches to check if there were changes.
  77. python3 src/electron/script/export_all_patches.py src/electron/patches/config.json
  78. cd src/electron
  79. git update-index --refresh || true
  80. if ! git diff-index --quiet HEAD --; then
  81. # There are changes to the patches. Make a git commit with the updated patches
  82. git add patches
  83. GIT_COMMITTER_NAME="PatchUp" GIT_COMMITTER_EMAIL="73610968+patchup[bot]@users.noreply.github.com" git commit -m "chore: update patches" --author="PatchUp <73610968+patchup[bot]@users.noreply.github.com>"
  84. # Export it
  85. mkdir -p ../../patches
  86. git format-patch -1 --stdout --keep-subject --no-stat --full-index > ../../patches/update-patches.patch
  87. if node ./script/push-patch.js; then
  88. echo
  89. echo "======================================================================"
  90. echo "Changes to the patches when applying, we have auto-pushed the diff to the current branch"
  91. echo "A new CI job will kick off shortly"
  92. echo "======================================================================"
  93. exit 1
  94. else
  95. echo
  96. echo "======================================================================"
  97. echo "There were changes to the patches when applying."
  98. echo "Check the CI artifacts for a patch you can apply to fix it."
  99. echo "======================================================================"
  100. echo
  101. cat ../../patches/update-patches.patch
  102. exit 1
  103. fi
  104. fi
  105. fi
  106. # delete all .git directories under src/ except for
  107. # third_party/angle/ and third_party/dawn/ because of build time generation of files
  108. # gen/angle/commit.h depends on third_party/angle/.git/HEAD
  109. # https://chromium-review.googlesource.com/c/angle/angle/+/2074924
  110. # and dawn/common/Version_autogen.h depends on third_party/dawn/.git/HEAD
  111. # https://dawn-review.googlesource.com/c/dawn/+/83901
  112. # TODO: maybe better to always leave out */.git/HEAD file for all targets ?
  113. - name: Delete .git directories under src to free space
  114. if: steps.check-cache.outputs.cache_exists == 'false'
  115. shell: bash
  116. run: |
  117. cd src
  118. ( find . -type d -name ".git" -not -path "./third_party/angle/*" -not -path "./third_party/dawn/*" -not -path "./electron/*" ) | xargs rm -rf
  119. - name: Minimize Cache Size for Upload
  120. if: steps.check-cache.outputs.cache_exists == 'false'
  121. shell: bash
  122. run: |
  123. rm -rf src/android_webview
  124. rm -rf src/ios/chrome
  125. rm -rf src/third_party/blink/web_tests
  126. rm -rf src/third_party/blink/perf_tests
  127. rm -rf src/chrome/test/data/xr/webvr_info
  128. rm -rf src/third_party/angle/third_party/VK-GL-CTS/src
  129. rm -rf src/third_party/swift-toolchain
  130. rm -rf src/third_party/swiftshader/tests/regres/testlists
  131. rm -rf src/electron
  132. - name: Compress Src Directory
  133. if: steps.check-cache.outputs.cache_exists == 'false'
  134. shell: bash
  135. run: |
  136. echo "Uncompressed src size: $(du -sh src | cut -f1 -d' ')"
  137. tar -cf $DEPSHASH.tar src
  138. echo "Compressed src to $(du -sh $DEPSHASH.tar | cut -f1 -d' ')"
  139. cp ./$DEPSHASH.tar /mnt/cross-instance-cache/
  140. - name: Persist Src Cache
  141. if: steps.check-cache.outputs.cache_exists == 'false'
  142. shell: bash
  143. run: |
  144. final_cache_path=/mnt/cross-instance-cache/$DEPSHASH.tar
  145. echo "Using cache key: $DEPSHASH"
  146. echo "Checking path: $final_cache_path"
  147. if [ ! -f "$final_cache_path" ]; then
  148. echo "Cache key not found"
  149. exit 1
  150. else
  151. echo "Cache key persisted in $final_cache_path"
  152. fi