action.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. name: Setup build environment (macOS)
  5. inputs:
  6. matrix_runner:
  7. required: true
  8. remote_cache_upload:
  9. required: true
  10. runs:
  11. using: composite
  12. steps:
  13. # Setup Python and related tools.
  14. - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
  15. with:
  16. # Match the min version listed in docs/project/contribution_tools.md
  17. # or the oldest version available on the OS.
  18. python-version:
  19. ${{ inputs.matrix_runner == 'macos-14' && '3.11' || '3.10' }}
  20. - uses: ./.github/actions/build-setup-macos
  21. if: startsWith(inputs.matrix_runner, 'macos')
  22. with:
  23. matrix_runner: ${{ inputs.matrix_runner }}
  24. - uses: ./.github/actions/build-setup-ubuntu
  25. if: startsWith(inputs.matrix_runner, 'ubuntu')
  26. # Print the various tool paths and versions to help in debugging.
  27. - name: Print tool debugging info
  28. shell: bash
  29. run: |
  30. echo '*** PATH'
  31. echo $PATH
  32. echo '*** bazelisk'
  33. which bazelisk
  34. bazelisk --version
  35. echo '*** run_bazel.py'
  36. ./scripts/run_bazel.py --version
  37. echo '*** python'
  38. which python
  39. python --version
  40. echo '*** clang'
  41. which clang
  42. clang --version
  43. echo '*** clang++'
  44. which clang++
  45. clang++ --version
  46. echo '*** clang-tidy'
  47. which clang-tidy
  48. clang-tidy --version
  49. # Add our bazel configuration and print basic info to ease debugging.
  50. - name: Configure Bazel and print info
  51. env:
  52. # Add a cache version for changes that bazel won't otherwise detect,
  53. # like llvm version changes.
  54. CACHE_VERSION: 1
  55. shell: bash
  56. run: |
  57. cat >user.bazelrc <<EOF
  58. # Disable the local disk cache as we use a remote cache and don't want
  59. # two copies of every output taking up disk space. The only way to
  60. # disable the disk cache is with an empty string:
  61. # https://github.com/bazelbuild/bazel/issues/5308
  62. build --disk_cache=
  63. # Enable remote cache for our CI but minimize downloads.
  64. build --remote_cache=https://storage.googleapis.com/carbon-builds-github-v${CACHE_VERSION}
  65. build --remote_download_outputs=minimal
  66. # Allow passing targets that are incompatible so that our explicit
  67. # target lists work more like //... wild card patterns in CI. In CI,
  68. # we're using explicit target lists to prune to a minimal set of
  69. # dependencies, and so skipping incompatible targets is the expected
  70. # behavior.
  71. build --skip_incompatible_explicit_targets
  72. # We import a special key into every action in order to key the Bazel
  73. # remote cache in a way that avoids collisions between different
  74. # runners. Anything that might change the system external to Bazel but
  75. # not be fully captured by the sand-boxing of the build should be used
  76. # as part of the key. We don't need to use the CPU target for example,
  77. # as that is captured by Bazel's configuration of each action. And the
  78. # Clang version is incorporated by our Clang toolchain setup. But we
  79. # do need to capture any differences between GitHub runner OSes that
  80. # don't impact the Bazel configuration to avoid collisions between
  81. # those.
  82. build --action_env=BAZEL_REMOTE_CACHE_KEY=github-action-${{ inputs.matrix_runner }}
  83. build ${{ inputs.remote_cache_upload }}
  84. # Set an artificially high jobs count. This flag controls the number
  85. # of concurrency Bazel itself uses, which is essential for actions
  86. # that are internally blocked on for example downloading results form
  87. # the cache above. Without setting this high, Bazel will pick a small
  88. # number based on the available host CPUs and the reality will be a
  89. # long chain of largely serialized download events with little or no
  90. # usage of the host machine. Fortunately, local actions are
  91. # *separately* gated on '--local_*_resources' that will avoid a large
  92. # jobs value overwhelming the host. There is a bug to make downloads
  93. # behave completely asynchronously and remove the need for this filed
  94. # back in 2018 but work seemed to not finish:
  95. # https://github.com/bazelbuild/bazel/issues/6394
  96. #
  97. # There is a new effort (yay!) but until then it seems worth using the
  98. # workaround of a high jobs value. The biggest downside (increased
  99. # heap usage) seems like it isn't currently a big loss for our builds.
  100. #
  101. # Higher values like 50 have led to CI failures with network errors
  102. # and IOExceptions, see
  103. # https://discord.com/channels/655572317891461132/707150492370862090/1151605725576056934
  104. build --jobs=32
  105. # Avoid any cache impact from build stamping in CI.
  106. build --nostamp
  107. # General build options.
  108. build --verbose_failures
  109. test --test_output=errors
  110. EOF
  111. ./scripts/run_bazel.py info
  112. - name: Run bazel to sync deps with retry
  113. shell: bash
  114. run: |
  115. # GitHub sometimes has a high failure rate for Bazel's downloads (even
  116. # from GitHub URLs). Bazel exits with `1` on HTTP errors, which is hard
  117. # to distinguish from a normal, permanent error.
  118. #
  119. # This workaround runs fast commands that should always pass (although
  120. # they may be broken by an invalid PR). All errors are retried. The hope
  121. # is that this caches necessary downloads, allowing later commands to
  122. # more reliably succeed without retrying "permanent" errors.
  123. #
  124. # Disable lockfile updates, because some actions want to see
  125. # differences.
  126. ./scripts/run_bazel.py --attempts=5 --retry-all-errors \
  127. mod --lockfile_mode=off deps
  128. ./scripts/run_bazel.py --attempts=5 --retry-all-errors \
  129. cquery --lockfile_mode=off //... | wc -l