generate-gitlab-ci-yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. main() {
  5. local template="${1}"
  6. preamble "${template}"
  7. gen_tests
  8. }
  9. preamble() {
  10. local template="${1}"
  11. cat - "${template}" <<-_EOF_
  12. # This file is generated; do not edit!
  13. # Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines
  14. image: ${CI_JOB_IMAGE}
  15. _EOF_
  16. }
  17. gen_tests() {
  18. local -a basics defconfigs runtimes
  19. local do_basics do_defconfigs do_runtime
  20. local defconfigs_ext cfg tst
  21. basics=( DEVELOPERS flake8 package )
  22. defconfigs=( $(cd configs; LC_ALL=C ls -1 *_defconfig) )
  23. runtimes=( $(./support/testing/run-tests -l 2>&1 \
  24. | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/' \
  25. | LC_ALL=C sort)
  26. )
  27. if [ -n "${CI_COMMIT_TAG}" ]; then
  28. # When a tag is added to the Buildroot git tree, we want
  29. # to run the runtime tests and only test Qemu defconfigs.
  30. defconfigs=( $(cd configs; LC_ALL=C ls -1 qemu_*_defconfig) )
  31. do_basics=true
  32. do_defconfigs=base
  33. do_runtime=true
  34. elif [ "${CI_PIPELINE_SOURCE}" = "trigger" ]; then
  35. case "${BR_SCHEDULE_JOBS}" in
  36. (basic)
  37. do_basics=true
  38. do_defconfigs=check
  39. defconfigs_ext=_check
  40. ;;
  41. (defconfig)
  42. do_defconfigs=base
  43. ;;
  44. (runtime)
  45. do_runtime=true
  46. ;;
  47. esac
  48. else
  49. case "${CI_COMMIT_REF_NAME}" in
  50. (*-basics)
  51. do_basics=true
  52. do_defconfigs=check
  53. defconfigs_ext=_check
  54. ;;
  55. (*-defconfigs)
  56. do_defconfigs=base
  57. ;;
  58. (*-*_defconfig)
  59. defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
  60. do_defconfigs=base
  61. ;;
  62. (*-runtime-tests)
  63. do_runtime=true
  64. ;;
  65. (*-tests.*)
  66. runtimes=( $(./support/testing/run-tests -l 2>&1 \
  67. | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/' \
  68. | LC_ALL=C sort \
  69. | grep "^${CI_COMMIT_REF_NAME##*-}")
  70. )
  71. do_runtime=true
  72. ;;
  73. esac
  74. fi
  75. # If nothing else, at least do the basics to generate a valid pipeline
  76. if [ -z "${do_defconfigs}" \
  77. -a -z "${do_runtime}" \
  78. ]
  79. then
  80. do_basics=true
  81. fi
  82. if ${do_basics:-false}; then
  83. for tst in "${basics[@]}"; do
  84. printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
  85. done
  86. fi
  87. if [ -n "${do_defconfigs}" ]; then
  88. for cfg in "${defconfigs[@]}"; do
  89. printf '%s%s: { extends: .defconfig_%s }\n' \
  90. "${cfg}" "${defconfigs_ext}" "${do_defconfigs}"
  91. done
  92. fi
  93. if ${do_runtime:-false}; then
  94. printf '%s: { extends: .runtime_test_base }\n' "${runtimes[@]}"
  95. fi
  96. }
  97. main "${@}"