summaryrefslogtreecommitdiff
path: root/.github/scripts/sg_platform_annotate.py
blob: e8567d81506915f9a6b8c8f2eaaaa0d52307484f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
"""Print ten chunks of a text file as notice annotations, starting at chunk N."""
import sys

CHUNK = 3600  # an annotation keeps 4096 bytes
lines = open(sys.argv[1], encoding="utf-8", errors="replace").read().splitlines()
chunks, current = [], ""
for line in lines:
    if current and len((current + line).encode("utf-8")) + 1 > CHUNK:
        chunks.append(current)
        current = ""
    current += line[:CHUNK] + "\n"
if current:
    chunks.append(current)
first = int(sys.argv[2])
for index in range(first, min(first + 10, len(chunks))):
    body = chunks[index].replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
    print("::notice title=report %03d of %03d::%s" % (index + 1, len(chunks), body))
if first == 0:
    print("%d chunks, %d characters" % (len(chunks), sum(map(len, chunks))))