generate-gitlab-ci-yml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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) build_defconfigs=true;;
  34. esac
  35. for cfg in "${defconfigs[@]}"; do
  36. if ${build_defconfigs}; then
  37. printf '%s: { extends: .defconfig }\n' "${cfg}"
  38. else
  39. printf '%s_check: { extends: .defconfig_check }\n' "${cfg}"
  40. fi
  41. done
  42. }
  43. gen_tests() {
  44. local -a tests
  45. local run_tests tst
  46. tests=( $(./support/testing/run-tests -l 2>&1 \
  47. | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/'\
  48. | LC_ALL=C sort)
  49. )
  50. run_tests=false
  51. if [ -n "${CI_COMMIT_TAG}" ]; then
  52. # For tags, create a pipeline.
  53. run_tests=true
  54. fi
  55. if [ -n "${CI_PIPELINE_TRIGGERED}" ]; then
  56. # For pipeline created by using a trigger token.
  57. run_tests=true
  58. fi
  59. case "${CI_COMMIT_REF_NAME}" in
  60. # For the branch or tag name named *-runtime-tests, create a pipeline.
  61. (*-runtime-tests) run_tests=true;;
  62. esac
  63. if ${run_tests}; then
  64. printf '%s: { extends: .runtime_test }\n' "${tests[@]}"
  65. fi
  66. }
  67. main "${@}"