send-email.yml 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. name: Send Email on Holidays Update
  2. on:
  3. schedule:
  4. # 从 00:00 到 10:00 UTC,每 2 小时运行一次(对应北京时间 08:00 到 06:00)
  5. - cron: '0 0-10/2 * * *'
  6. # Allows you to run this workflow manually from the Actions tab on GitHub.
  7. workflow_dispatch:
  8. jobs:
  9. notify:
  10. runs-on: ubuntu-latest
  11. steps:
  12. - name: Checkout code
  13. uses: actions/checkout@v4
  14. - name: Setup Node.js
  15. uses: actions/setup-node@v4
  16. with:
  17. node-version: "20"
  18. registry-url: "https://registry.npmjs.org"
  19. - name: Install dependencies
  20. run: npm install
  21. - name: Run script
  22. id: run-script
  23. run: npm run fetch ${{ vars.HOLIDAYS_YEAR }}
  24. - name: Read holidays file
  25. id: read-holidays
  26. run: |
  27. echo "HOLIDAYS_CONTENT=$(cat holidays.html)" >> $GITHUB_ENV
  28. env:
  29. HOLIDAYS_CONTENT: $(cat holidays.html)
  30. - name: Send notification if holidays has value
  31. if: ${{ steps.run-script.outputs.holidays != '' }}
  32. uses: dawidd6/action-send-mail@v3
  33. with:
  34. server_address: smtp.gmail.com
  35. server_port: 587
  36. username: ${{ secrets.EMAIL_USERNAME }}
  37. password: ${{ secrets.EMAIL_PASSWORD }}
  38. subject: "${{ vars.HOLIDAYS_YEAR }} Holidays Update"
  39. to: ${{ secrets.TO_EMAIL }}
  40. from: Holidays Update
  41. html_body: ${{ env.HOLIDAYS_CONTENT }}