DEV Community

Michal Moczulski
Michal Moczulski

Posted on

🔊 Say Github - monitoring Github Workflow

Introduction

Disclaimer: Presented solution applies to OS X but the general idea can be easily adjusted to other systems.

Recently I have found a great tool called saydle. It's a simple Gradle wrapper that notifies you using say command when your build is completed.

I think it's a great example of improving everyday workflow with simple system command. I run many Android builds on daily basis using Github CI, so I've started thinking about similar solution for notifying me when my Github Workflow is completed.

Solution - 1st approach

After doing quick research, it turned out that I've already had all the necessary components to monitor Github Workflow.

I used Github command line tool to be notified when a workflow is completed.

gh run watch <run-id> && say "Workflow completed"
Enter fullscreen mode Exit fullscreen mode

Run id can be obtained directly from the workflow URL or the workflow list command

gh run list
Enter fullscreen mode Exit fullscreen mode

System notification - 2nd approach

Going a step further I've thought that relying on sound maybe it's not the best option. I've decided to display system notification instead of using say command. For displaying notification I used terminal-notifier tool which is pretty straightforward to use.

gh run watch <run-id> && terminal-notifier -message 'Workflow completed'
Enter fullscreen mode Exit fullscreen mode

Clickable notification - my final approach

At this moment I was pretty happy with my current solution but then I thought that clickable notification taking me directly to the Github Workflow result page would be even cooler.

After checking that terminal-notifier supports URL parameter I created a simple script.

#!/usr/bin/env bash

WORKFLOW_ID=$1
URL=https://github.com/<USERNAME>/<PROJECT>/actions/runs/$WORKFLOW_ID
gh run watch $WORKFLOW_ID && terminal-notifier -message 'Workflow completed' -open $URL
Enter fullscreen mode Exit fullscreen mode

Usage is simple:

./monitor-workflow <run-id>
Enter fullscreen mode Exit fullscreen mode

After my workflow was completed I've got the notification:

System notification

And as expected, clicking it took me to the result page.

Summary

It took me around 20 minutes to build the final version. It helps me save time every day while I'm waiting for my Android builds.

Maybe this solution won't fit your needs, but I want to encourage you to create tools that work for you. Creating custom solutions with all the great tools out there is now simpler than ever before.

Happy hacking :)

Top comments (0)