GitHub Action for sending a notification to a Mattermost channel https://github.com/mattermost/action-mattermost-notify
  • JavaScript 100%
Find a file
2024-07-29 18:03:46 +08:00
.github feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
badges feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
dist feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
src feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
.eslintignore feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
.gitattributes feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
.gitignore feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
.nvmrc feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
.prettierignore feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
.prettierrc.json feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
action.yml feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
CODEOWNERS feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
package-lock.json feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
package.json feat: Migrate action to native js (#13) 2024-04-15 12:43:09 +03:00
README.md fix: typo on readme for MATTERMOST_ICON_URL (#17) 2024-07-29 18:03:46 +08:00

Github Action Mattermost notify

Mattermost — Send Mattermost messages. Fork/inspired from https://github.com/apex/actions/tree/master/slack

For the message format you can check the Mattermost documentation

Inputs

Input Description Default Required
MATTERMOST_WEBHOOK_URL The Mattermost Incoming Webhook URL true
MATTERMOST_CHANNEL The Mattermost channel to sent the message false
MATTERMOST_USERNAME The Mattermost username shown in the webhook false
MATTERMOST_ICON_URL The Mattermost Icon URL for the webhook false
TEXT The text for the webhook message false
PAYLOAD The payload for the webhook false
PAYLOAD_FILENAME The payload file name for the webhook (deprecated) mattermost.json false

Usage

You can use it as below:

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: mattermost/action-mattermost-notify@master
        with:
          MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
          MATTERMOST_CHANNEL: the-best-channel
          TEXT: |
            This is a message from ${{ github.repository }}.
            [Pipeline](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) was completed :white_check_mark:
          MATTERMOST_USERNAME: ${{ github.triggering_actor }}
          MATTERMOST_ICON_URL: https://cdn3.iconfinder.com/data/icons/system-basic-vol-4-1/20/icon-note-attention-alt3-512.png

or alternatively you can use the PAYLOAD input:

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: mattermost/action-mattermost-notify@master
        with:
          MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
          PAYLOAD: |-
            {
              "text": "What a message from ${{ github.repository }}",
              "channel": "the-best-channel",
              "username": "${{ github.triggering_actor }}",
              "icon": "https://cdn3.iconfinder.com/data/icons/system-basic-vol-4-1/20/icon-note-attention-alt3-512.png"
            }

Update the Action Metadata

The action.yml file defines metadata about your action, such as input(s) and output(s). For details about this file, see Metadata syntax for GitHub Actions.

When you copy this repository, update action.yml with the name, description, inputs, and outputs for your action.

Update the Action Code

The src/ directory is the heart of your action! This contains the source code that will be run when your action is invoked. You can replace the contents of this directory with your own code.

There are a few things to keep in mind when writing your action code:

  • Most GitHub Actions toolkit and CI/CD operations are processed asynchronously. In main.js, you will see that the action is run in an async function.

    const core = require('@actions/core')
    //...
    
    async function run() {
      try {
        //...
      } catch (error) {
        core.setFailed(error.message)
      }
    }
    

    For more information about the GitHub Actions toolkit, see the documentation.

So, what are you waiting for? Go ahead and start customizing your action!

  1. Create a new branch

    git checkout -b releases/v1
    
  2. Replace the contents of src/ with your action code

  3. Add tests to __tests__/ for your source code

  4. Format, test, and build the action

    npm run all
    
  5. Commit your changes

    git add .
    git commit -m "My first action is ready!"
    
  6. Push them to your repository

    git push -u origin releases/v1
    
  7. Create a pull request and get feedback on your action

  8. Merge the pull request into the main branch

Your action is now published! 🚀

For information about versioning your action, see Versioning in the GitHub Actions toolkit.