calculate_jobs.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. IS_PR = os.environ["GITHUB_REF"].startswith("refs/pull/")
  19. # First calculate the various trial jobs.
  20. #
  21. # For each type of test we only run on Py3.7 on PRs
  22. trial_sqlite_tests = [
  23. {
  24. "python-version": "3.7",
  25. "database": "sqlite",
  26. "extras": "all",
  27. }
  28. ]
  29. if not IS_PR:
  30. trial_sqlite_tests.extend(
  31. {
  32. "python-version": version,
  33. "database": "sqlite",
  34. "extras": "all",
  35. }
  36. for version in ("3.8", "3.9", "3.10")
  37. )
  38. trial_postgres_tests = [
  39. {
  40. "python-version": "3.7",
  41. "database": "postgres",
  42. "postgres-version": "10",
  43. "extras": "all",
  44. }
  45. ]
  46. if not IS_PR:
  47. trial_postgres_tests.append(
  48. {
  49. "python-version": "3.10",
  50. "database": "postgres",
  51. "postgres-version": "14",
  52. "extras": "all",
  53. }
  54. )
  55. trial_no_extra_tests = [
  56. {
  57. "python-version": "3.7",
  58. "database": "sqlite",
  59. "extras": "",
  60. }
  61. ]
  62. print("::group::Calculated trial jobs")
  63. print(
  64. json.dumps(
  65. trial_sqlite_tests + trial_postgres_tests + trial_no_extra_tests, indent=4
  66. )
  67. )
  68. print("::endgroup::")
  69. test_matrix = json.dumps(
  70. trial_sqlite_tests + trial_postgres_tests + trial_no_extra_tests
  71. )
  72. print(f"::set-output name=trial_test_matrix::{test_matrix}")
  73. # First calculate the various sytest jobs.
  74. #
  75. # For each type of test we only run on focal on PRs
  76. sytest_tests = [
  77. {
  78. "sytest-tag": "focal",
  79. },
  80. {
  81. "sytest-tag": "focal",
  82. "postgres": "postgres",
  83. },
  84. {
  85. "sytest-tag": "focal",
  86. "postgres": "multi-postgres",
  87. "workers": "workers",
  88. },
  89. ]
  90. if not IS_PR:
  91. sytest_tests.extend(
  92. [
  93. {
  94. "sytest-tag": "testing",
  95. "postgres": "postgres",
  96. },
  97. {
  98. "sytest-tag": "buster",
  99. "postgres": "multi-postgres",
  100. "workers": "workers",
  101. },
  102. ]
  103. )
  104. print("::group::Calculated sytest jobs")
  105. print(json.dumps(sytest_tests, indent=4))
  106. print("::endgroup::")
  107. test_matrix = json.dumps(sytest_tests)
  108. print(f"::set-output name=sytest_test_matrix::{test_matrix}")