-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpost_upload_coverage.py
More file actions
62 lines (50 loc) · 1.78 KB
/
Copy pathpost_upload_coverage.py
File metadata and controls
62 lines (50 loc) · 1.78 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
#!/usr/bin/env python3
"""Post step for upload-code-coverage Action telemetry.
Runs after the main step (even on cancellation/failure) to ensure we
always report a final status. If the main step already sent a completion
report, this is a no-op.
"""
import json
import os
import sys
import status_report
def main() -> int:
if status_report.get_state("status_sent") == "true":
return 0
env = os.environ
repository = env.get("GITHUB_REPOSITORY", "")
api_url = env.get("GITHUB_API_URL", "https://api.github.com")
token = env.get("GH_TOKEN", "")
# Try to retry the completed report if it was built but failed to send
completed_report_json = status_report.get_state("completed_report")
if completed_report_json:
try:
report = json.loads(completed_report_json)
status_report.send_status_report(
report,
repository=repository,
api_url=api_url,
token=token,
)
return 0
except (json.JSONDecodeError, TypeError):
pass
# Otherwise build an "aborted" report from the saved starting report
starting_report_json = status_report.get_state("starting_report")
if starting_report_json:
try:
starting_report = json.loads(starting_report_json)
except (json.JSONDecodeError, TypeError):
starting_report = status_report.build_starting_report()
else:
starting_report = status_report.build_starting_report()
report = status_report.build_completed_report(starting_report, status="aborted")
status_report.send_status_report(
report,
repository=repository,
api_url=api_url,
token=token,
)
return 0
if __name__ == "__main__":
sys.exit(main())