buildkite-solana-private.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/usr/bin/env bash
  2. #
  3. # Builds a buildkite pipeline based on the environment variables
  4. #
  5. set -e
  6. cd "$(dirname "$0")"/..
  7. output_file=${1:-/dev/stderr}
  8. if [[ -n $CI_PULL_REQUEST ]]; then
  9. # filter pr number from ci branch.
  10. [[ $CI_BRANCH =~ pull/([0-9]+)/head ]]
  11. pr_number=${BASH_REMATCH[1]}
  12. echo "get affected files from PR: $pr_number"
  13. # get affected files
  14. readarray -t affected_files < <(gh pr diff --name-only "$pr_number")
  15. if [[ ${#affected_files[*]} -eq 0 ]]; then
  16. echo "Unable to determine the files affected by this PR"
  17. exit 1
  18. fi
  19. else
  20. affected_files=()
  21. fi
  22. annotate() {
  23. if [[ -n $BUILDKITE ]]; then
  24. buildkite-agent annotate "$@"
  25. fi
  26. }
  27. # Checks if a CI pull request affects one or more path patterns. Each
  28. # pattern argument is checked in series. If one of them found to be affected,
  29. # return immediately as such.
  30. #
  31. # Bash regular expressions are permitted in the pattern:
  32. # affects .rs$ -- any file or directory ending in .rs
  33. # affects .rs -- also matches foo.rs.bar
  34. # affects ^snap/ -- anything under the snap/ subdirectory
  35. # affects snap/ -- also matches foo/snap/
  36. # Any pattern starting with the ! character will be negated:
  37. # affects !^docs/ -- anything *not* under the docs/ subdirectory
  38. #
  39. affects() {
  40. if [[ -z $CI_PULL_REQUEST ]]; then
  41. # affected_files metadata is not currently available for non-PR builds so assume
  42. # the worse (affected)
  43. return 0
  44. fi
  45. # Assume everything needs to be tested when any Dockerfile changes
  46. for pattern in ^ci/docker-rust/Dockerfile ^ci/docker-rust-nightly/Dockerfile "$@"; do
  47. if [[ ${pattern:0:1} = "!" ]]; then
  48. for file in "${affected_files[@]}"; do
  49. if [[ ! $file =~ ${pattern:1} ]]; then
  50. return 0 # affected
  51. fi
  52. done
  53. else
  54. for file in "${affected_files[@]}"; do
  55. if [[ $file =~ $pattern ]]; then
  56. return 0 # affected
  57. fi
  58. done
  59. fi
  60. done
  61. return 1 # not affected
  62. }
  63. # Checks if a CI pull request affects anything other than the provided path patterns
  64. #
  65. # Syntax is the same as `affects()` except that the negation prefix is not
  66. # supported
  67. #
  68. affects_other_than() {
  69. if [[ -z $CI_PULL_REQUEST ]]; then
  70. # affected_files metadata is not currently available for non-PR builds so assume
  71. # the worse (affected)
  72. return 0
  73. fi
  74. for file in "${affected_files[@]}"; do
  75. declare matched=false
  76. for pattern in "$@"; do
  77. if [[ $file =~ $pattern ]]; then
  78. matched=true
  79. fi
  80. done
  81. if ! $matched; then
  82. return 0 # affected
  83. fi
  84. done
  85. return 1 # not affected
  86. }
  87. start_pipeline() {
  88. echo "# $*" > "$output_file"
  89. echo "steps:" >> "$output_file"
  90. }
  91. command_step() {
  92. cat >> "$output_file" <<EOF
  93. - name: "$1"
  94. command: "$2"
  95. timeout_in_minutes: $3
  96. artifact_paths: "log-*.txt"
  97. agents:
  98. queue: "default"
  99. EOF
  100. }
  101. # trigger_secondary_step() {
  102. # cat >> "$output_file" <<"EOF"
  103. # - name: "Trigger Build on solana-secondary"
  104. # trigger: "solana-secondary"
  105. # branches: "!pull/*"
  106. # async: true
  107. # build:
  108. # message: "${BUILDKITE_MESSAGE}"
  109. # commit: "${BUILDKITE_COMMIT}"
  110. # branch: "${BUILDKITE_BRANCH}"
  111. # env:
  112. # TRIGGERED_BUILDKITE_TAG: "${BUILDKITE_TAG}"
  113. # EOF
  114. # }
  115. wait_step() {
  116. echo " - wait" >> "$output_file"
  117. }
  118. all_test_steps() {
  119. command_step checks "ci/docker-run-default-image.sh ci/test-checks.sh" 20
  120. wait_step
  121. # Full test suite
  122. .buildkite/scripts/build-stable.sh default >> "$output_file"
  123. # Docs tests
  124. if affects \
  125. .rs$ \
  126. ^ci/rust-version.sh \
  127. ^ci/test-docs.sh \
  128. ; then
  129. command_step doctest "ci/docker-run-default-image.sh ci/test-docs.sh" 15
  130. else
  131. annotate --style info --context test-docs \
  132. "Docs skipped as no .rs files were modified"
  133. fi
  134. wait_step
  135. # SBF test suite
  136. if affects \
  137. .rs$ \
  138. Cargo.lock$ \
  139. Cargo.toml$ \
  140. ^ci/rust-version.sh \
  141. ^ci/test-stable-sbf.sh \
  142. ^ci/test-stable.sh \
  143. ^ci/test-local-cluster.sh \
  144. ^core/build.rs \
  145. ^fetch-perf-libs.sh \
  146. ^platform-tools-sdk/ \
  147. ^programs/ \
  148. ; then
  149. cat >> "$output_file" <<"EOF"
  150. - command: "ci/docker-run-default-image.sh ci/test-stable-sbf.sh"
  151. name: "stable-sbf"
  152. timeout_in_minutes: 35
  153. agents:
  154. queue: "default"
  155. EOF
  156. else
  157. annotate --style info \
  158. "Stable-SBF skipped as no relevant files were modified"
  159. fi
  160. # Coverage...
  161. if affects \
  162. .rs$ \
  163. Cargo.lock$ \
  164. Cargo.toml$ \
  165. ^ci/rust-version.sh \
  166. ^ci/test-coverage.sh \
  167. ^scripts/coverage.sh \
  168. ; then
  169. command_step coverage "ci/docker-run-default-image.sh ci/test-coverage.sh" 80
  170. else
  171. annotate --style info --context test-coverage \
  172. "Coverage skipped as no .rs files were modified"
  173. fi
  174. }
  175. pull_or_push_steps() {
  176. command_step sanity "ci/test-sanity.sh" 5
  177. wait_step
  178. # Check for any .sh file changes
  179. if affects .sh$; then
  180. command_step shellcheck "ci/shellcheck.sh" 5
  181. wait_step
  182. fi
  183. # Run the full test suite by default, skipping only if modifications are local
  184. # to some particular areas of the tree
  185. if affects_other_than ^.mergify .md$ ^docs/ ^.gitbook; then
  186. all_test_steps
  187. fi
  188. # docs changes run on Github actions...
  189. }
  190. # if [[ -n $BUILDKITE_TAG ]]; then
  191. # start_pipeline "Tag pipeline for $BUILDKITE_TAG"
  192. # annotate --style info --context release-tag \
  193. # "https://github.com/solana-labs/solana/releases/$BUILDKITE_TAG"
  194. # # Jump directly to the secondary build to publish release artifacts quickly
  195. # trigger_secondary_step
  196. # exit 0
  197. # fi
  198. if [[ $BUILDKITE_BRANCH =~ ^pull ]]; then
  199. echo "+++ Affected files in this PR"
  200. for file in "${affected_files[@]}"; do
  201. echo "- $file"
  202. done
  203. start_pipeline "Pull request pipeline for $BUILDKITE_BRANCH"
  204. # Add helpful link back to the corresponding Github Pull Request
  205. annotate --style info --context pr-backlink \
  206. "Github Pull Request: https://github.com/anza-xyz/agave/$BUILDKITE_BRANCH"
  207. pull_or_push_steps
  208. exit 0
  209. fi
  210. start_pipeline "Push pipeline for ${BUILDKITE_BRANCH:-?unknown branch?}"
  211. pull_or_push_steps
  212. wait_step
  213. # trigger_secondary_step
  214. exit 0