Skip to content

Commit 4480082

Browse files
authored
Attachments (#12)
related to #11
1 parent feaa5fe commit 4480082

20 files changed

Lines changed: 809 additions & 32 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Email subject
2222

2323
Email body
2424

25+
### `attachment`
26+
27+
Filename of the attachment
28+
2529
## Outputs
2630

2731
### `status`
@@ -36,4 +40,5 @@ with:
3640
to: 'example@example.com'
3741
subject: 'building main'
3842
body: 'This is a notification from GitHub actions.'
43+
attachment: 'artifacts.zip'
3944
```

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ inputs:
1111
description: 'Email subject'
1212
body:
1313
description: 'Email body'
14+
attachment:
15+
description: 'Email attachment'
1416
outputs:
1517
status: # id of output
1618
description: 'The delivery status of the notification'

index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
const core = require('@actions/core');
2-
const { email } = require('@cinotify/js')
2+
const mime = require('mime');
3+
const { email } = require('@cinotify/js');
4+
const {readFileSync} = require('fs');
35

46
try {
57
const to = core.getInput('to');
68
const subject = core.getInput('subject');
79
const body = core.getInput('body');
8-
email({
9-
to,
10-
subject,
11-
body
12-
}).then(() => {
10+
const payload = {to, subject, body};
11+
12+
const attachmentPath = core.getInput('attachment');
13+
if (attachmentPath) {
14+
const file = readFileSync(attachmentPath);
15+
const attachment = {
16+
filename: attachmentPath,
17+
type: mime.getType(attachmentPath),
18+
content: file.toString('base64')
19+
}
20+
payload.attachments = [attachment];
21+
}
22+
23+
email(payload).then(() => {
1324
core.setOutput("status", "ok")
1425
}).catch(err => {
1526
core.setFailed(err.message)
1627
})
1728
} catch (error) {
1829
core.setFailed(error.message);
19-
}
30+
}

node_modules/.bin/mime

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@cinotify/js/README.md

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@cinotify/js/index.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@cinotify/js/package.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)