pr opened and closed #3
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
name: Notify on Commit or PR Merge | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [closed, opened] | |
jobs: | |
notify: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "14" | |
- name: Install dependencies | |
run: npm install -g nodemailer | |
- name: Send email notification | |
env: | |
GITHUB_EVENT: ${{ toJson(github.event) }} | |
GITHUB_ACTOR: ${{ github.actor }} | |
GITHUB_USER: ${{ github.event.pusher.name || github.event.pull_request.user.login }} | |
EVENT_TYPE: ${{ github.event_name }} | |
EMAIL: ${{ secrets.EMAIL }} | |
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }} | |
run: | | |
node -e " | |
const nodemailer = require('nodemailer'); | |
const transporter = nodemailer.createTransport({ | |
service: 'gmail', | |
auth: { | |
user: process.env.EMAIL, | |
pass: process.env.EMAIL_PASSWORD | |
} | |
}); | |
const mailOptions = { | |
from: process.env.EMAIL, | |
to: process.env.EMAIL, | |
subject: 'GitHub Event Notification', | |
text: \`Event Type: ${{ github.event_name }}\n | |
GitHub Event: ${{ env.GITHUB_EVENT }}\n | |
GitHub Actor: ${{ env.GITHUB_ACTOR }}\n | |
GitHub User: ${{ env.GITHUB_USER }}\` | |
}; | |
transporter.sendMail(mailOptions, (error, info) => { | |
if (error) { | |
return console.log(error); | |
} | |
console.log('Email sent: ' + info.response); | |
}); | |
" |