You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

146 lines
3.4 KiB

  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")
  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.12",
  55. "database": "postgres",
  56. "postgres-version": "16",
  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)