check-mzcompose-files.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # check-mzcompose-files.sh - Make sure mzcompose files run automatically in CI
  12. set -euo pipefail
  13. cd "$(dirname "$0")/../../../.."
  14. . misc/shlib/shlib.bash
  15. check_all_files_referenced_in_ci() {
  16. RETURN=0
  17. COMPOSITIONS=$(find . -name mzcompose.py \
  18. -not -wholename "./misc/python/materialize/cli/mzcompose.py" `# Only glue code, no workflows` \
  19. -not -wholename "./misc/monitoring/mzcompose.py" `# Only run manually` \
  20. -not -wholename "./test/canary-environment/mzcompose.py" `# Only run manually` \
  21. -not -wholename "./test/console/mzcompose.py" `# Only run manually` \
  22. -not -wholename "./test/mzcompose_examples/mzcompose.py" `# Example only` \
  23. -not -wholename "./test/get-cloud-hostname/mzcompose.py" `# Utility, no test` \
  24. | sed -e "s|.*/\([^/]*\)/mzcompose.py|\1|")
  25. while read -r composition; do
  26. if ! grep -q "composition: $composition" ci/*/pipeline.template.yml; then
  27. echo "mzcompose composition \"$composition\" is unused in any CI pipeline file"
  28. RETURN=1
  29. fi
  30. done <<< "$COMPOSITIONS"
  31. return $RETURN
  32. }
  33. check_default_workflow_references_others() {
  34. RETURN=0
  35. MZCOMPOSE_TEST_FILES=()
  36. while IFS= read -r file; do
  37. MZCOMPOSE_TEST_FILES+=("$file")
  38. done < <(find ./test -name "mzcompose.py" \
  39. -not -wholename "./test/canary-environment/mzcompose.py" `# Only run manually` \
  40. -not -wholename "./test/ssh-connection/mzcompose.py" `# Handled differently` \
  41. -not -wholename "./test/scalability/mzcompose.py" `# Other workflows are for manual usage` \
  42. -not -wholename "./test/testdrive-old-kafka-src-syntax/mzcompose.py" `# Other workflow is run separately` \
  43. -not -wholename "./test/terraform/mzcompose.py" `# Handled differently` \
  44. )
  45. for file in "${MZCOMPOSE_TEST_FILES[@]}"; do
  46. MATCHES_COUNT=$(grep "def workflow_" "$file" -c)
  47. if (( MATCHES_COUNT > 1 )); then
  48. # mzcompose file contains more than one workflow
  49. LOOP_DETECTED=$(grep "c.workflow(name" "$file" -c)
  50. if (( LOOP_DETECTED < 1 )); then
  51. echo "$file contains more than one workflow but does not seem to loop over the workflows"
  52. RETURN=1
  53. fi
  54. fi
  55. done
  56. if (( RETURN > 0 )); then
  57. echo "Use this pattern in the default workflow:"
  58. echo "for name in c.workflows:"
  59. echo " if name == \"default\":"
  60. echo " continue"
  61. echo ""
  62. echo " with c.test_case(name):"
  63. echo " c.workflow(name)"
  64. fi
  65. return $RETURN
  66. }
  67. # ensure that each mzcompose file is referenced
  68. try check_all_files_referenced_in_ci
  69. # ensure that each mzcompose file with more than one workflow loops over workflows in the default workflow
  70. try check_default_workflow_references_others
  71. # ensure that we can list the compositions without requiring environment variables to be set
  72. try env -i PATH="$PATH" MZ_DEV_CI_BUILDER="${MZ_DEV_CI_BUILDER:-local}" bin/mzcompose list-compositions > /dev/null
  73. try_status_report