action.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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: Test setup
  5. inputs:
  6. matrix_runner:
  7. required: true
  8. base_sha:
  9. required: true
  10. remote_cache_key:
  11. required: true
  12. targets_file:
  13. required: true
  14. outputs:
  15. has_code:
  16. value: ${{ steps.filter.outputs.has_code}}
  17. runs:
  18. using: composite
  19. steps:
  20. # Tests should only run on applicable paths, but we still need to have an
  21. # action run for the merge queue. We filter steps based on the paths here,
  22. # and condition steps on the output.
  23. - id: filter
  24. uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
  25. with:
  26. filters: |
  27. has_code:
  28. - '!{**/*.md,LICENSE,CODEOWNERS,.git*}'
  29. # Disable uploads when the remote cache is read-only.
  30. - name: Set up remote cache access (read-only)
  31. if:
  32. steps.filter.outputs.has_code == 'true' && github.event_name ==
  33. 'pull_request'
  34. shell: bash
  35. run: |
  36. echo "remote_cache_upload=--remote_upload_local_results=false" \
  37. >> $GITHUB_ENV
  38. # Provide a cache key when the remote cache is read-write.
  39. - name: Set up remote cache access (read-write)
  40. if:
  41. steps.filter.outputs.has_code == 'true' && github.event_name !=
  42. 'pull_request'
  43. shell: bash
  44. env:
  45. REMOTE_CACHE_KEY: ${{ inputs.remote_cache_key }}
  46. run: |
  47. echo "$REMOTE_CACHE_KEY" | base64 -d > $HOME/remote_cache_key.json
  48. echo "remote_cache_upload=--google_credentials=$HOME/remote_cache_key.json" \
  49. >> $GITHUB_ENV
  50. - uses: ./.github/actions/build-setup-common
  51. if: steps.filter.outputs.has_code == 'true'
  52. with:
  53. matrix_runner: ${{ inputs.matrix_runner }}
  54. remote_cache_upload: ${{ env.remote_cache_upload }}
  55. # Just for visibility, print space before and after the build.
  56. - name: Disk space before build
  57. if: steps.filter.outputs.has_code == 'true'
  58. shell: bash
  59. run: df -h
  60. - name: Verify MODULE.bazel.lock
  61. if: steps.filter.outputs.has_code == 'true'
  62. shell: bash
  63. run: |
  64. exit_code=0
  65. ./scripts/run_bazel.py \
  66. --attempts=5 \
  67. mod deps --lockfile_mode=error || exit_code=$?
  68. if (( $exit_code != 0 )); then
  69. ./scripts/run_bazel.py \
  70. --attempts=5 \
  71. mod deps --lockfile_mode=update
  72. echo "MODULE.bazel.lock is out of date! Use below file for update."
  73. echo "Platforms may require merging output, for example by applying"
  74. echo "an update, re-running triggers, and applying the next update."
  75. echo "============================================================"
  76. cat MODULE.bazel.lock
  77. echo "============================================================"
  78. exit 1
  79. fi
  80. # Build and run all targets on branch pushes to ensure we always have a
  81. # clean tree. We don't expect this to be an interactive path and so don't
  82. # optimize the latency of this step.
  83. - name: Compute impacted pull request targets (for push)
  84. if: steps.filter.outputs.has_code == 'true' && github.event_name == 'push'
  85. shell: bash
  86. env:
  87. TARGETS_FILE: ${{ inputs.targets_file }}
  88. run: |
  89. echo "//..." >$TARGETS_FILE
  90. # Compute the set of possible rules impacted by this change using
  91. # Bazel-based diffing. This lets PRs and the merge queue have a much more
  92. # efficient test CI action by avoiding even enumerating (and downloading)
  93. # all of the unaffected Bazel targets.
  94. - name: Compute impacted pull request targets
  95. if: steps.filter.outputs.has_code == 'true' && github.event_name != 'push'
  96. shell: bash
  97. env:
  98. # Compute the base SHA from the different event structures.
  99. GIT_BASE_SHA: ${{ inputs.base_sha }}
  100. TARGETS_FILE: ${{ inputs.targets_file }}
  101. run: |
  102. # First fetch the relevant base into the git repository.
  103. git fetch --depth=1 origin $GIT_BASE_SHA
  104. # Do a retried query to try to download things for target-determinator.
  105. ./scripts/run_bazel.py --attempts=5 cquery //... > /dev/null
  106. # Then use `target-determinator` as wrapped by our script.
  107. ./scripts/target_determinator.py $GIT_BASE_SHA >$TARGETS_FILE
  108. # Bazel requires a test target to run the test command. There may be
  109. # no targets or there may only be non-test targets that we want to
  110. # build, so simply inject an explicit no-op test target.
  111. echo "//scripts:no_op_test" >> $TARGETS_FILE