generate-gitlab-ci-yml 2.7 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. fi
  40. if [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  41. # For pipeline created by using a trigger token.
  42. template=base
  43. fi
  44. case "${CI_COMMIT_REF_NAME}" in
  45. # For master, next, and maintenance branches, only check the defconfigs
  46. (master|next|????.??.x)
  47. template=check
  48. ext=_check
  49. ;;
  50. # For the branch or tag name named *-defconfigs, create a pipeline.
  51. (*-defconfigs)
  52. template=base
  53. ;;
  54. (*-*_defconfig)
  55. defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
  56. template=base
  57. ;;
  58. esac
  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. fi
  78. if [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  79. # For pipeline created by using a trigger token.
  80. run_tests=true
  81. fi
  82. case "${CI_COMMIT_REF_NAME}" in
  83. # For the branch or tag name named *-runtime-tests, create a pipeline.
  84. (*-runtime-tests)
  85. run_tests=true
  86. ;;
  87. (*-tests.*)
  88. tests=( "${CI_COMMIT_REF_NAME##*-}" )
  89. run_tests=true
  90. ;;
  91. esac
  92. if ${run_tests}; then
  93. printf '%s: { extends: .runtime_test_base }\n' "${tests[@]}"
  94. fi
  95. }
  96. main "${@}"