Keeping Your Sanity with `ntfy` During Long GitHub Action Builds

You,β€’web developmentci/cd

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:

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:

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