action.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.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.9' }}
  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. # We import a special key into every action in order to key the Bazel
  67. # remote cache in a way that avoids collisions between different
  68. # runners. Anything that might change the system external to Bazel but
  69. # not be fully captured by the sand-boxing of the build should be used
  70. # as part of the key. We don't need to use the CPU target for example,
  71. # as that is captured by Bazel's configuration of each action. And the
  72. # Clang version is incorporated by our Clang toolchain setup. But we
  73. # do need to capture any differences between GitHub runner OSes that
  74. # don't impact the Bazel configuration to avoid collisions between
  75. # those.
  76. build --action_env=BAZEL_REMOTE_CACHE_KEY=github-action-${{ inputs.matrix_runner }}
  77. build ${{ inputs.remote_cache_upload }}
  78. # Set an artificially high jobs count. This flag controls the number
  79. # of concurrency Bazel itself uses, which is essential for actions
  80. # that are internally blocked on for example downloading results form
  81. # the cache above. Without setting this high, Bazel will pick a small
  82. # number based on the available host CPUs and the reality will be a
  83. # long chain of largely serialized download events with little or no
  84. # usage of the host machine. Fortunately, local actions are
  85. # *separately* gated on '--local_*_resources' that will avoid a large
  86. # jobs value overwhelming the host. There is a bug to make downloads
  87. # behave completely asynchronously and remove the need for this filed
  88. # back in 2018 but work seemed to not finish:
  89. # https://github.com/bazelbuild/bazel/issues/6394
  90. #
  91. # There is a new effort (yay!) but until then it seems worth using the
  92. # workaround of a high jobs value. The biggest downside (increased
  93. # heap usage) seems like it isn't currently a big loss for our builds.
  94. #
  95. # Higher values like 50 have led to CI failures with network errors
  96. # and IOExceptions, see
  97. # https://discord.com/channels/655572317891461132/707150492370862090/1151605725576056934
  98. build --jobs=32
  99. # Avoid any cache impact from build stamping in CI.
  100. build --nostamp
  101. # General build options.
  102. build --verbose_failures
  103. test --test_output=errors
  104. EOF
  105. ./scripts/run_bazel.py info
  106. - name: Run bazel to sync deps with retry
  107. shell: bash
  108. run: |
  109. # GitHub sometimes has a high failure rate for Bazel's downloads (even
  110. # from GitHub URLs). Bazel exits with `1` on HTTP errors, which is hard
  111. # to distinguish from a normal, permanent error.
  112. #
  113. # This workaround runs fast commands that should always pass (although
  114. # they may be broken by an invalid PR). All errors are retried. The hope
  115. # is that this caches necessary downloads, allowing later commands to
  116. # more reliably succeed without retrying "permanent" errors.
  117. #
  118. # Disable lockfile updates, because some actions want to see
  119. # differences.
  120. ./scripts/run_bazel.py --attempts=5 --retry-all-errors \
  121. mod --lockfile_mode=off deps
  122. ./scripts/run_bazel.py --attempts=5 --retry-all-errors \
  123. cquery --lockfile_mode=off //... | wc -l