2
1

generate-gitlab-ci-yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 do_testpkg
  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. do_basics=true
  29. do_defconfigs=base
  30. do_runtime=true
  31. elif [ "${CI_PIPELINE_SOURCE}" = "trigger" ]; then
  32. case "${BR_SCHEDULE_JOBS}" in
  33. (basic)
  34. do_basics=true
  35. do_defconfigs=check
  36. defconfigs_ext=_check
  37. ;;
  38. (defconfig)
  39. do_defconfigs=base
  40. ;;
  41. (runtime)
  42. do_runtime=true
  43. ;;
  44. esac
  45. else
  46. case "${CI_COMMIT_REF_NAME}" in
  47. (*-basics)
  48. do_basics=true
  49. do_defconfigs=check
  50. defconfigs_ext=_check
  51. ;;
  52. (*-defconfigs)
  53. do_defconfigs=base
  54. ;;
  55. (*-*_defconfig)
  56. defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
  57. do_defconfigs=base
  58. ;;
  59. (*-runtime-tests)
  60. do_runtime=true
  61. ;;
  62. (*-tests.*)
  63. runtimes=( $(./support/testing/run-tests -l 2>&1 \
  64. | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/' \
  65. | LC_ALL=C sort \
  66. | grep "^${CI_COMMIT_REF_NAME##*-}")
  67. )
  68. do_runtime=true
  69. ;;
  70. esac
  71. fi
  72. # Retrieve defconfig for test-pkg from the git commit message (if any)
  73. if grep -q -E '^test-pkg config:$' <<<"${CI_COMMIT_DESCRIPTION}"; then
  74. sed -r -n -e '/^test-pkg config:$/{:a;n;p;ba;}' \
  75. <<<"${CI_COMMIT_DESCRIPTION}" \
  76. >defconfig.frag
  77. if [ ! -s defconfig.frag ]; then
  78. printf "Empty configuration fragment.\n" >&2; exit 1
  79. fi
  80. # Use --all since we expect the user having already pre-tested the
  81. # new package with the default subset of toolchains.
  82. ./utils/test-pkg \
  83. --all --prepare-only \
  84. --config-snippet defconfig.frag \
  85. --build-dir br-test-pkg >&2
  86. do_testpkg=( $(ls -1 br-test-pkg/*/.config 2>/dev/null |xargs -r dirname ) )
  87. if [ "${#do_testpkg[@]}" -eq 0 ]; then
  88. printf "Configuration fragment enables no test.\n" >&2; exit 1
  89. fi
  90. fi
  91. # If nothing else, at least do the basics to generate a valid pipeline
  92. if [ -z "${do_defconfigs}" \
  93. -a -z "${do_runtime}" \
  94. -a -z "${do_testpkg}" \
  95. ]
  96. then
  97. do_basics=true
  98. fi
  99. if ${do_basics:-false}; then
  100. for tst in "${basics[@]}"; do
  101. printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
  102. done
  103. fi
  104. if [ -n "${do_defconfigs}" ]; then
  105. for cfg in "${defconfigs[@]}"; do
  106. printf '%s%s: { extends: .defconfig_%s }\n' \
  107. "${cfg}" "${defconfigs_ext}" "${do_defconfigs}"
  108. done
  109. fi
  110. if ${do_runtime:-false}; then
  111. printf '%s: { extends: .runtime_test_base }\n' "${runtimes[@]}"
  112. fi
  113. if [ -n "${do_testpkg}" ]; then
  114. printf '%s: { extends: .test_pkg }\n' "${do_testpkg[@]}"
  115. fi
  116. }
  117. main "${@}"