-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreset-schedule.py
55 lines (34 loc) · 1.18 KB
/
reset-schedule.py
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
# This script only works within Github Actions
# pip install ruamel.yaml
# ---
from csv import DictReader
import os
from ruamel.yaml import YAML
# import env variables from runner's bash shell
folder = os.environ["folder"]
default_cron = []
wf_cron = []
with open("default-schedule.csv", mode="r") as csv_file:
reader = DictReader(csv_file)
for row in reader:
if row["Folder"] == folder:
default_cron.append(row["Cron"])
print(f"\n\nDefault cron times for login-{folder}-auto are:\n{default_cron}\n\n")
yaml = YAML() # defaults to round-trip (typ="rt")
workflow_file = f"./.github/workflows/login-{folder}-auto.yml"
with open(workflow_file, "r") as file:
wf = yaml.load(file)
schedules = wf["on"]["schedule"]
for schedule in schedules:
wf_cron.append(schedule["cron"])
print(f"Current cron times are:\n{wf_cron}\n\n")
if wf_cron == default_cron:
print("\nNo reset needed.\n\n")
else:
for schedule, Cron in zip(schedules, default_cron):
if schedule["cron"] != Cron:
schedule["cron"] = Cron
print("\nSchedule has been reset.\n\n")
with open(workflow_file, "w") as file:
yaml.dump(wf, file)
print(wf)