|
18 | 18 | "Close stale pull requests", |
19 | 19 | "Update S3 HTML indices for download.pytorch.org", |
20 | 20 | "Create Release", |
| 21 | + "Apple", |
| 22 | + "pull-test-sandbox", |
21 | 23 | ] |
22 | 24 |
|
23 | | -requires = ["pull", "trunk", "lint", "linux-binary"] |
| 25 | +# Matched with re.fullmatch: exact name ("lint" matches "Lint" via IGNORECASE) |
| 26 | +# or explicit regex ("^Apple$"). "pull" must NOT match "pull-test-sandbox". |
| 27 | +requires = ["pull", "trunk", "lint", "linux-binary-libtorch-pre-cxx11", "^Apple$"] |
24 | 28 |
|
25 | 29 |
|
26 | 30 | def set_workflow_job_status( |
@@ -117,7 +121,7 @@ def test_skippable_skipped( |
117 | 121 | workflow_checks = set_workflow_job_status( |
118 | 122 | workflow_checks, "docker-release-builds", "skipped" |
119 | 123 | ) |
120 | | - self.assertTrue(is_green("sha", requires, workflow_checks)) |
| 124 | + self.assertTrue(is_green("sha", requires, workflow_checks)[0]) |
121 | 125 |
|
122 | 126 | @mock.patch( |
123 | 127 | "tools.scripts.fetch_latest_green_commit.get_commit_results", |
@@ -163,8 +167,69 @@ def test_no_workflows( |
163 | 167 | self.assertFalse(result[0]) |
164 | 168 | self.assertEqual( |
165 | 169 | result[1], |
166 | | - "missing required workflows: pull, trunk, lint, linux-binary", |
| 170 | + "missing required workflows: pull, trunk, lint, " |
| 171 | + "linux-binary-libtorch-pre-cxx11, ^Apple$", |
| 172 | + ) |
| 173 | + |
| 174 | + @mock.patch( |
| 175 | + "tools.scripts.fetch_latest_green_commit.get_commit_results", |
| 176 | + return_value=TestChecks().make_test_checks(), |
| 177 | + ) |
| 178 | + def test_prefix_does_not_match( |
| 179 | + self, mock_get_commit_results: Any, mock_fetch_unstable_issues: Any |
| 180 | + ) -> None: |
| 181 | + """A required "pull" must not match "pull-test-sandbox".""" |
| 182 | + workflow_checks = mock_get_commit_results() |
| 183 | + workflow_checks = set_workflow_job_status( |
| 184 | + workflow_checks, "pull-test-sandbox", "failed" |
167 | 185 | ) |
| 186 | + result = is_green("sha", requires, workflow_checks) |
| 187 | + self.assertTrue(result[0]) |
| 188 | + |
| 189 | + @mock.patch( |
| 190 | + "tools.scripts.fetch_latest_green_commit.get_commit_results", |
| 191 | + return_value=TestChecks().make_test_checks(), |
| 192 | + ) |
| 193 | + def test_regex_required_check( |
| 194 | + self, mock_get_commit_results: Any, mock_fetch_unstable_issues: Any |
| 195 | + ) -> None: |
| 196 | + """An explicit regex required check (ex: "^Apple$") still matches.""" |
| 197 | + workflow_checks = mock_get_commit_results() |
| 198 | + workflow_checks = set_workflow_job_status(workflow_checks, "Apple", "failed") |
| 199 | + result = is_green("sha", requires, workflow_checks) |
| 200 | + self.assertFalse(result[0]) |
| 201 | + self.assertEqual(result[1], "Apple was not successful, test/job failed") |
| 202 | + |
| 203 | + @mock.patch( |
| 204 | + "tools.scripts.fetch_latest_green_commit.get_commit_results", |
| 205 | + return_value=[ |
| 206 | + WorkflowCheck( |
| 207 | + workflowName="pull-test-sandbox", |
| 208 | + name="test/job", |
| 209 | + jobName="job", |
| 210 | + conclusion="success", |
| 211 | + )._asdict() |
| 212 | + ], |
| 213 | + ) |
| 214 | + def test_prefix_success_does_not_satisfy( |
| 215 | + self, mock_get_commit_results: Any, mock_fetch_unstable_issues: Any |
| 216 | + ) -> None: |
| 217 | + """A prefix-named workflow does not satisfy an exact required check.""" |
| 218 | + result = is_green("sha", ["pull"], mock_get_commit_results()) |
| 219 | + self.assertFalse(result[0]) |
| 220 | + self.assertEqual(result[1], "missing required workflows: pull") |
| 221 | + |
| 222 | + @mock.patch( |
| 223 | + "tools.scripts.fetch_latest_green_commit.get_commit_results", |
| 224 | + return_value=TestChecks().make_test_checks(), |
| 225 | + ) |
| 226 | + def test_empty_required_check_ignored( |
| 227 | + self, mock_get_commit_results: Any, mock_fetch_unstable_issues: Any |
| 228 | + ) -> None: |
| 229 | + """An empty required-check entry is skipped, not left unsatisfiable.""" |
| 230 | + workflow_checks = mock_get_commit_results() |
| 231 | + result = is_green("sha", requires + [""], workflow_checks) |
| 232 | + self.assertTrue(result[0]) |
168 | 233 |
|
169 | 234 |
|
170 | 235 | if __name__ == "__main__": |
|
0 commit comments