calculate_jobs.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env python
  2. # Copyright 2022 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Calculate the trial jobs to run based on if we're in a PR or not.
  16. import json
  17. import os
  18. def set_output(key: str, value: str):
  19. # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
  20. with open(os.environ["GITHUB_OUTPUT"], "at") as f:
  21. print(f"{key}={value}", file=f)
  22. IS_PR = os.environ["GITHUB_REF"].startswith("refs/pull/")
  23. # First calculate the various trial jobs.
  24. #
  25. # For each type of test we only run on Py3.7 on PRs
  26. trial_sqlite_tests = [
  27. {
  28. "python-version": "3.7",
  29. "database": "sqlite",
  30. "extras": "all",
  31. }
  32. ]
  33. if not IS_PR:
  34. trial_sqlite_tests.extend(
  35. {
  36. "python-version": version,
  37. "database": "sqlite",
  38. "extras": "all",
  39. }
  40. for version in ("3.8", "3.9", "3.10", "3.11")
  41. )
  42. trial_postgres_tests = [
  43. {
  44. "python-version": "3.7",
  45. "database": "postgres",
  46. "postgres-version": "11",
  47. "extras": "all",
  48. }
  49. ]
  50. if not IS_PR:
  51. trial_postgres_tests.append(
  52. {
  53. "python-version": "3.11",
  54. "database": "postgres",
  55. "postgres-version": "15",
  56. "extras": "all",
  57. }
  58. )
  59. trial_no_extra_tests = [
  60. {
  61. "python-version": "3.7",
  62. "database": "sqlite",
  63. "extras": "",
  64. }
  65. ]
  66. print("::group::Calculated trial jobs")
  67. print(
  68. json.dumps(
  69. trial_sqlite_tests + trial_postgres_tests + trial_no_extra_tests, indent=4
  70. )
  71. )
  72. print("::endgroup::")
  73. test_matrix = json.dumps(
  74. trial_sqlite_tests + trial_postgres_tests + trial_no_extra_tests
  75. )
  76. set_output("trial_test_matrix", test_matrix)
  77. # First calculate the various sytest jobs.
  78. #
  79. # For each type of test we only run on focal on PRs
  80. sytest_tests = [
  81. {
  82. "sytest-tag": "focal",
  83. },
  84. {
  85. "sytest-tag": "focal",
  86. "postgres": "postgres",
  87. },
  88. {
  89. "sytest-tag": "focal",
  90. "postgres": "multi-postgres",
  91. "workers": "workers",
  92. },
  93. {
  94. "sytest-tag": "focal",
  95. "postgres": "multi-postgres",
  96. "workers": "workers",
  97. "reactor": "asyncio",
  98. },
  99. ]
  100. if not IS_PR:
  101. sytest_tests.extend(
  102. [
  103. {
  104. "sytest-tag": "focal",
  105. "reactor": "asyncio",
  106. },
  107. {
  108. "sytest-tag": "focal",
  109. "postgres": "postgres",
  110. "reactor": "asyncio",
  111. },
  112. {
  113. "sytest-tag": "testing",
  114. "postgres": "postgres",
  115. },
  116. {
  117. "sytest-tag": "buster",
  118. "postgres": "multi-postgres",
  119. "workers": "workers",
  120. },
  121. ]
  122. )
  123. print("::group::Calculated sytest jobs")
  124. print(json.dumps(sytest_tests, indent=4))
  125. print("::endgroup::")
  126. test_matrix = json.dumps(sytest_tests)
  127. set_output("sytest_test_matrix", test_matrix)