@@ -85,60 +85,66 @@ def buzzer_on_completion():
8585 print ("Opening serial port." )
8686 mSerial = serial .Serial (serial_port , baud_rate )
8787
88- print ("Starting Github Actions Status Watcher" )
88+ print ("Starting Github Actions Status Watcher. " )
8989print ("Press Ctrl-C to Exit" )
90- while True :
91- print ("Fetching workflow run status." )
92- response = requests .get (f"{ REPO_WORKFLOW_URL } ?per_page=1" , headers = headers )
93- response_json = response .json ()
94- with open ("action_status_result.json" , "w" ) as f :
95- f .write (json .dumps (response_json ))
96-
97- workflow_run_id = response_json ['workflow_runs' ][0 ]['id' ]
98- if workflow_run_id not in already_shown_ids :
99- status = response_json ['workflow_runs' ][0 ]['status' ]
100- conclusion = response_json ['workflow_runs' ][0 ]['conclusion' ]
101- print (f"Status - Conclusion: { status } - { conclusion } " )
102-
103- if status == "queued" :
104- print ("Actions run status: Queued." )
105- if ENABLE_USB_LIGHT_MESSAGES :
106- print ("Sending serial command 'YELLOW_BLINK'." )
107- send_command (mSerial , YELLOW_BLINK )
108-
109- if status == "in_progress" :
110- print ("Actions run status: In progress." )
111- if ENABLE_USB_LIGHT_MESSAGES :
112- print ("Sending serial command 'YELLOW_ON'." )
113- send_command (mSerial , YELLOW_ON )
114-
115- if status == "completed" :
116- print (f"Adding { workflow_run_id } to shown workflow IDs." )
117- already_shown_ids .append (workflow_run_id )
118-
119- if conclusion == "success" :
120- print ("Actions run status: Completed - successful." )
90+ try :
91+ while True :
92+ print ("Fetching workflow run status." )
93+ response = requests .get (f"{ REPO_WORKFLOW_URL } ?per_page=1" , headers = headers )
94+ response_json = response .json ()
95+ with open ("action_status_result.json" , "w" ) as f :
96+ f .write (json .dumps (response_json ))
97+
98+ workflow_run_id = response_json ['workflow_runs' ][0 ]['id' ]
99+ if workflow_run_id not in already_shown_ids :
100+ status = response_json ['workflow_runs' ][0 ]['status' ]
101+ conclusion = response_json ['workflow_runs' ][0 ]['conclusion' ]
102+ print (f"Status - Conclusion: { status } - { conclusion } " )
103+
104+ if status == "queued" :
105+ print ("Actions run status: Queued." )
121106 if ENABLE_USB_LIGHT_MESSAGES :
122- send_command (mSerial , YELLOW_OFF )
123- print ("Sending serial command 'GREEN_ON'." )
124- send_command (mSerial , GREEN_ON )
125- buzzer_on_completion ()
126- time .sleep (COMPLETION_LIGHT_TIME - COMPLETION_BUZZER_TIME )
127- if ENABLE_USB_LIGHT_MESSAGES :
128- print ("Sending serial command 'GREEN_OFF'." )
129- send_command (mSerial , GREEN_OFF )
107+ print ("Sending serial command 'YELLOW_BLINK'." )
108+ send_command (mSerial , YELLOW_BLINK )
130109
131- if conclusion == "failure" :
132- print ("Actions run status: Completed - failed." )
133- if ENABLE_USB_LIGHT_MESSAGES :
134- send_command (mSerial , YELLOW_OFF )
135- print ("Sending serial command 'RED_ON'." )
136- send_command (mSerial , RED_ON )
137- buzzer_on_completion ()
138- time .sleep (COMPLETION_LIGHT_TIME - COMPLETION_BUZZER_TIME )
110+ if status == "in_progress" :
111+ print ("Actions run status: In progress." )
139112 if ENABLE_USB_LIGHT_MESSAGES :
140- print ("Sending serial command 'RED_OFF'." )
141- send_command (mSerial , RED_OFF )
142- else :
143- print ("Already followed the current run." )
144- time .sleep (POLL_DELAY )
113+ print ("Sending serial command 'YELLOW_ON'." )
114+ send_command (mSerial , YELLOW_ON )
115+
116+ if status == "completed" :
117+ print (f"Adding { workflow_run_id } to shown workflow IDs." )
118+ already_shown_ids .append (workflow_run_id )
119+
120+ if conclusion == "success" :
121+ print ("Actions run status: Completed - successful." )
122+ if ENABLE_USB_LIGHT_MESSAGES :
123+ send_command (mSerial , YELLOW_OFF )
124+ print ("Sending serial command 'GREEN_ON'." )
125+ send_command (mSerial , GREEN_ON )
126+ buzzer_on_completion ()
127+ time .sleep (COMPLETION_LIGHT_TIME - COMPLETION_BUZZER_TIME )
128+ if ENABLE_USB_LIGHT_MESSAGES :
129+ print ("Sending serial command 'GREEN_OFF'." )
130+ send_command (mSerial , GREEN_OFF )
131+
132+ if conclusion == "failure" :
133+ print ("Actions run status: Completed - failed." )
134+ if ENABLE_USB_LIGHT_MESSAGES :
135+ send_command (mSerial , YELLOW_OFF )
136+ print ("Sending serial command 'RED_ON'." )
137+ send_command (mSerial , RED_ON )
138+ buzzer_on_completion ()
139+ time .sleep (COMPLETION_LIGHT_TIME - COMPLETION_BUZZER_TIME )
140+ if ENABLE_USB_LIGHT_MESSAGES :
141+ print ("Sending serial command 'RED_OFF'." )
142+ send_command (mSerial , RED_OFF )
143+
144+ else :
145+ print ("Already followed the current run." )
146+ time .sleep (POLL_DELAY )
147+
148+ except KeyboardInterrupt :
149+ print ("\n Exiting Github Actions Status Watcher." )
150+ reset_state ()
0 commit comments