Automating Cron Jobs & Email Alerts with GitHub Actions + JavaScript

05 / Aug / 2025 by Amit Singh Bhandari 0 comments

Introduction

You probably already know how powerful GitHub Workflows are. They can transform the way you consume software and significantly boost your productivity. With them, you can automate almost anything.

If you’re new to GitHub Actions or want to understand them in depth, I highly recommend Sudarshan’s excellent post, “GitHub Actions for Seamless CI/CD,” which also covers the fundamentals for beginners.

Have you ever wanted an assistant that gives you your daily schedule, collects all the relevant data on your behalf, and creates an action plan for the day? If so, GitHub Actions can help automate most of that process.

In this blog post, we’ll build a scheduled GitHub Action (a.k.a. a cron job) that runs JavaScript code and emails you the weather report for the day — and all you need is a free GitHub repository to get started.

What we will build

  • A GitHub Action that runs on a schedule (e.g., every day at 8 AM IST)
  • A Node.js script that fetches weather data from Open-Meteo API
  • An email sender using Gmail SMTP (check this guide to create SMTP credentials)
  • Secrets management to securely store email credentials

Folder Structure

folder-structure

Folder structure for GitHub workflows

You can follow this simple structure or create your own for advanced use cases. Here, we’ve kept things simple and modular. You can easily add more workflows to this same repository in the future for different use cases.

GitHub Workflow: daily-report.yml

workflows-daily-report

Code for daily report GitHub workflow

on:
  schedule:
    - cron: '0 3 * * *'

This is how you set the timer for your workflow execution. The time is in UTC, and you can adjust it to run at your preferred time. You can also add multiple cron expressions if you want to schedule the workflow to run multiple times a day. For example:

on:
  schedule:
    - cron: '30 2 * * *' # 08:00 AM IST
    - cron: '30 8 * * *' # 02:00 PM IST
    - cron: '30 14 * * *' # 08:00 PM IST

The script initializes a virtual environment on an Ubuntu-based machine with Node.js 22. It then installs your NPM dependencies and runs the script. In our case, we don’t have any packages to install, so we can skip the dependency installation step.

The Script: sendReport.js

workflows-send-daily-report

Code to fetch weather report and send email.

This script fetches hourly temperature data from the Open-Meteo API and selects the 8 AM temperature for the report. You can customize and enhance it to include the full day’s data or the day’s high and low temperatures. The script is quick, lightweight, and runs on GitHub infrastructure — so you don’t have to pay anything.

Final Steps & Setting Secrets in GitHub

Now we’re ready to test the script. Create a new repository on your GitHub account, push the code, and prepare it for testing.

To send emails, you’ll need to set secrets in GitHub. These secrets will be injected as environment variables, which the script will read to authenticate and send the email using the proper credentials.

To keep your credentials safe:

  1. Go to your repo → Settings → Secrets and variables → Actions.
  2. Add the following secrets:
    EMAIL_USER – Your Gmail address
    EMAIL_PASS – Your Gmail App Password [Link]

Now that you’ve set the secrets, it’s time to manually test the workflow.
Navigate to your repository → Actions → Daily Weather Report, and click “Run workflow”.

Refer to the attached screenshot for guidance.

run-workflow

Manually run workflow from GitHub actions page.

What Else Can You Automate?

Here are some cool ideas to boost your productivity by automating daily tasks:

  • Daily stock price reports with Google Sheets integration.
  • Top 5 Hacker News or Reddit posts from your favorite niche.
  • Reading your calendar and sending daily summaries and reminders for important meetings.
  • Breaking news alerts that might be important for you.

Conclusion

GitHub Actions + JavaScript is a powerful combo — and best of all, it’s free for most use cases. For private repositories, there is a monthly usage limit, which you can verify on GitHub. The good news is that it’s free to use for public repositories.

However, the guarantee for running scheduled workflows (cron jobs) exactly on the specified time is limited on free accounts. I have noticed occasional delays in receiving email notifications, but there’s a simple workaround: schedule your cron jobs a bit earlier than needed.

To be honest, the sky’s the limit for automation with GitHub, and you should start offloading daily tasks to these automation scripts. Integration with OpenAI and other large language models opens doors to exciting new possibilities.

 

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *