Last active
November 15, 2023 23:34
-
-
Save Pyrrha/c8f94934f984ccb785c87ccdbbed32ad to your computer and use it in GitHub Desktop.
Watcher CircleCI using blink(1) appliance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: CIRCLE_TOKEN=x CIRCLE_WATCHER_ORG=y CIRCLE_WATCHER_PROJECT=z python main.py | |
from blink1.blink1 import Blink1 | |
from pycircleci.api import Api, CIRCLE_TOKEN | |
import os | |
import time | |
ORG = os.environ["CIRCLE_WATCHER_ORG"] | |
PROJECT = os.environ["CIRCLE_WATCHER_PROJECT"] | |
BRANCH = os.environ.get("CIRCLE_WATCHER_BRANCH", None) | |
circle_client = Api(token=CIRCLE_TOKEN) | |
b1 = Blink1() | |
def get_latest_build_summary(): | |
return circle_client.get_project_build_summary( | |
username=ORG, | |
project=PROJECT, | |
branch=BRANCH, | |
limit=1)[0] | |
def fixed_running(): | |
b1.fade_to_rgb(300, 5, 5, 49) | |
def blink_success(): | |
for x in range(2): | |
b1.fade_to_rgb(300, 0, 255, 0) | |
time.sleep(500 / 1000) | |
b1.fade_to_color(300, 'black') | |
time.sleep(500 / 1000) | |
def blink_failure(): | |
for x in range(4): | |
b1.fade_to_rgb(300, 255, 0, 0) | |
time.sleep(500 / 1000) | |
b1.fade_to_color(300, 'black') | |
time.sleep(500 / 1000) | |
latest = get_latest_build_summary()["workflows"]["workflow_id"] | |
while True: | |
time.sleep(5) | |
current = get_latest_build_summary() | |
if current["workflows"]["workflow_id"] != latest: | |
if current["status"] == "failed": | |
blink_failure() | |
elif current["status"] == "success": | |
blink_success() | |
else: | |
fixed_running() | |
continue | |
latest = current["workflows"]["workflow_id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blink1==0.3.1 | |
pycircleci==0.7.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment