calculate_jobs.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 PRs, we only run each type of test with the oldest Python version supported (which
  26. # is Python 3.8 right now)
  27. trial_sqlite_tests = [
  28. {
  29. "python-version": "3.8",
  30. "database": "sqlite",
  31. "extras": "all",
  32. }
  33. ]
  34. if not IS_PR:
  35. trial_sqlite_tests.extend(
  36. {
  37. "python-version": version,
  38. "database": "sqlite",
  39. "extras": "all",
  40. }
  41. for version in ("3.9", "3.10", "3.11", "3.12.0-rc.1")
  42. )
  43. trial_postgres_tests = [
  44. {
  45. "python-version": "3.8",
  46. "database": "postgres",
  47. "postgres-version": "11",
  48. "extras": "all",
  49. }
  50. ]
  51. if not IS_PR:
  52. trial_postgres_tests.append(
  53. {
  54. "python-version": "3.11",
  55. "database": "postgres",
  56. "postgres-version": "15",
  57. "extras": "all",
  58. }
  59. )
  60. trial_no_extra_tests = [
  61. {
  62. "python-version": "3.8",
  63. "database": "sqlite",
  64. "extras": "",
  65. }
  66. ]
  67. print("::group::Calculated trial jobs")
  68. print(
  69. json.dumps(
  70. trial_sqlite_tests + trial_postgres_tests + trial_no_extra_tests, indent=4
  71. )
  72. )
  73. print("::endgroup::")
  74. test_matrix = json.dumps(
  75. trial_sqlite_tests + trial_postgres_tests + trial_no_extra_tests
  76. )
  77. set_output("trial_test_matrix", test_matrix)
  78. # First calculate the various sytest jobs.
  79. #
  80. # For each type of test we only run on focal on PRs
  81. sytest_tests = [
  82. {
  83. "sytest-tag": "focal",
  84. },
  85. {
  86. "sytest-tag": "focal",
  87. "postgres": "postgres",
  88. },
  89. {
  90. "sytest-tag": "focal",
  91. "postgres": "multi-postgres",
  92. "workers": "workers",
  93. },
  94. {
  95. "sytest-tag": "focal",
  96. "postgres": "multi-postgres",
  97. "workers": "workers",
  98. "reactor": "asyncio",
  99. },
  100. ]
  101. if not IS_PR:
  102. sytest_tests.extend(
  103. [
  104. {
  105. "sytest-tag": "focal",
  106. "reactor": "asyncio",
  107. },
  108. {
  109. "sytest-tag": "focal",
  110. "postgres": "postgres",
  111. "reactor": "asyncio",
  112. },
  113. {
  114. "sytest-tag": "testing",
  115. "postgres": "postgres",
  116. },
  117. ]
  118. )
  119. print("::group::Calculated sytest jobs")
  120. print(json.dumps(sytest_tests, indent=4))
  121. print("::endgroup::")
  122. test_matrix = json.dumps(sytest_tests)
  123. set_output("sytest_test_matrix", test_matrix)