Giter Club home page Giter Club logo

action-discord's Introduction

๐Ÿš€ Discord for GitHub Actions

Build Status

Sends a Discord notification message. Simple as that. Supports all workflow event types by using the Discord GitHub webhooks.

Appearance on Discord :

Discord message

This GitHub action is part of a list of Actions that are located in an other repo. Feel free to check it out : https://github.com/Ilshidur/actions.

Compatibility note

As this Action is containerized with Docker, it can only run on Linux environments.

Docker container actions can only execute in the GitHub-hosted Linux environment. Self-hosted runners must use a Linux operating system and have Docker installed to run Docker container actions. For more information about the requirements of self-hosted runners, see "About self-hosted runners."


Usage

- name: Discord notification
  env:
    DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
  uses: Ilshidur/action-discord@master
  with:
    args: 'The project {{ EVENT_PAYLOAD.repository.full_name }} has been deployed.'

NOTICE : for stability purposes, it is recommended to use the action with an explicit commit SHA-1 :

Arguments

By default, the GitHub action will send a notificaction with the event informations. Providing the arguments will override the message.

Environment variables can be interpolated in the message using brackets ({{ and }}) :

e.g.: Action called : {{ GITHUB_ACTION }}

Event Payload data can also be interpolated in the message using brackets ({{ and }}) with the EVENT_PAYLOAD variable.

e.g.: Action called: {{ GITHUB_ACTION }} as {{ EVENT_PAYLOAD.pull_request.id }}

See the event types for valid payload informations.

Examples

  • args = "Hello, beautiful ! I ran a GitHub Actions for you <3"
  • args = "I showed you my commit. Please respond."

Environment variables

Alternatives

Because open source is about everyone :

https://github.com/marketplace/actions/discord-message-notify

TODO


Don't forget to ๐ŸŒŸ Star ๐ŸŒŸ the repo if you like this GitHub Action !
Your feedback is appreciated

action-discord's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

action-discord's Issues

Receive an Error Message when trying to use DISCORD_EMBEDS

Receive an Error Message when trying to use DISCORD_EMBEDS.

The error:

Error : 400 Bad Request
Message : { embeds: [ '0' ] }

The configurations:

    - name: Discord notification
        env:
          DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
          DISCORD_EMBEDS :  "{\"embeds\":[{\"title\":\"Meow!\",\"color\":1127128},{\"title\":\"Meow-meow!\",\"color\":14177041}]}"        
        uses: Ilshidur/[email protected]
        with:
          args: "Message"

When used without DISCORD_EMBEDS, this works fine.

Error : 400 Bad Request

action trigger by schedule task

on:
  push:
    branches:
      - master
  schedule:
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule
#            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ minute (0 - 59)
#            โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ hour (0 - 23)
#            โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ day of the month (1 - 31)
#            โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ month (1 - 12 or JAN-DEC)
#            โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ day of the week (0 - 6 or SUN-SAT)
#            โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
#            โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
#            โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
#            * * * * *
    - cron: '0 0 * * 1'
    - cron: '0 0 * * 5'

image

Sending message ...
Error : 400 Bad Request
Message : { sender: [ 'This field is required' ] }

Default message not working?

I've tried running the action with no args to replicate the embed example in the README but no messages is being sent.
What is required to send that message?

Clarify how to notify on pull request events

Can you provide an example of notifying Discord on pull request? Is that supposed to be a supported event type?

It used to work for me using the pull_request event type, but related to a GitHub security change that broke recently with an error Env var DISCORD_WEBHOOK not defined, apparently unable to access secrets (see #71). I tried changing it to pull_request_target, and that now runs without errors but doesn't post anything to Discord.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
  • mhart/alpine-node 12.19.1
github-actions
.github/workflows/main.yml
npm
package.json
  • axios 0.21.1
  • lodash 4.17.21
  • yargs 16.2.0
  • dotenv 8.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Action fails/crashes

The action sometimes fails with the following error:

internal/fs/utils.js:269
9
    throw err;
10
    ^
11

12
Error: ENOENT: no such file or directory, open '/github/workflow/event.json'
13
    at Object.openSync (fs.js:462:3)
14
    at Object.readFileSync (fs.js:364:35)
15
    at Object.<anonymous> (/entrypoint.js:27:25)
16
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
17
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
18
    at Module.load (internal/modules/cjs/loader.js:985:32)
19
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
20
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
21
    at internal/main/run_main_module.js:17:47 {
22
  errno: -2,
23
  syscall: 'open',
24
  code: 'ENOENT',
25
  path: '/github/workflow/event.json'
26
}

"Env var DISCORD_WEBHOOK not defined" when run on push

I've been getting this error since like a week or so now. It only happens when the workflow is triggered automatically by the push event:

grafik

But as soon as I re-run the job, it works fine:

grafik

Idk if I'm just doing something wrong or if there's a bug so that's why I'm opening an issue.
I've double checked the DISCORD_WEBHOOK secret exists and is correct.

Here's the relevant part of the workflow YAML file (full file here):

    - name: Discord success notification # sends a Discord notification
      env:
        DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
      uses: Ilshidur/action-discord@master
      with:
        args: 'โœ… **JokeAPI CI** (triggered by `{{GITHUB_ACTOR}}` on `{{GITHUB_REF}}`) was successful (see https://github.com/Sv443/JokeAPI/commit/{{GITHUB_SHA}}/checks)' 
    - name: Discord failure notification # sends a Discord notification
      env:
        DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
      uses: Ilshidur/action-discord@master
      with:
        args: '๐Ÿšซ **JokeAPI CI** (triggered by `{{GITHUB_ACTOR}}` on `{{GITHUB_REF}}`) has failed (see https://github.com/Sv443/JokeAPI/commit/{{GITHUB_SHA}}/checks)'
      if: failure()

Workflow failing when DISCORD_EMBEDS contain double quotes

Trying to use a single action for sending a pass/fail notification but unable to use the ternary in DISCORD_EMBEDS as it contains double quotes.

Step:

- name: Build and push
  id: build-and-push
  ...
- name: Build success Discord notification
  if: always()
  env:
    DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
    DISCORD_EMBEDS: '[{ 
      "author": { "name": "${{github.event.pusher.full_name}}", "icon_url": "${{github.event.pusher.avatar_url}}" }, 
      "description": "${{github.event.repository.name}}: Build ${{github.run_number}} has ${{ steps.build-and-push.outcome == "success && "passed!" || "failed." }}",
      "timestamp": "${{ steps.current-time.outputs.time }}",
      "footer":{"text": " "}
    }]'
  uses: Ilshidur/[email protected]

Workflow failing with output

Sending message ...
Error : 400 Bad Request
Message : { sender: [ 'html_url' ] }

Currently using 2 separate actions with success() and failure() for now, but hoping this issue can be resolved so that the codes will not need to be repeated.

Related issue: #122

Error: ENOENT: no such file or directory, open '/var/run/act/workflow/event.json'

I'm using https://github.com/actionsflow/actionsflow. And this is my repo which can reproduce it: https://github.com/Discreater/actionsflow .

[0-curseforge-script.yml/send to discord 0 ]   ๐Ÿณ  docker build -t act-ilshidur-action-discord-0-3-2:latest --platform  /home/runner/.cache/act/[email protected]
[0-curseforge-script.yml/send to discord 0 ]   ๐Ÿณ  docker run image=act-ilshidur-action-discord-0-3-2:latest platform= entrypoint=[] cmd=["new" "2" "released:" "JustEnoughCalculation-1.15.2-3.6.1.jar"]
[0-curseforge-script.yml/send to discord 0 ]   | internal/fs/utils.js:269
[0-curseforge-script.yml/send to discord 0 ]   |     throw err;
[0-curseforge-script.yml/send to discord 0 ]   |     ^
[0-curseforge-script.yml/send to discord 0 ]   | 
[0-curseforge-script.yml/send to discord 0 ]   | Error: ENOENT: no such file or directory, open '/var/run/act/workflow/event.json'
[0-curseforge-script.yml/send to discord 0 ]   |     at Object.openSync (fs.js:462:3)
[0-curseforge-script.yml/send to discord 0 ]   |     at Object.readFileSync (fs.js:364:35)
[0-curseforge-script.yml/send to discord 0 ]   |     at Object.<anonymous> (/entrypoint.js:27:25)
[0-curseforge-script.yml/send to discord 0 ]   |     at Module._compile (internal/modules/cjs/loader.js:1015:30)
[0-curseforge-script.yml/send to discord 0 ]   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
[0-curseforge-script.yml/send to discord 0 ]   |     at Module.load (internal/modules/cjs/loader.js:879:32)
[0-curseforge-script.yml/send to discord 0 ]   |     at Function.Module._load (internal/modules/cjs/loader.js:724:14)
[0-curseforge-script.yml/send to discord 0 ]   |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
[0-curseforge-script.yml/send to discord 0 ]   |     at internal/main/run_main_module.js:17:47 {
[0-curseforge-script.yml/send to discord 0 ]   |   errno: -2,
[0-curseforge-script.yml/send to discord 0 ]   |   syscall: 'open',
[0-curseforge-script.yml/send to discord 0 ]   |   code: 'ENOENT',
[0-curseforge-script.yml/send to discord 0 ]   |   path: '/var/run/act/workflow/event.json'
[0-curseforge-script.yml/send to discord 0 ]   | }
Error: exit with `FAILURE`: 1
[0-curseforge-script.yml/send to discord 0 ]   โŒ  Failure - Actions for Discord
Error: Process completed with exit code 1.

Github Marketplace metadata incorrect for "latest version" value

I've just started integrating this action into our project, and just so happened to realise that the tags on the repo don't match up with the "use latest version" metadata on the marketplace page https://github.com/marketplace/actions/actions-for-discord - clicking the button gives this popup:

Screenshot_20210617_144200

I had a quick look into the documentation for publishing an action to see how to change that value so that I could submit a PR fixing it, but that mentions a required action.yml or action.yaml file which doesn't appear to be anywhere in this or your main actions repo.

Use GitHub environment variables in the Discord message

Hi!
I was trying to add the commit SHA to the Discord message using the env.GITHUB_SHA GitHub environment variable. But no matter how I tried to do this, it never worked out.
I want to achieve a message like this:

CI run was successful.
https://github.com/Sv443/Project/[COMMIT_SHA_HERE]/actions

I've never really used bash, nor did I ever use this GitHub action, so please tell me how I could achieve this or whether you could add this feature.

message variable support for string manipulation?

I see you can use variables with {{ variable }}. does it support bash variable manipulation such as ${github_ref#refs/tags/ }

this would provide the tag without the refs/tags/ prefix so a message could look like "Build started for {{ github_repository }} version {{ github_ref#refs/tags/ }}" would look like "Build started for REPO version X". or is there a better way to do this?

Do I have to be Discord-Server owner/admin?

Is it possible to post a message on any discord server I like or do I have to be admin to create and provide the webhook url?
Can I use my discord credentials to post a message with my discord account?

To clarify stuff:
I am implementing a mod for a specific game. There is a discord server for this game with a mod-release channel, where I would like to post a message everytime there is a new tag/release on github.

Any possibility to do so? (Because I am lazy and love to automate stuff)

Thanks in advantage!

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.