Coder Social home page Coder Social logo

campfire-notify-action's Introduction

Campfire notification GitHub Action

Get notified of GitHub events (commit pushed, job failed) through an action that posts messages into your ONCE Campfire chat.

Post commit info on push

Use the commit_pushed template to get a helpful summary in chat when someone pushes a commit to main. It looks like this:

commit message example

Post notification when GitHub workflow job fails

If my workflow failed after pushing the commit from the previous screenshot, here's how the notification message would look using the job_failed template:

job failed message example.png

Usage

Step 1: Create a bot

Creating a bot through Campfire, you'll end up on a screen like this:

bot secret

Here I've named the bot "GitHub" and uploaded a matching icon as the profile picture.

Each room has a unique curl command that you can use to post messages to that room.

Locate the room you'd like to use with this action, and then copy the URL portion to use as a secret for the next step.

Step 2: Create secret in your GitHub repo

You'll need to create a secret in your repo in order to securely pass the necessary details to the action, so that it's able to post into the Campfire room.

Save the URL (the last part of the curl command, not the whole thing) into a new secret. The URL acts as both an endpoint and a key, so no other details are needed. For the following examples I've named the secret CAMPFIRE_MESSAGES_URL.

Step 3: Add the action to your workflow

How you add the action to your workflow is based on the desired template/event type.

commit_pushed

If you're using the commit_pushed template, you'll want to trigger a workflow on push to your main branch.

It's convenient to have a dedicated workflow yaml file for this purpose. Here's an example:

.github/workflows/post-commit-info.yml:

name: Post commit info

on:
   push:
      branches: [ main ]

jobs:
   post-commit-info:
      runs-on: ubuntu-latest

      steps:
         - name: Post commit info to Campfire
           uses: shane-lamb/[email protected]
           with:
              messages_url: ${{ secrets.CAMPFIRE_MESSAGES_URL }}
              template: commit_pushed

You can change the branch name if you're not using main as your development branch.

job_failed

For the job_failed template, instead of creating a new workflow, you'll want to add a step at the end of each job you'd like to monitor for failure.

Here's how you can add the action into the steps list of your existing job/s:

steps:
   - name: Checkout
     uses: actions/checkout@v4

   - name: Do stuff that might fail
     uses: ...

   - name: Post job failure details to Campfire
     if: failure() && github.ref == 'refs/heads/main'
     uses: shane-lamb/[email protected]
     with:
        messages_url: ${{ secrets.CAMPFIRE_MESSAGES_URL }}
        template: job_failed

The if condition ensures that it'll only notify if the job has failed.

This example has an additional condition to only notify if the branch is main, as you might not want the noise coming from feature branch builds.

Development

This repo was initialised using the typescript-action GitHub action template.

Format, test, and build the action

npm run all

Publishing a New Release

This project includes a helper script, script/release designed to streamline the process of tagging and pushing new releases for GitHub Actions.

GitHub Actions allows users to select a specific version of the action to use, based on release tags. This script simplifies this process by performing the following steps:

  1. Retrieving the latest release tag: The script starts by fetching the most recent release tag by looking at the local data available in your repository.
  2. Prompting for a new release tag: The user is then prompted to enter a new release tag. To assist with this, the script displays the latest release tag and provides a regular expression to validate the format of the new tag.
  3. Tagging the new release: Once a valid new tag is entered, the script tags the new release.
  4. Pushing the new tag to the remote: Finally, the script pushes the new tag to the remote repository. From here, you will need to create a new release in GitHub and users can easily reference the new tag in their workflows.

campfire-notify-action's People

Contributors

dependabot[bot] avatar devnacho avatar shane-lamb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.