Automating README Creation
Stop manually updating your GitHub profile. Set up a bot that fetches latest stats and updates your README automatically every week.
The Automation Loop
Infinite consistency without manual effort
1. Write Permissions
Go to Settings → Actions → General and change Workflow permissions to "Read and write permissions".
2. Bot Identity
Standard github-actions[bot] config ensures clean, automated commit histories.
Part 1: The Orchestrator (YAML)
How to handle the scheduling and Git persistence.
# .github/workflows/auto-readme.yml
name: Auto-Update README
on:
schedule:
- cron: '20 7 * * 6' # Run every Saturday at 7:20 AM
push:
branches: [master]
paths:
- 'scripts/generate-readme.js'
workflow_dispatch:
jobs:
update-readme:
name: "Generate and Commit README"
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: "Run README generator"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: ${{ github.repository_owner }}
run: node scripts/generate-readme.js
- name: "Commit & Push changes"
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "docs: auto-update README [skip ci]"
git pushCron Triggers
Scheduled runs use Cron syntax. '20 7 * * 6' means every Saturday at 7:20 AM.
Permission Set
Explicitly defining 'contents: write' allows the workflow to commit files back to your repo.
The [skip ci] Flag
Critically important: telling GitHub NOT to trigger a second workflow from this automated commit.
Part 2: The Generator (Node.js)
Fetching live data and overwriting the README file.
GitHub API Statistics
We use the https module to ping the GitHub API. This retrieves Star counts, Forks, and Open Issues for your series repository.
Blog Content (RSS)
Most blogs (Hashnode, Dev.to) provide an RSS feed. Our script parses this XML using simple Regex to extract Title and Link pairs.
Dynamic Overwriting
Once data is ready, we use fs.writeFileSync. This completely replaces your old README with a fresh version containing the new data.
// FILE: scripts/generate-readme.js
const https = require('https');
const fs = require('fs');
const USERNAME = process.env.GITHUB_USERNAME || 'Yuvadi29';
const REPO_NAME = 'Github-Actions-Series';
const BLOG_URL = 'https://codingadda.hashnode.dev/';
const TOKEN = process.env.GITHUB_TOKEN;
// 1. Fetch GitHub Stats
async function getStats() {
const headers = TOKEN ? { Authorization: `Bearer ${TOKEN}` } : {};
const data = JSON.parse(await get(`https://api.github.com/repos/${USERNAME}/${REPO_NAME}`, headers));
return { stars: data.stargazers_count, forks: data.forks_count };
}
// 2. Fetch Blog Posts via RSS
async function getPosts() {
const xml = await get(`${BLOG_URL}/rss.xml`);
// Regex parsing logic...
return posts;
}
// 3. Write README.md
async function run() {
const stats = await getStats();
const posts = await getPosts();
const content = `# 👋 Hey, I'm ${USERNAME}! ...stats: ${stats.stars}...`;
fs.writeFileSync('README.md', content);
}
run();