Compare commits

...
33 Commits
Author SHA1 Message Date
SethCohen c811a53b57 chore(master): release 1.13.0 (#19) 2022-08-24 20:56:59 -04:00
SethCohen e67e0f9064 refactor: added JSDocs, created more descriptive functions 2022-08-24 20:51:13 -04:00
SethCohen d76d7aafe4 feat: created test action 2022-08-24 20:05:42 -04:00
SethCohen a809bb6f0e Merge pull request #18 from iCiaran/rename-context-variables
refactor: rename variables returned from getContext
2022-08-24 16:27:50 -04:00
Ciaran Moran 998060befe refactor: rename variables returned from getContext 2022-08-24 21:19:37 +01:00
SethCohen 27e9acb517 chore: updated README.md 2022-08-24 02:26:40 -04:00
SethCohen d019e5acd9 Merge pull request #17 from SethCohen/release-please--branches--master--components--release-please-action
chore(master): release 1.12.1
2022-08-24 01:50:47 -04:00
SethCohen 9e0e0c94da chore(master): release 1.12.1 2022-08-24 01:50:33 -04:00
SethCohen 6aea64bf70 chore: release 1.12.1
Release-As: 1.12.1
2022-08-24 01:50:08 -04:00
SethCohen 234bc3b25f chore: updated workflow actions 2022-08-24 01:46:57 -04:00
SethCohen 6df64644c1 chore: updated README.md 2022-08-24 01:46:50 -04:00
SethCohen a5abfa09d3 Merge pull request #16 from SethCohen/release-please--branches--master--components--release-please-action
chore(master): release 1.12.0
2022-08-24 01:19:34 -04:00
SethCohen a49a5347be chore(master): release 1.12.0 2022-08-24 01:19:23 -04:00
SethCohen a0914f433a feat: renamed all colour>color 2022-08-24 01:18:46 -04:00
SethCohen 7f6cee8772 Merge pull request #15 from SethCohen/add-license-1
chore: created LICENSE
2022-08-24 01:13:23 -04:00
SethCohen 6382bf4bfb chore: created LICENSE 2022-08-24 01:13:14 -04:00
SethCohen 3a1a5b68a2 Merge remote-tracking branch 'origin/master' 2022-08-24 01:10:33 -04:00
SethCohen 6a018ddca1 chore: updated action workflow 2022-08-24 01:10:25 -04:00
SethCohen 8c4da10759 chore: updated README.md 2022-08-24 01:10:14 -04:00
SethCohen 8ebec0c4c4 Merge pull request #14 from SethCohen/release-please--branches--master--components--release-please-action
chore(master): release 1.11.1
2022-08-24 01:01:59 -04:00
SethCohen 8212a24dfa chore(master): release 1.11.1 2022-08-24 01:01:07 -04:00
SethCohen 233db9c33f fix: fixed ReferenceError on require vs import 2022-08-24 01:00:48 -04:00
SethCohen 5001ed03b7 Merge pull request #13 from SethCohen/release-please--branches--master--components--release-please-action
chore(master): release 1.11.0
2022-08-24 00:59:13 -04:00
SethCohen f7e8576166 chore(master): release 1.11.0 2022-08-24 00:58:49 -04:00
SethCohen baa4c82901 fix: fixed version tag 2022-08-24 00:58:31 -04:00
SethCohen aea0a60ccd feat: updated package.json 2022-08-24 00:55:19 -04:00
SethCohen e49c674890 feat: updated action.yml 2022-08-24 00:55:06 -04:00
SethCohen f84f12e7b0 Merge pull request #12 from SethCohen/release-please--branches--master--components--release-please-action
chore(master): release 1.10.1
2022-08-24 00:48:15 -04:00
SethCohen c64205076b chore(master): release 1.10.1 2022-08-24 00:47:07 -04:00
SethCohen e384a39c62 Merge remote-tracking branch 'origin/master' 2022-08-24 00:46:50 -04:00
SethCohen 0e4e0d83ff fix: fixed fetch import 2022-08-24 00:46:44 -04:00
SethCohen 54e99ee992 Merge remote-tracking branch 'origin/master' 2022-08-24 00:40:49 -04:00
SethCohen baad0090bf fixed: fixed fetch import 2022-08-24 00:40:43 -04:00
10 changed files with 205 additions and 91 deletions
-18
View File
@@ -1,18 +0,0 @@
on:
release:
types: [published]
name: github-release-to-discord
jobs:
github-release-to-discord:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Handle Release
uses: ./ # Uses an action in the root directory
id: release
with:
webhook_url: ${{ secrets.WEBHOOK_URL }}
colour: "7766090"
username: "tes"
avatar_url: "https://i.imgur.com/UPbV3Nx.png"
+14
View File
@@ -0,0 +1,14 @@
on:
release:
types: [published]
name: test-action
jobs:
github-release-to-discord:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Github Releases To Discord
uses: ./ # Uses an action in the root directory
with:
webhook_url: ${{ secrets.WEBHOOK_URL }}
+41
View File
@@ -1,5 +1,46 @@
# Changelog # Changelog
## [1.13.0](https://github.com/SethCohen/github-release-to-discord/compare/v1.12.1...v1.13.0) (2022-08-25)
### Features
* created test action ([d76d7aa](https://github.com/SethCohen/github-release-to-discord/commit/d76d7aafe49eadfc8d388bef38a8d3fb0230041b))
## [1.12.1](https://github.com/SethCohen/github-release-to-discord/compare/v1.12.0...v1.12.1) (2022-08-24)
### Miscellaneous Chores
* release 1.12.1 ([6aea64b](https://github.com/SethCohen/github-release-to-discord/commit/6aea64bf70aca011417fed5000ff080269024a93))
## [1.12.0](https://github.com/SethCohen/github-release-to-discord/compare/v1.11.1...v1.12.0) (2022-08-24)
### Features
* renamed all `colour`>`color` ([a0914f4](https://github.com/SethCohen/github-release-to-discord/commit/a0914f433a5c2a2626ca39637851235fd4f7adea))
## [1.11.1](https://github.com/SethCohen/github-release-to-discord/compare/v1.11.0...v1.11.1) (2022-08-24)
### Bug Fixes
* fixed ReferenceError on require vs import ([233db9c](https://github.com/SethCohen/github-release-to-discord/commit/233db9c33f9059cbe008e61acf7f321e671f352c))
## [1.11.0](https://github.com/SethCohen/github-release-to-discord/compare/v1.10.1...v1.11.0) (2022-08-24)
### Features
* updated `action.yml` ([e49c674](https://github.com/SethCohen/github-release-to-discord/commit/e49c674890cd5309d63bf570a550ffa0361c9ebc))
* updated `package.json` ([aea0a60](https://github.com/SethCohen/github-release-to-discord/commit/aea0a60ccd2456ae24e6ce7f21c1622a1b3ee18f))
### Bug Fixes
* fixed version tag ([baa4c82](https://github.com/SethCohen/github-release-to-discord/commit/baa4c82901455b2fbc18187cfa8f74f2a171f033))
## [1.10.0](https://github.com/SethCohen/github-release-to-discord/compare/v1.9.0...v1.10.0) (2022-08-24) ## [1.10.0](https://github.com/SethCohen/github-release-to-discord/compare/v1.9.0...v1.10.0) (2022-08-24)
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 SethCohen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+34 -17
View File
@@ -1,20 +1,22 @@
# Github Release To Discord Action # GitHub Release To Discord Action
A GitHub action that parses a GitHub release and posts it to a Discord channel as a stylized Discord webhook.
This action parses a github release and posts it to a discord channel via a discord webhook.
## Configuration
| Variable | Required | Default | Description |
|-------------|----------|----------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| webhook_url | ✔ | | Discord's webhook url. Use GH repo secrets. |
| colour | ❌ | "2105893" | Decimal colour value for embed. |
| username | ❌ | "Release Changelog" | String username for webhook. |
| avatar_url | ❌ | ["Profile Picture"](https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png) | String url to webhook avatar picture. |
---
## Output ## Output
![output](https://i.imgur.com/fOIu7pC.png) ![output](https://i.imgur.com/Zf3TXtb.png)
## Example usage ## Configuration
| Variable | Required | Default | Description |
|------------|----------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| webhook_url | ✔ | | Discord's webhook url. Use GH repo secrets. |
| color | ❌ | "2105893" | Decimal color value for embed. |
| username | ❌ | "Release Changelog" | String username for webhook. |
| avatar_url | ❌ | ["Profile Picture"](https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png) | String url to webhook avatar picture. |
## Example Usage
`.github/workflows/github-release-to-discord.yml`
```yaml ```yaml
on: on:
release: release:
@@ -26,9 +28,24 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Handle Release - name: Github Releases To Discord
uses: ./ # Uses an action in the root directory uses: SethCohen/github-release-to-discord@v1.12.0
id: release
with: with:
webhook_url: ${{ secrets.WEBHOOK_URL }} webhook_url: ${{ secrets.WEBHOOK_URL }}
``` color: "2105893"
username: "Release Changelog"
avatar_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
```
## Setup Instructions
1. Open your **Server Settings** and head into the **Integrations** tab:
2. Click the "**Create Webhook**" button to create a new webhook!
![](https://support.discord.com/hc/article_attachments/1500000463501/Screen_Shot_2020-12-15_at_4.41.53_PM.png)
![](https://support.discord.com/hc/article_attachments/360101553853/Screen_Shot_2020-12-15_at_4.51.38_PM.png)
3. Copy the webhook url
4. Create a new Github repository secret called WEBHOOK_URL and paste the webhook url into it.
![](https://i.imgur.com/hAaNOds.png)
5. Save the secret.
6. Add the secret to your action configuration.
And you're done! Whenever you create a new release, the workflow should run and, if properly setup, post to your specified Discord channel.
+7 -3
View File
@@ -1,11 +1,12 @@
name: Github Releases To Discord name: Github Releases To Discord
author: SethCohen
description: Send automatic styled releases to Discord. description: Send automatic styled releases to Discord.
inputs: inputs:
webhook_url: webhook_url:
description: Discord's webhook url. Use GH repo secrets. description: Discord's webhook url. Use GH repo secrets.
required: true required: true
colour: color:
description: Decimal colour value for embed. description: Decimal color value for embed.
required: false required: false
default: '2105893' default: '2105893'
username: username:
@@ -18,4 +19,7 @@ inputs:
default: 'https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png' default: 'https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png'
runs: runs:
using: 'node16' using: 'node16'
main: 'index.js' main: 'index.js'
branding:
icon: file-text
color: gray-dark
+64 -44
View File
@@ -1,7 +1,32 @@
const core = require('@actions/core'); import core from '@actions/core';
const github = require('@actions/github'); import github from '@actions/github';
const fetch = require('node-fetch') import fetch from 'node-fetch';
/**
* Stylizes a markdown body into an appropriate embed message style.
* H3s converted to bold and underlined.
* H2s converted to bold.
* Redundant whitespace and newlines removed.
* @param description
* @returns {*}
*/
const formatDescription = (description) => {
return description
.replace(/### (.*?)\n/g,function (substring) {
const newString = substring.slice(4).replace(/(\r\n|\n|\r)/gm, "")
return `**__${newString}__**`
})
.replace(/## (.*?)\n/g,function (substring) {
const newString = substring.slice(3).replace(/(\r\n|\n|\r)/gm, "")
return `**${newString}**`
})
.replace(/\n\s*\n/g, '\n')
}
/**
* Get the context of the action, returns a GitHub Release payload.
* @returns {Promise<{html_url, body: (*|string), version: string}>}
*/
async function getContext () { async function getContext () {
const payload = github.context.payload const payload = github.context.payload
@@ -14,52 +39,47 @@ async function getContext () {
} }
} }
/**
* Handles the action.
* Get inputs, creates a stylized response webhook, and sends it to the channel.
* @returns {Promise<void>}
*/
async function run () { async function run () {
try { const webhookUrl = core.getInput('webhook_url')
const webhookUrl = core.getInput('webhook_url') const color = core.getInput('color')
const colour = core.getInput('colour') const username = core.getInput('username')
const username = core.getInput('username') const avatarUrl = core.getInput('avatar_url')
const avatarUrl = core.getInput('avatar_url')
if (!webhookUrl) { if (!webhookUrl) return core.setFailed('webhook_url not set. Please set it.')
return core.setFailed('webhook_url not set. Please set it.')
}
const content = await getContext() const {body, html_url, version} = await getContext()
const description = content.body const description = formatDescription(body)
.replace(/### (.*?)\n/g,function (substring) {
const newString = substring.slice(4).replace(/(\r\n|\n|\r)/gm, "")
return `**__${newString}__**`
})
.replace(/## (.*?)\n/g,function (substring) {
const newString = substring.slice(3).replace(/(\r\n|\n|\r)/gm, "")
return `**${newString}**`
})
.replace(/\n\s*\n/g, '\n')
const embedMsg = { const embedMsg = {
title: `Release ${content.version}`, title: `Release ${version}`,
url: content.html_url, url: html_url,
color: colour, color: color,
description: description, description: description
}
const body = { username: username, avatar_url: avatarUrl, 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)
} }
const requestBody = {
username: username,
avatar_url: avatarUrl,
embeds: [embedMsg]
}
const url = `${webhookUrl}?wait=true`
fetch(url, {
method: 'post',
body: JSON.stringify(requestBody),
headers: { 'Content-Type': 'application/json' }
})
.then(res => res.json())
.then(data => core.info(JSON.stringify(data)))
.catch(err => core.info(err))
} }
run() run()
.then(() => {core.info('Action completed successfully')})
.catch(err => {core.setFailed(err.message)})
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "github-release-to-discord", "name": "github-release-to-discord",
"version": "1.9.0", "version": "1.12.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
+3 -3
View File
@@ -1,13 +1,13 @@
{ {
"name": "github-release-to-discord", "name": "github-release-to-discord",
"version": "1.10.0", "version": "1.13.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "github-release-to-discord", "name": "github-release-to-discord",
"version": "1.10.0", "version": "1.13.0",
"license": "ISC", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.9.1",
"@actions/github": "^5.0.3", "@actions/github": "^5.0.3",
+20 -5
View File
@@ -1,14 +1,29 @@
{ {
"name": "github-release-to-discord", "name": "github-release-to-discord",
"version": "1.10.0", "version": "1.13.0",
"description": "", "description": "Github Action that parses a release and sends it to a Discord channel",
"type": "module",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [], "keywords": [
"author": "", "discord",
"license": "ISC", "github",
"release",
"action",
"release-to-discord",
"github-release-to-discord",
"webhook",
"github-action",
"changelog"
],
"author": "SethCohen",
"bugs": {
"url": "https://github.com/SethCohen/github-release-to-discord/issues"
},
"homepage": "https://github.com/SethCohen/github-release-to-discord#readme",
"license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.9.1",
"@actions/github": "^5.0.3", "@actions/github": "^5.0.3",