Skip to content

Commit a5d54f6

Browse files
authored
Add support for discord (#9)
* add support for discord Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent afc4e07 commit a5d54f6

File tree

6 files changed

+313
-110
lines changed

6 files changed

+313
-110
lines changed

.github/workflows/post-jobs-slack.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
jobs:
55
slack-poster:
66
runs-on: ubuntu-latest
7-
name: Run Jobs Slack Poster
7+
name: Run Jobs Test Poster
88
steps:
99
- uses: actions/checkout@v3
1010
with:
@@ -13,29 +13,23 @@ jobs:
1313
- id: updater
1414
name: Job Updater
1515
uses: ./
16-
env:
17-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
1816
with:
1917
filename: "example/jobs.yaml"
2018
previous_filename: "example/jobs-previous.yaml"
2119
keys: "url"
2220
unique: "url"
23-
2421
deploy: false
2522
test: true
2623

2724

2825
- id: multifield_updater
2926
name: Job Updater
3027
uses: ./
31-
env:
32-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
3328
with:
3429
filename: "example/jobs.yaml"
3530
previous_filename: "example/jobs-previous.yaml"
3631
keys: "name,location,url"
3732
unique: "url"
38-
3933
deploy: false
4034
test: true
4135

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-2023 Vanessa Sochat, HPC Social Community
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,28 @@ and a yaml file with a list of jobs (or other links):
99
url: https://my-job.org/12345
1010
```
1111

12-
The action will inspect the file to determine lines that are newly added (compared to the parent commit)
13-
for a field of interest (e.g., the "url" attribute in a list of jobs), extract this field, and then post to a Slack channel.
12+
The action will inspect the file to determine lines that are newly added (compared to a parent commit or second file)
13+
for a field of interest (e.g., the "url" attribute in a list of jobs), extract this field, and then post to a Slack channel,
14+
a Discord Channel, Twitter, or Mastodon.
1415

1516
![img/example.png](img/example.png)
1617

17-
This is custom made to help the [US-RSE](https://github.com/US-RSE/usrse.github.io) site
18-
to have job updates posted to slack!
18+
This is custom made to help the [hpc.social](https://hpc.social/jobs) and [US-RSE](https://github.com/US-RSE/usrse.github.io) site
19+
to have job updates posted to slack! If you'd like help setting this up for your group, please
20+
ping [@vsoch](https://github.com/vsoch).
1921

20-
## Quickstart
2122

22-
1. Create a [webhook app](https://api.slack.com/messaging/webhooks#getting_started) and grab the URL and save to `SLACK_WEBHOOK` in your repository secrets.
23+
## Usage
24+
25+
You'll generally want to:
26+
27+
1. Generate needed credentials for your apps of choice.
2328
2. Add a GitHub workflow file, as shown below, with your desired triggers.
2429

25-
For more details on the above, keep reading.
30+
More specifically, add a GitHub workflow file in `.github/workflows` to specify the following. Note that
31+
the workflow below will do the check and update on any push to main (e.g., a merged pull request).
2632

27-
## 1. Slack Setup
33+
### Deploy to Slack
2834

2935
You'll want to [follow the instructions here](https://api.slack.com/messaging/webhooks#getting_started) to create a webhook
3036
for your slack community and channel of interest. This usually means first creating an application and selecting your slack
@@ -39,21 +45,13 @@ curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"
3945
```
4046

4147
Click on "Add new webhook to workspace" and then test the provided url with the bot. Copy the webhook URL
42-
and put it in a safe place. We will want to keep this URL as a secret in our eventual GitHub workflow.
43-
44-
45-
## 2. Usage
46-
47-
Add a GitHub workflow file in `.github/workflows` to specify the following. Note that
48-
the workflow below will do the check and update on any push to main (e.g., a merged pull request).
49-
50-
### Deploy to Slack
48+
and save this to `SLACK_WEBHOOK` in your repository secrets.
5149

5250
```yaml
5351
on:
5452
push:
5553
paths:
56-
- '_data/jobs.yml'
54+
- '_data/jobs.yaml'
5755
branches:
5856
- main
5957

@@ -69,33 +67,33 @@ jobs:
6967
- id: updater
7068
name: Job Updater
7169
uses: rseng/jobs-updater@main
72-
env:
73-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
7470
with:
75-
filename: "_data/jobs.yml"
71+
filename: "_data/jobs.yaml"
7672
keys: "url,name"
7773
unique: "url"
74+
slack_webhook: ${{ secrets.SLACK_WEBHOOK }}
75+
slack_deploy: true
7876

7977
- run: echo ${{ steps.updater.outputs.fields }}
8078
name: Show New Jobs
8179
shell: bash
8280
```
8381
8482
In the above, we will include the url and name fields, and use the url field to determine uniqueness (default).
85-
By default, given that you have the slack webhook in the environment, deployment will
86-
happen because deploy is true. If you just want to test, then do:
83+
Given that you have the slack webhook as a secret provided to the action and `deploy_slack` is true, the default `deploy`
84+
variable (to indicate all services) is true and deployment will happen. If you just want to test, then do:
8785

8886
```yaml
8987
...
9088
- id: updater
9189
name: Job Updater
9290
uses: rseng/jobs-updater@main
93-
env:
94-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
9591
with:
96-
filename: "_data/jobs.yml"
92+
filename: "_data/jobs.yaml"
9793
keys: "url"
9894
deploy: false
95+
slack_webhook: ${{ secrets.SLACK_WEBHOOK }}
96+
slack_deploy: true
9997
```
10098

10199
If you want to run a test run (meaning a random number of jobs will be selected that
@@ -106,12 +104,11 @@ aren't necessarily new) then add test:
106104
- id: updater
107105
name: Job Updater
108106
uses: rseng/jobs-updater@main
109-
env:
110-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
111107
with:
112-
filename: "_data/jobs.yml"
108+
filename: "_data/jobs.yaml"
113109
keys: "url"
114110
test: true
111+
slack_deploy: true
115112
```
116113

117114
If test is true, deploy will always be set to false.
@@ -123,17 +120,15 @@ to true, and also define all the needed environment variables in your repository
123120
secrets.
124121

125122
```yaml
123+
...
126124
- id: updater
127125
name: Job Updater
128126
uses: rseng/jobs-updater@add/deploy-arg
129-
env:
130-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
131127
with:
132-
filename: "_data/jobs.yml"
128+
filename: "_data/jobs.yaml"
133129
keys: "url,name"
134-
135-
deploy: true
136130
test: false
131+
slack_deploy: true
137132
138133
# Also deploy to Twitter (all secrets required in repository secrets)
139134
twitter_deploy: true
@@ -153,13 +148,9 @@ secrets.
153148
- id: updater
154149
name: Job Updater
155150
uses: rseng/jobs-updater@main
156-
env:
157-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
158151
with:
159-
filename: "_data/jobs.yml"
152+
filename: "_data/jobs.yaml"
160153
key: "url"
161-
162-
deploy: true
163154
test: false
164155
165156
# Also deploy to Mastodon (all secrets required in repository secrets)
@@ -175,3 +166,56 @@ secrets.
175166
mastodon_access_token: ${{ secrets.MASTODON_ACCESS_TOKEN }}
176167
mastodon_api_base_url: ${{ secrets.MASTODON_API_BASE_URL }}
177168
```
169+
170+
### Deploy to Discord
171+
172+
To deploy to Discord you will need to [create a webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
173+
and then set `deploy_discord` to true, along with adding the webhook to your repository secrets as `DISCORD_WEBHOOK`.
174+
175+
```yaml
176+
- id: updater
177+
name: Job Updater
178+
uses: rseng/jobs-updater@main
179+
with:
180+
filename: "_data/jobs.yaml"
181+
key: "url"
182+
test: false
183+
discord_deploy: true
184+
discord_webhook: ${{ secrets.DISCORD_WEBHOOK }}
185+
```
186+
187+
## Variables
188+
189+
### Inputs
190+
191+
The following variables are available. You can also look at the [action.yml](action.yml).
192+
193+
| Name | Description | Required | Default |
194+
|------|-------------|----------|---------|
195+
| filename | The filename for the jobs | true | unset |
196+
| previous_filename | The previous filename (for manual tesing or running alongside update) | false | unset |
197+
| keys | Comma separated list of keys to post (defaults to url) | false | url |
198+
| unique | Field to use to determine uniqueness | true | url |
199+
| hashtag | A hashtag to use (defaults to `#Rseng`) | false | #RSEng |
200+
| test | Test the updater (ensure there are jobs) | true | false |
201+
| deploy | Global deploy across any service set to true? | true | true |
202+
| slack_deploy | Deploy to Slack? | true | false |
203+
| slack_webhook | Slack webhook to deploy to. | false | unset |
204+
| discord_deploy | Deploy to Discord? | true | false |
205+
| discord_webhook | Discord webhook to deploy to. | false | unset |
206+
| twitter_deploy | Deploy to Twitter? | false | unset |
207+
| twitter_api_key | API key generated for the user account to tweet | false | unset |
208+
| twitter_api_secret |API secret generated for the user account to tweet | false | unset |
209+
| twitter_consumer_key | Consumer key generated for the entire app | false | unset |
210+
| twitter_consumer_secret | Consumer secret generated for the entire app | false | unset |
211+
| mastodon_deploy | Boolean to deploy to Mastodon | false | unset |
212+
| mastodon_access_token | API key generated for the user account to tweet | false | unset |
213+
| mastodon_api_base_url | Base URL of the Mastodon instance to post to, e.g., https://fosstodon.org/ | false | unset |
214+
215+
### Outputs
216+
217+
| Name | Description |
218+
|------|-------------|
219+
| Fields (keys) parsed | The fields that are parsed in the jobs |
220+
| Matrix | Matrix (list of lists) with value (index 1), icon (index 2) and full message (index 3) |
221+
| Empty Matrix | true if empty, false otherwise |

action.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Jobs Updater'
2-
description: "The jobs updater will respond on some trigger, and them parse a jobs file for changes, posting a field of interest to slack."
2+
description: "The jobs updater will respond on some trigger, and them parse a jobs file for changes, posting to one or more services."
33
inputs:
44
filename:
55
description: the filename for the jobs
@@ -15,19 +15,39 @@ inputs:
1515
description: Field to use to determine uniqueness
1616
required: true
1717
default: url
18+
hashtag:
19+
description: A hashtag to use (defaults to <hashtag>Rseng)
20+
required: false
21+
default: "#RSEng"
1822
test:
1923
description: Test the updater (ensure there are jobs)
2024
required: true
2125
default: false
2226
deploy:
23-
description: Deploy to slack?
27+
description: Global deploy across any service set to true?
2428
required: true
2529
default: true
30+
31+
slack_deploy:
32+
description: Deploy to Slack?
33+
required: true
34+
default: false
35+
slack_webhook:
36+
description: Slack webhook to deploy to.
37+
required: false
38+
discord_deploy:
39+
description: Deploy to Discord?
40+
required: true
41+
default: false
42+
discord_webhook:
43+
description: Discord webhook to deploy to.
44+
required: false
45+
2646
# If you want to post to Twitter, all of these credentials are required for a specific user
2747

2848
# API keys are typically generated on behalf of a user (at the bottom of the interface)
2949
twitter_deploy:
30-
description: Boolean to deploy to Twitter
50+
description: Deploy to Twitter?
3151
required: false
3252
twitter_api_key:
3353
description: API key generated for the user account to tweet
@@ -86,12 +106,17 @@ runs:
86106
ACTION_DIR: ${{ github.action_path }}
87107
INPUT_REPO: ${{ github.repository }}
88108
INPUT_TEST: ${{ inputs.test }}
109+
INPUT_HASHTAG: ${{ inputs.hashtag }}
89110
INPUT_DEPLOY: ${{ inputs.deploy }}
111+
SLACK_DEPLOY: ${{ inputs.slack_deploy }}
112+
SLACK_WEBHOOK: ${{ inputs.slack_webhook }}
90113
TWITTER_DEPLOY: ${{ inputs.twitter_deploy }}
91114
TWITTER_API_KEY: ${{ inputs.twitter_api_key }}
92115
TWITTER_API_SECRET: ${{ inputs.twitter_api_secret }}
93116
TWITTER_CONSUMER_KEY: ${{ inputs.twitter_consumer_key }}
94117
TWITTER_CONSUMER_SECRET: ${{ inputs.twitter_consumer_secret }}
118+
DISCORD_DEPLOY: ${{ inputs.discord_deploy }}
119+
DISCORD_WEBHOOK: ${{ inputs.discord_webhook }}
95120
MASTODON_DEPLOY: ${{ inputs.mastodon_deploy }}
96121
MASTODON_ACCESS_TOKEN: ${{ inputs.mastodon_access_token }}
97122
MASTODON_API_BASE_URL: ${{ inputs.mastodon_api_base_url }}

0 commit comments

Comments
 (0)