annotation_search.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python3
  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. import argparse
  11. from materialize.buildkite_insights.annotation_search import annotation_search_logic
  12. from materialize.buildkite_insights.annotation_search.buildkite_search_source import (
  13. ANY_PIPELINE_VALUE,
  14. BuildkiteDataSource,
  15. )
  16. from materialize.buildkite_insights.buildkite_api.buildkite_config import (
  17. MZ_PIPELINES_WITH_WILDCARD,
  18. )
  19. from materialize.buildkite_insights.cache.cache_constants import (
  20. FETCH_MODE_CHOICES,
  21. FetchMode,
  22. )
  23. if __name__ == "__main__":
  24. parser = argparse.ArgumentParser(
  25. prog="buildkite-annotation-search",
  26. formatter_class=argparse.RawDescriptionHelpFormatter,
  27. )
  28. parser.add_argument(
  29. "pipeline",
  30. choices=MZ_PIPELINES_WITH_WILDCARD,
  31. type=str,
  32. help=f"Use {ANY_PIPELINE_VALUE} for all pipelines",
  33. )
  34. parser.add_argument("pattern", type=str)
  35. parser.add_argument(
  36. "--branch",
  37. type=str,
  38. default=None,
  39. )
  40. parser.add_argument(
  41. "--fetch-builds",
  42. type=lambda mode: FetchMode[mode.upper()],
  43. choices=FETCH_MODE_CHOICES,
  44. default=FetchMode.AUTO,
  45. help="Whether to fetch fresh builds from Buildkite.",
  46. )
  47. parser.add_argument(
  48. "--fetch-annotations",
  49. type=lambda mode: FetchMode[mode.upper()],
  50. choices=FETCH_MODE_CHOICES,
  51. default=FetchMode.AUTO,
  52. help="Whether to fetch fresh annotations from Buildkite.",
  53. )
  54. parser.add_argument("--max-build-fetches", default=2, type=int)
  55. parser.add_argument("--first-build-page-to-fetch", default=1, type=int)
  56. parser.add_argument("--max-results", default=50, type=int)
  57. parser.add_argument(
  58. "--only-one-result-per-build",
  59. default=False,
  60. action="store_true",
  61. )
  62. parser.add_argument(
  63. "--only-failed-builds",
  64. default=False,
  65. action="store_true",
  66. )
  67. parser.add_argument(
  68. "--short",
  69. default=False,
  70. action="store_true",
  71. )
  72. parser.add_argument(
  73. "--oneline",
  74. default=False,
  75. action="store_true",
  76. )
  77. parser.add_argument(
  78. "--only-failed-build-step-key", action="append", default=[], type=str
  79. )
  80. parser.add_argument(
  81. "--verbose",
  82. default=False,
  83. action="store_true",
  84. )
  85. parser.add_argument(
  86. "--use-regex",
  87. action="store_true",
  88. )
  89. args = parser.parse_args()
  90. if args.short and args.oneline:
  91. print("Note: --oneline will be ignored if --short is set")
  92. source = BuildkiteDataSource(
  93. fetch_builds_mode=args.fetch_builds,
  94. fetch_annotations_mode=args.fetch_annotations,
  95. max_build_fetches=args.max_build_fetches,
  96. first_build_page_to_fetch=args.first_build_page_to_fetch,
  97. only_failed_builds=args.only_failed_builds,
  98. only_failed_build_step_keys=args.only_failed_build_step_key,
  99. )
  100. annotation_search_logic.start_search(
  101. args.pipeline,
  102. args.branch,
  103. source,
  104. args.max_results,
  105. args.only_one_result_per_build,
  106. args.pattern,
  107. args.use_regex,
  108. args.short,
  109. args.oneline,
  110. args.verbose,
  111. )