generate-gitlab-ci-yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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=( "${CI_COMMIT_REF_NAME##*-}" )
  64. do_runtime=true
  65. ;;
  66. esac
  67. fi
  68. # Retrieve defconfig for test-pkg from the git commit message (if any)
  69. if grep -q -E '^test-pkg config:$' <<<"${CI_COMMIT_DESCRIPTION}"; then
  70. sed -r -n -e '/^test-pkg config:$/{:a;n;p;ba;}' \
  71. <<<"${CI_COMMIT_DESCRIPTION}" \
  72. >defconfig.frag
  73. if [ ! -s defconfig.frag ]; then
  74. printf "Empty configuration fragment.\n" >&2; exit 1
  75. fi
  76. # Use --all since we expect the user having already pre-tested the
  77. # new package with the default subset of toolchains.
  78. ./utils/test-pkg \
  79. --all --prepare-only \
  80. --config-snippet defconfig.frag \
  81. --build-dir br-test-pkg >&2
  82. do_testpkg=( $(ls -1 br-test-pkg/*/.config 2>/dev/null |xargs -r dirname ) )
  83. if [ "${#do_testpkg[@]}" -eq 0 ]; then
  84. printf "Configuration fragment enables no test.\n" >&2; exit 1
  85. fi
  86. fi
  87. # If nothing else, at least do the basics to generate a valid pipeline
  88. if [ -z "${do_defconfigs}" \
  89. -a -z "${do_runtime}" \
  90. -a -z "${do_testpkg}" \
  91. ]
  92. then
  93. do_basics=true
  94. fi
  95. if ${do_basics:-false}; then
  96. for tst in "${basics[@]}"; do
  97. printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
  98. done
  99. fi
  100. if [ -n "${do_defconfigs}" ]; then
  101. for cfg in "${defconfigs[@]}"; do
  102. printf '%s%s: { extends: .defconfig_%s }\n' \
  103. "${cfg}" "${defconfigs_ext}" "${do_defconfigs}"
  104. done
  105. fi
  106. if ${do_runtime:-false}; then
  107. printf '%s: { extends: .runtime_test_base }\n' "${runtimes[@]}"
  108. fi
  109. if [ -n "${do_testpkg}" ]; then
  110. printf '%s: { extends: .test_pkg }\n' "${do_testpkg[@]}"
  111. fi
  112. }
  113. main "${@}"