Keeping Your Sanity with `ntfy` During Long GitHub Action Builds
Waiting for a GitHub Actions build to finish can feel like watching paint dry... in slow motion... underwater. You push your code, lean back, open a tab for YouTube, and suddenly it's an hour later and youβre three conspiracy videos deep wondering if the moon is hollow β only to realize your build failed 57 minutes ago. Wouldnβt it be nice if something just told you what happened?
What is ntfy.sh?
ntfy (opens in a new tab) is a simple and effective notification service that lets you send push notifications to your phone or desktop via a pub-sub model β using just HTTP. You can post messages to a topic (aka a βchannelβ), and any device or browser subscribed to that topic receives the notification in real-time. So that you know exactly where your 400 package react native build failed while you're on the toilet.
Itβs perfect for:
- Getting alerts when your GitHub Actions build finishes (or fails in dramatic fashion).
- Letting you walk away from CI logs and touch grass without missing a beat.
- Automating all kinds of pings for jobs, scripts, or commands that take an eternity.
To get started, download the ntfy (opens in a new tab) mobile app from your app store, and subscribe to the topic (i.e., the channel name like your-ntfy-subchannel) youβll be sending to. Boom - you're in the loop.
Below are two GitHub Actions snippets:
- A simple implementation to notify on pass/fail.
- A more thorough version that tries to explain why things broke β with the same
ntfymagic.
Simple ntfy implementation for pass/fail of a build
- name: ntfy-success-notifications πβ
if: success()
run: |
curl \
-H 'X-Title: Build Successful' \
-H 'Attach: http://www.quickmeme.com/img/14/14c0f057abec6dabfc5be48cbbd0d904fef889a8781eee667984089207daf998.jpg' \
-H 'Tags: heavy_check_mark,partying_face' \
-d 'Build and deployment completed successfully' \
https://ntfy.sh/your-ntfy-subchannel
- name: ntfy-failed-notifications πβ
if: failure()
run: |
curl \
-H 'X-Title: Build failed' \
-H 'Tags: x,skull' \
-d Build failed for commit with the message '\''${{ github.event.head_commit.message }}'\'' ' \
https://ntfy.sh/your-ntfy-subchannel A more thorough set of checks
- name: failure check - installing dependencies
if: failure() && steps.install_node_dependencies.outcome == 'failure'
run: echo "FAIL_REASON=Failed to install node.js dependencies" >> $GITHUB_ENV
- name: failure check - building app
if: failure() && steps.build_app.outcome == 'failure'
run: echo "FAIL_REASON=Failed to build the app" >> $GITHUB_ENV
- name: failure check - ftp deploy
if: failure() && steps.ftp_deploy.outcome == 'failure'
run: echo "FAIL_REASON=Failed to deploy to cPanel" >> $GITHUB_ENV
- name: ntfy-success-notifications πβ
if: success()
run: |
curl \
-H 'X-Title: Build Successful' \
-H 'Attach: http://www.quickmeme.com/img/14/14c0f057abec6dabfc5be48cbbd0d904fef889a8781eee667984089207daf998.jpg' \
-H 'Tags: heavy_check_mark,partying_face' \
-d 'Build and deployment completed successfully' \
https://ntfy.sh/your-ntfy-subchannel
- name: ntfy-failed-notifications πβ
if: failure()
run: |
curl \
-H 'X-Title: Build failed' \
-H 'Tags: x,skull' \
-d '${{env.FAIL_REASON}} for commit with the message '\''${{ github.event.head_commit.message }}'\'' ' \
https://ntfy.sh/your-ntfy-subchannel