-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
on: [push] | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
hello_world_job: | ||
github-release-to-discord: | ||
runs-on: ubuntu-latest | ||
name: A job to say hello | ||
steps: | ||
# To use this repository's private action, | ||
# you must check out the repository | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Hello world action step | ||
- name: Handle Release | ||
uses: ./ # Uses an action in the root directory | ||
id: hello | ||
id: release | ||
with: | ||
who-to-greet: 'Mona the Octocat' | ||
# Use the output from the `hello` step | ||
- name: Get the output time | ||
run: echo "The time was ${{ steps.hello.outputs.time }}" | ||
webhook_url: ${{ secrets.WEBHOOK_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
name: 'Hello World' | ||
description: 'Greet someone and record the time' | ||
name: Github Releases To Discord | ||
description: Send automatic styled releases to Discord. | ||
inputs: | ||
who-to-greet: # id of input | ||
description: 'Who to greet' | ||
webhook_url: | ||
description: Discord's webhook url. Use GH repo secrets. | ||
required: true | ||
default: 'World' | ||
outputs: | ||
time: # id of output | ||
description: 'The time we greeted you' | ||
runs: | ||
using: 'node16' | ||
main: 'index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,52 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
|
||
try { | ||
// `who-to-greet` input defined in action metadata file | ||
const nameToGreet = core.getInput('who-to-greet'); | ||
console.log(`Hello ${nameToGreet}!`); | ||
const time = (new Date()).toTimeString(); | ||
core.setOutput("time", time); | ||
// Get the JSON webhook payload for the event that triggered the workflow | ||
const payload = JSON.stringify(github.context.payload, undefined, 2) | ||
console.log(`The event payload: ${payload}`); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
const fetch = require('node-fetch') | ||
|
||
async function getContext () { | ||
const payload = github.context.payload | ||
|
||
return { | ||
body: payload.release.body.length < 1500 | ||
? payload.release.body | ||
: payload.release.body.substring(0, 1500) + ` ([...](${payload.release.html_url}))`, | ||
version: payload.release.tag_name, | ||
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() |