Giter Site home page Giter Site logo

sarisia / actions-status-discord Goto Github PK

View Code? Open in Web Editor NEW
168.0 2.0 22.0 5.79 MB

Post GitHub Actions status to Discord as an beautiful embed

License: MIT License

TypeScript 99.74% JavaScript 0.14% Dockerfile 0.13%
github-actions discord discord-webhook webhook

actions-status-discord's Introduction

Actions Status Discord

Post GitHub Actions status to Discord as an beautiful embed

image

  • 🍣 Super Easy! Works perfectly out of the box.
  • 🍣 OS & Arch-agnostic! Supports Linux (Ubuntu), macOS (Intel, M1) and Windows runners.
  • 🍣 Fast! Faster than ones written as Docker container action.

⚠️ If you're reading this document in master branch, please refer to the latest released document here.

Usage

Minimum

- uses: sarisia/actions-status-discord@v1
  if: always()
  with:
    webhook: ${{ secrets.DISCORD_WEBHOOK }}

image

Full options

- uses: sarisia/actions-status-discord@v1
  if: always()
  with:
    webhook: ${{ secrets.DISCORD_WEBHOOK }}
    status: ${{ job.status }}
    content: "Hey <@316911818725392384>"
    title: "deploy"
    description: "Build and deploy to GitHub Pages"
    image: ${{ secrets.EMBED_IMAGE }}
    color: 0x0000ff
    url: "https://github.com/sarisia/actions-status-discord"
    username: GitHub Actions
    avatar_url: ${{ secrets.AVATAR_URL }}

image

No detail

- uses: sarisia/actions-status-discord@v1
  if: always()
  with:
    webhook: ${{ secrets.DISCORD_WEBHOOK }}
    nodetail: true
    title: "New version of `software` is ready!"
    description: |
      Version `${{ github.event.release.tag_name }}`
      Click [here](${{ github.event.release.html_url }}) to download!
    color: 0xff91a4

image

For if parameter, see GitHub Actions Reference

Configuration

Environment Variables

Key Value Description
DISCORD_WEBHOOK Discord webhook endpoind like:
https://discordapp.com/api/webhooks/...
You can provide webhook via inputs either.
DO NOT APPEND /github SUFFIX!

Inputs

General customizations

Key Required Value Default Description
webhook No String env.DISCORD_WEBHOOK Discord webhook endpoind like:
https://discordapp.com/api/webhooks/...
This overrides env.DISCORD_WEBHOOK.
DO NOT APPEND /github SUFFIX!
status No Success, Failure or Cancelled ${{ job.status }} See Document for job context
content No String Content. Shown as an message outside of the embed. See Mention to user/role
title No String ${{ github.workflow}} String included in embed title. Overrides job input.
description No String Description included in message
image No String Image attached to the message
color No Hex string like: 0xFFFFFF Overrides Discord embed color
url No String URL to jump when the title is clicked
username No String Overrides Discord webhook username
avatar_url No String Overrides Discord webhook avatar url

Advanced usages

Key Required Value Default Description
nofail No true or false true This action won't make workflow failed by default. If set to false, this action will set status failed when failed to notify.
nocontext No true or false false Set true to suppress GitHub context fields (Repository, Ref, etc).
noprefix No true or false false Set true to avoid appending job status (Success: , etc.) to title
nodetail No true or false false Set true will set both nocontext and noprefix to true
notimestamp No true or false false Set true to avoid appending timestamp
ack_no_webhook No true or false false Set true to suppress warnings when no Webhook endpoint is given
Show deprecated
Key Required Value Default Description
job No String Deprecated. Will be removed in v2
Job name included in message title. Same as title input.

Outputs

Key Description
payload Discord webhook payload. See Full payload control

Tips

Using markdown

Some fields support markdown syntax.

- uses: sarisia/actions-status-discord@v1
  with:
    webhook: ${{ secrets.DISCORD_WEBHOOK }}
    nodetail: true
    title: "New version of `software` is ready!"
    description: |
      Version `${{ github.event.release.tag_name }}`
      Click [here](${{ github.event.release.html_url }}) to download!
    color: 0xff91a4

image

Mention to user/role

Since @mention inside the embed does not generate ping to users, you can use content input to mention users/roles:

- uses: sarisia/actions-status-discord@v1
  if: always()
  with:
    webhook: ${{ secrets.DISCORD_WEBHOOK }}
    content: "Hey <@316911818725392384>"

See the Discord Developer Docs for available formats.

Trigger multiple webhooks

You can set multiple webhooks separated with EOL (line break, \n) to Secrets.

For example, set Secrets to:

https://discordapp.com/api/webhooks/...
https://media.guilded.gg/webhooks/...
https://this-is-invalid-webhook-endpoint.invalid/...

will trigger these 3 webhooks simultaneously.

If some of these webhooks are failed, other deliveries will NOT be cancelled.

If the option nofail is set to false and any of one fail, the action will set workflow status to Failure.

Full payload control

You can modify payload before sending to Discord:

- uses: sarisia/actions-status-discord@v1
  if: always()
  id: webhook # set id to reference output payload later
  with:
    ack_no_webhook: true # set this to suppress warning
    # you can omit webhook input (or DISCORD_WEBHOOK environment variable)
  
- run: npm install axios
- uses: actions/github-script@v7
  env:
    WEBHOOK_PAYLOAD: ${{ steps.webhook.outputs.payload }}
    WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK }}
  with:
    script: |
      const axios = require("axios")

      const { WEBHOOK_PAYLOAD, WEBHOOK_URL } = process.env

      const payload = JSON.parse(WEBHOOK_PAYLOAD)

      // modify payload as you like
      delete payload.embeds[0].color

      // send to Discord
      axios.post(WEBHOOK_URL, payload)

See actions/github-script docs

GHES, Gitea and Forgejo

This actions may work with GHES, Gitea and Forgejo, but not tested against yet.

If you have any issues, please let us know in Discussions or Issues.

Guilded webhook support

As Guilded supports Discord Webhooks API, you can use Guilded webhook endpoint in the same way as Discord webhook.

Verifying Artifact Attestations

This action is shipped with Artifact attestations for action.yml and lib/index.js.

You can verify these files with GitHub CLI:

$ gh attestation verify --repo sarisia/actions-status-discord lib/index.js
Loaded digest sha256:4cc20dac6053670b29ff3ae8b9ddeafeed73fe79e5ab31fd8e34b6acd44d30c3 for file://lib/index.js
Loaded 1 attestation from GitHub API
βœ“ Verification succeeded!

sha256:4cc20dac6053670b29ff3ae8b9ddeafeed73fe79e5ab31fd8e34b6acd44d30c3 was attested by:
REPO                            PREDICATE_TYPE                  WORKFLOW                                              
sarisia/actions-status-discord  https://slsa.dev/provenance/v1  .github/workflows/release.yml@refs/tags/v.1.14.3-pre.0

FAQ

Error: Webhook response: 400: {"sender":["This field is required"]}

Do not append /github suffix to your webhook URL. See Inputs section.

Questions? Bugs?

Feel free to ask in Discussions, or report bugs in Issues!

actions-status-discord's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar kisaragieffective avatar kobew50 avatar meisnate12 avatar nextfire avatar riskymh avatar sarisia avatar weslleynasrocha avatar

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

actions-status-discord's Issues

Tag user or role on discord

Discussed in #387

Originally posted by murilomorato December 15, 2022
I created a server to receive alerts whenever a deploy fails, but I haven't been receiving notifications alerts.
I tried to insert inside the 'description' prop my Role tag and my user id. They arrive tagged in the discord message, but it does not generate the notification, as I believe the message arrives as a kind of 'quote', not as a normal message.

Have you tried any alternatives yet?

ThanksπŸ˜‰

Workflow link points to a non-existent commit on pull requests

Issue description

For workflows triggered by pull_request events, the workflow link points to a commit that does not belong to the repository.

For example,
image
the link above goes to https://github.com/GiganticMinecraft/SeichiAssist/commit/695bf7133c95640b663f4e817f84f300874ca809/checks, while I expect it to go to https://github.com/GiganticMinecraft/SeichiAssist/commit/2cb1b549800285c790832a45d71e17e21fd85faf/checks.

I believe the link uses SHA hash of a merge commit automatically generated by Actions, which is different from github.sha.
EDIT: My bad, this is in fact the expected github.sha, but would it be reasonable to use github.event.pull_request.head.sha when this is available?

Reproduction

Set up a workflow with sarisia/actions-status-discord@v1, trigger it with pull_request event and check the link generated for "Workflow" column.

Full workflow file

fix e2e in release workflow

  • do not use v1 tag
  • use upload-artifact and download-artifact
    • since we cannot build this action with devcontainer in macos (macos runner does not have docker!)
    • maybe checking out the tag ref is log easier

question

Hi.

Are it's possible to set ${{ job.status }} - so It will display on actions, if it has been success or failed?

Because it does not work for me. ;/

Customizable description

This workflow currently runs for us to notify of a push to a branch. The description shows the title of that PR, but it would be ideal if we could list the title of each commit included with that PR. Currently looking into what data you are getting back from github and if this is even an option, but figured I would toss it here if anyone knows of a better way to accomplish this. Great action.

Suggestion: status-defined image and descriptions

Hello,
I'm unable to do this myself, but a suggestion I have and would appreciate if implemented, is enabling the option to have a custom image and description per status, for success, cancellation and failure.

I've partially hardcoded this on my own fork to create the following real world example:
image

use devcontainer image in ci

  • use devcontainer-cli to build & publish devcontainer image
  • use that devcontainer image in devcontainer.json AND GitHub Actions Workflows

Have a way to override the `fields` embed (or at least the `eventDetail` part of the fields)

Hi !

It would be cool if there was a way to override the fields part of the embed.

I really like the display of the message when using fields but, sometimes, the eventDetail part is huge (when squash merging a PR with lots of commits, github's default is to append all the commit message to the merge commit message).

Currently, there is no way to reproduce the display of what the fields embed do and passing nocontext remove the fields entirely.

What do you think about adding an option which, when provided, override the eventDetail value ?


Something event more flexible would be to be able to pass an option with the entire fields array but I'm not sure if it's possible to passe something like:

with:
  fields: ${{ fromJSON('[{"name":"Repository","value":"...","inline":true},{"name":"Ref","value":"...","inline":true},{"name":"Event","value":"...","inline":false},{"name":"Triggered by","value":"...","inline":true},{"name":"Workflow","value":"...","inline":true}]') }}

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

Automerging is not enabled for this account. You can enable it from the [account settings](https://app.dependabot.com/accounts/sarisia/settings) screen in your Dependabot dashboard.

Please update the config file to conform with Dependabot's specification using our docs and online validator.

I'm not seeing how this works, can you help?

I'm newer to github actions and I'm just not seeing where/how the scripts runs so I can look at the javascript that is actually running.

In actions.yml it says:

runs:
  using: "node20"
  main: "lib/index.js"

I don't see /lib/index.js anywhere in the project directory, where is this file being called from? -- I'm interested in looking at the js itself to see what's happening and try to learn from it.

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.