-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathupdate-score.sh
executable file
·33 lines (27 loc) · 993 Bytes
/
update-score.sh
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
#!/usr/bin/env bash
export NEW_SCORE="$(python3 ./tools/python/score.py)"
export NEW_SCORE_SUMMARY="$(python3 ./tools/python/score.py --summary)"
python3 - <<'EOF' > README.md.tmp
import sys
import os
import re
from datetime import datetime
BEGIN = '<!-- README_SCORE_BEGIN -->'
END = '<!-- README_SCORE_END -->'
BEGIN_SUMMARY = '<!-- README_SCORE_SUMMARY_BEGIN -->'
END_SUMMARY = '<!-- README_SCORE_SUMMARY_END -->'
DATE_STR = datetime.now().strftime('As of %B %-d, %Y, this is our current score:')
score_updated = re.sub(
fr'(?s).{BEGIN}.*{END}',
f'\n{BEGIN}\n{DATE_STR}\n```\n{os.environ["NEW_SCORE"]}\n```\n{END}',
open('README.md', 'r').read()
)
tabbed_summary = '\n\n'.join([(' ' * 4) + line for line in os.environ["NEW_SCORE_SUMMARY"].split('\n')])
summary_updated = re.sub(
fr'(?s).{BEGIN_SUMMARY}.*{END_SUMMARY}',
f'\n{BEGIN_SUMMARY}\n{DATE_STR}\n\n{tabbed_summary}\n{END_SUMMARY}',
score_updated
)
print(summary_updated, end='')
EOF
mv README.md.tmp README.md