rss-to-email/.github/workflows/send-email.yaml
2023-10-30 07:12:47 +01:00

54 lines
1.6 KiB
YAML

name: Send email
on:
schedule:
- cron: '30 4 * * *'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: read-all
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- name: Last successful run
id: last_success
run: echo "LAST_SUCCESS=$(gh api -XGET repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/workflows/send-email.yaml/runs --jq '.workflow_runs[0].run_started_at' -F status=success -F per_page=1)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: npm ci
- name: Create email
run: npm run email actionUrl=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} lastSuccess=${{ steps.last_success.outputs.LAST_SUCCESS }}
- name: Check email exists
id: check_email
uses: andstor/file-existence-action@v2.0.0
with:
files: 'dist/email.html'
- name: Send email
if: steps.check_email.outputs.files_exists == 'true'
uses: dawidd6/action-send-mail@v3.9.0
with:
server_address: ${{ vars.SMTP_SERVER }}
server_port: ${{ vars.SMTP_PORT }}
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: RSS to Email
to: ${{ secrets.MAIL_TO }}
from: ${{ secrets.SMTP_USERNAME }}
html_body: file://dist/email.html