mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-14 20:13:23 +00:00
feat: updated action
This commit is contained in:
@@ -1,19 +1,15 @@
|
|||||||
on: [push]
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
hello_world_job:
|
github-release-to-discord:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: A job to say hello
|
|
||||||
steps:
|
steps:
|
||||||
# To use this repository's private action,
|
|
||||||
# you must check out the repository
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Hello world action step
|
- name: Handle Release
|
||||||
uses: ./ # Uses an action in the root directory
|
uses: ./ # Uses an action in the root directory
|
||||||
id: hello
|
id: release
|
||||||
with:
|
with:
|
||||||
who-to-greet: 'Mona the Octocat'
|
webhook_url: ${{ secrets.WEBHOOK_URL }}
|
||||||
# Use the output from the `hello` step
|
|
||||||
- name: Get the output time
|
|
||||||
run: echo "The time was ${{ steps.hello.outputs.time }}"
|
|
||||||
+4
-8
@@ -1,13 +1,9 @@
|
|||||||
name: 'Hello World'
|
name: Github Releases To Discord
|
||||||
description: 'Greet someone and record the time'
|
description: Send automatic styled releases to Discord.
|
||||||
inputs:
|
inputs:
|
||||||
who-to-greet: # id of input
|
webhook_url:
|
||||||
description: 'Who to greet'
|
description: Discord's webhook url. Use GH repo secrets.
|
||||||
required: true
|
required: true
|
||||||
default: 'World'
|
|
||||||
outputs:
|
|
||||||
time: # id of output
|
|
||||||
description: 'The time we greeted you'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
main: 'index.js'
|
main: 'index.js'
|
||||||
@@ -1,15 +1,52 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const github = require('@actions/github');
|
const github = require('@actions/github');
|
||||||
|
|
||||||
try {
|
const fetch = require('node-fetch')
|
||||||
// `who-to-greet` input defined in action metadata file
|
|
||||||
const nameToGreet = core.getInput('who-to-greet');
|
async function getContext () {
|
||||||
console.log(`Hello ${nameToGreet}!`);
|
const payload = github.context.payload
|
||||||
const time = (new Date()).toTimeString();
|
|
||||||
core.setOutput("time", time);
|
return {
|
||||||
// Get the JSON webhook payload for the event that triggered the workflow
|
body: payload.release.body.length < 1500
|
||||||
const payload = JSON.stringify(github.context.payload, undefined, 2)
|
? payload.release.body
|
||||||
console.log(`The event payload: ${payload}`);
|
: payload.release.body.substring(0, 1500) + ` ([...](${payload.release.html_url}))`,
|
||||||
} catch (error) {
|
version: payload.release.tag_name,
|
||||||
core.setFailed(error.message);
|
html_url: payload.release.html_url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function run () {
|
||||||
|
try {
|
||||||
|
const webhookUrl = core.getInput('webhook_url')
|
||||||
|
|
||||||
|
if (!webhookUrl) {
|
||||||
|
return core.setFailed('webhook_url not set. Please set it.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = await getContext()
|
||||||
|
|
||||||
|
const embedMsg = {
|
||||||
|
color: 3447003,
|
||||||
|
title: `Release ${content.version}`,
|
||||||
|
description: content.body,
|
||||||
|
url: content.html_url
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = { embeds: [embedMsg] }
|
||||||
|
|
||||||
|
const url = `${webhookUrl}?wait=true`
|
||||||
|
|
||||||
|
fetch(url, {
|
||||||
|
method: 'post',
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => core.info(JSON.stringify(data)))
|
||||||
|
.catch(err => core.info(err))
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
Reference in New Issue
Block a user