diff --git a/README.md b/README.md index 3e1527c..cdf7d07 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ jobs: SENDGRID_API_TOKEN: ${{ secrets.SENDGRID_API_TOKEN }} RECIPIENTS_URL: ${{ secrets.RECIPIENTS_URL }} SENDER_EMAIL: ${{ secrets.SENDER_EMAIL }} + DISTRIBUTION_LISTS: ${{ secrets.DISTRIBUTION_LISTS }} ``` ### 2. Set the SendGrid secret @@ -48,10 +49,14 @@ list@example.com If you don't know where to host this file, just go to [GitHub Gists](https://gist.github.com) and create a new textfile with the e-mails you want to target. After you save the file just click `raw` and get the URI of the file you've just created. -### 3. Set the SENDER_EMAIL secret +### 4. Set the DISTRIBUTION_LISTS secret (Optional) + +Do the same for a secret named `DISTRIBUTION_LISTS`. The secret contents is a comma separated list of e-mails for other lists (This e-mails will be put in CC in the outgoing mail). + +### 5. Set the SENDER_EMAIL secret Do the same for a secret named `SENDER_EMAIL` including the e-mail to be used in the `from:` field on the mail message. -### 4. Test the workflow! +### 6. Test the workflow! Create a new release for your repository and verify that the action triggers and that the e-mails were sent. Sometimes it's worth checking the spam inbox. diff --git a/env.template b/env.template index bcd6d12..8b7d668 100644 --- a/env.template +++ b/env.template @@ -1,4 +1,5 @@ SENDGRID_API_TOKEN= RECIPIENTS_URL= +DISTRIBUTION_LISTS= SENDER_EMAIL= GITHUB_EVENT_PATH= diff --git a/src/notify.js b/src/notify.js index a83f4ac..15c4922 100644 --- a/src/notify.js +++ b/src/notify.js @@ -5,7 +5,7 @@ const sendgridMail = require('@sendgrid/mail'); const setCredentials = () => sendgridMail.setApiKey(process.env.SENDGRID_API_TOKEN); -async function prepareMessage(recipients) { +async function prepareMessage(recipients, lists) { const { repository, release } = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')); const converter = new showdown.Converter(); @@ -33,15 +33,17 @@ async function prepareMessage(recipients) { email: sender, }, to: sender, + cc: lists, bcc: recipients, subject, html: releaseBody, }; } -async function run(recipientsUrl) { +async function run(recipientsUrl, distributionLists) { const { data } = await axios.get(recipientsUrl); const recipients = data.split(/\r\n|\n|\r/); - const message = await prepareMessage(recipients); + const lists = distributionLists ? distributionLists.split(',') : []; + const message = await prepareMessage(recipients, lists); await sendgridMail.send(message); console.log('Mail sent!'); } @@ -50,7 +52,7 @@ async function run(recipientsUrl) { * Run */ setCredentials(); -run(process.env.RECIPIENTS_URL) +run(process.env.RECIPIENTS_URL, process.env.DISTRIBUTION_LISTS) .catch((error) => { console.error(error); process.exit(1);