generate-gitlab-ci-yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. main() {
  5. local template="${1}"
  6. preamble "${template}"
  7. gen_basics
  8. gen_defconfigs
  9. gen_tests
  10. }
  11. preamble() {
  12. local template="${1}"
  13. cat - "${template}" <<-_EOF_
  14. # This file is generated; do not edit!
  15. # Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines
  16. image: ${CI_JOB_IMAGE}
  17. _EOF_
  18. }
  19. gen_basics() {
  20. local tst
  21. # Skip basic tests when explicitly building defconfigs or runtime tests
  22. case "${CI_COMMIT_REF_NAME}" in
  23. (*-defconfigs) return;;
  24. (*-*_defconfig) return;;
  25. (*-runtime-tests) return;;
  26. (*-tests.*) return;;
  27. esac
  28. for tst in DEVELOPERS flake8 package; do
  29. printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
  30. done
  31. }
  32. gen_defconfigs() {
  33. local -a defconfigs
  34. local template cfg ext
  35. defconfigs=( $(cd configs; LC_ALL=C ls -1 *_defconfig) )
  36. if [ -n "${CI_COMMIT_TAG}" ]; then
  37. # For tags, create a pipeline.
  38. template=base
  39. elif [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  40. # For pipeline created by using a trigger token.
  41. template=base
  42. else
  43. case "${CI_COMMIT_REF_NAME}" in
  44. # For master, next, and maintenance branches, only check the defconfigs
  45. (master|next|????.??.x)
  46. template=check
  47. ext=_check
  48. ;;
  49. # For the branch or tag name named *-defconfigs, create a pipeline.
  50. (*-defconfigs)
  51. template=base
  52. ;;
  53. (*-*_defconfig)
  54. defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
  55. template=base
  56. ;;
  57. esac
  58. fi
  59. if [ -n "${template}" ]; then
  60. for cfg in "${defconfigs[@]}"; do
  61. printf '%s%s: { extends: .defconfig_%s }\n' \
  62. "${cfg}" "${ext}" "${template}"
  63. done
  64. fi
  65. }
  66. gen_tests() {
  67. local -a tests
  68. local run_tests tst
  69. tests=( $(./support/testing/run-tests -l 2>&1 \
  70. | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/'\
  71. | LC_ALL=C sort)
  72. )
  73. run_tests=false
  74. if [ -n "${CI_COMMIT_TAG}" ]; then
  75. # For tags, create a pipeline.
  76. run_tests=true
  77. elif [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  78. # For pipeline created by using a trigger token.
  79. run_tests=true
  80. else
  81. case "${CI_COMMIT_REF_NAME}" in
  82. # For the branch or tag name named *-runtime-tests, create a pipeline.
  83. (*-runtime-tests)
  84. run_tests=true
  85. ;;
  86. (*-tests.*)
  87. tests=( "${CI_COMMIT_REF_NAME##*-}" )
  88. run_tests=true
  89. ;;
  90. esac
  91. fi
  92. if ${run_tests}; then
  93. printf '%s: { extends: .runtime_test_base }\n' "${tests[@]}"
  94. fi
  95. }
  96. main "${@}"