forked from ChelseaKR/permit-bearings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_currency_workflow.py
More file actions
63 lines (50 loc) · 2.39 KB
/
Copy pathtest_currency_workflow.py
File metadata and controls
63 lines (50 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from __future__ import annotations
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
WORKFLOW_PATH = ROOT / ".github" / "workflows" / "currency.yml"
def _workflow_step(workflow: str, name: str) -> str:
marker = f" - name: {name}\n"
start = workflow.index(marker)
end = workflow.find("\n - name: ", start + len(marker))
return workflow[start:] if end == -1 else workflow[start:end]
def test_review_package_requires_a_nonempty_changed_source_list():
workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
watch_step = _workflow_step(workflow, "Re-fetch watched sources and diff hashes")
package_step = _workflow_step(
workflow,
"Build the exact re-verification review package",
)
upload_step = _workflow_step(
workflow,
"Retain the exact re-verification review package",
)
assert 'payload.get("changed_source_ids")' in watch_step
assert 'echo "has_changed_sources=$has_changed_sources"' in watch_step
assert "if: steps.watch.outputs.has_changed_sources == 'true'" in package_step
assert "if: steps.watch.outputs.has_changed_sources == 'true'" in upload_step
assert "steps.watch.outputs.exit_code == '1'" not in package_step
assert "steps.watch.outputs.exit_code == '1'" not in upload_step
def test_stale_only_or_golden_regression_still_opens_currency_alert():
workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
alert_step = _workflow_step(
workflow, "Open an issue when currency review is needed"
)
assert "always() && steps.watch.outputs.exit_code == '1'" in alert_step
assert "changed watched sources, stale rules, or a golden regression" in alert_step
assert "has_changed_sources" not in alert_step
def test_package_failure_cannot_suppress_the_currency_alert():
workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
package_step = _workflow_step(
workflow,
"Build the exact re-verification review package",
)
upload_step = _workflow_step(
workflow,
"Retain the exact re-verification review package",
)
alert_step = _workflow_step(
workflow, "Open an issue when currency review is needed"
)
assert workflow.index(package_step) < workflow.index(alert_step)
assert workflow.index(upload_step) < workflow.index(alert_step)
assert "if: ${{ always() && steps.watch.outputs.exit_code == '1' }}" in alert_step