generate-gitlab-ci-yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. main() {
  5. local template="${1}"
  6. preamble "${template}"
  7. gen_defconfigs
  8. gen_tests
  9. }
  10. preamble() {
  11. local template="${1}"
  12. cat - "${template}" <<-_EOF_
  13. # This file is generated; do not edit!
  14. # Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines
  15. image: ${CI_JOB_IMAGE}
  16. _EOF_
  17. }
  18. gen_defconfigs() {
  19. local -a defconfigs
  20. local build_defconfigs cfg
  21. defconfigs=( $(cd configs; LC_ALL=C ls -1 *_defconfig) )
  22. build_defconfigs=false
  23. if [ -n "${CI_COMMIT_TAG}" ]; then
  24. # For tags, create a pipeline.
  25. build_defconfigs=true
  26. fi
  27. if [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  28. # For pipeline created by using a trigger token.
  29. build_defconfigs=true
  30. fi
  31. case "${CI_COMMIT_REF_NAME}" in
  32. # For the branch or tag name named *-defconfigs, create a pipeline.
  33. (*-defconfigs)
  34. build_defconfigs=true
  35. ;;
  36. (*-*_defconfig)
  37. defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
  38. build_defconfigs=true
  39. ;;
  40. esac
  41. for cfg in "${defconfigs[@]}"; do
  42. if ${build_defconfigs}; then
  43. printf '%s: { extends: .defconfig }\n' "${cfg}"
  44. else
  45. printf '%s_check: { extends: .defconfig_check }\n' "${cfg}"
  46. fi
  47. done
  48. }
  49. gen_tests() {
  50. local -a tests
  51. local run_tests tst
  52. tests=( $(./support/testing/run-tests -l 2>&1 \
  53. | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/'\
  54. | LC_ALL=C sort)
  55. )
  56. run_tests=false
  57. if [ -n "${CI_COMMIT_TAG}" ]; then
  58. # For tags, create a pipeline.
  59. run_tests=true
  60. fi
  61. if [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  62. # For pipeline created by using a trigger token.
  63. run_tests=true
  64. fi
  65. case "${CI_COMMIT_REF_NAME}" in
  66. # For the branch or tag name named *-runtime-tests, create a pipeline.
  67. (*-runtime-tests)
  68. run_tests=true
  69. ;;
  70. (*-tests.*)
  71. tests=( "${CI_COMMIT_REF_NAME##*-}" )
  72. run_tests=true
  73. ;;
  74. esac
  75. if ${run_tests}; then
  76. printf '%s: { extends: .runtime_test }\n' "${tests[@]}"
  77. fi
  78. }
  79. main "${@}"