Skip to content

LeetCode Streak Reminder #182

LeetCode Streak Reminder

LeetCode Streak Reminder #182

Workflow file for this run

name: LeetCode Streak Reminder
# ─────────────────────────────────────────────────────────────────────────────
# SCHEDULING
#
# DEFAULT: Three jobs fire at 9:00 PM, 11:00 PM, and 11:30 PM UTC (= GMT).
#
# TO CHANGE THE TIMES — two options:
#
# Option A (recommended): Keep these crons, but set REMINDER_TIMES as a
# GitHub Secret (e.g. "20:00,22:00,23:00"). The script will skip itself
# if the current time doesn't match. Update the crons below to match.
#
# Option B: Replace the 3 crons below with a single frequent cron, e.g.:
# - cron: "*/30 18-23 * * *" # every 30 min between 6 PM–midnight UTC
# Then set REMINDER_TIMES to exactly when you want notifications.
# The script's ±5-minute time window will handle the matching.
#
# Use https://crontab.guru to build cron expressions.
# Note: GitHub Actions has ~1 min of scheduling latency.
# ─────────────────────────────────────────────────────────────────────────────
on:
schedule:
- cron: "0 21 * * *" # 21:00 UTC — 9:00 PM GMT (default)
- cron: "0 23 * * *" # 23:00 UTC — 11:00 PM GMT (default)
- cron: "30 23 * * *" # 23:30 UTC — 11:30 PM GMT (default)
# Manual trigger from Actions tab — great for testing
workflow_dispatch:
jobs:
check-and-remind:
name: Check LeetCode & Remind if Needed
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
# ── 1. Compute today's date for the cache key ──────────────────────────
- name: Get today's date (UTC)
id: date
run: echo "today=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
# ── 2. Short-circuit if we already confirmed "solved today" ────────────
# Cache key includes the date, so it naturally expires at midnight.
- name: Restore solved-today cache
id: cache
uses: actions/cache/restore@v4
with:
path: .solved_today
key: leetcode-solved-${{ steps.date.outputs.today }}
- name: Skip — already solved today (cached)
if: steps.cache.outputs.cache-hit == 'true'
run: |
echo "✅ Cache hit: problem already solved today (${{ steps.date.outputs.today }}). Exiting."
exit 0
# ── 3. Checkout & Python setup ─────────────────────────────────────────
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt
# ── 4. Run the reminder ────────────────────────────────────────────────
- name: Run LeetCode Streak Reminder
id: reminder
env:
LEETCODE_USERNAME: ${{ secrets.LEETCODE_USERNAME }}
LEETCODE_TIMEZONE: ${{ secrets.LEETCODE_TIMEZONE }}
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }}
TO_PHONE_NUMBER: ${{ secrets.TO_PHONE_NUMBER }}
NOTIFICATION_CHANNEL: ${{ secrets.NOTIFICATION_CHANNEL }}
REMINDER_TIMES: ${{ secrets.REMINDER_TIMES }}
REMINDER_MESSAGE: ${{ secrets.REMINDER_MESSAGE }}
ERROR_ALERT_MESSAGE: ${{ secrets.ERROR_ALERT_MESSAGE }}
NOTIFY_ON_ERROR: ${{ secrets.NOTIFY_ON_ERROR }}
run: |
python main.py
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
# ── 5. Cache "solved today" so later cron jobs skip instantly ──────────
- name: Create solved marker file
if: steps.reminder.outputs.exit_code == '0'
run: echo "solved on ${{ steps.date.outputs.today }}" > .solved_today
- name: Save solved-today to cache
if: steps.reminder.outputs.exit_code == '0'
uses: actions/cache/save@v4
with:
path: .solved_today
key: leetcode-solved-${{ steps.date.outputs.today }}