Skip to main content

Command Palette

Search for a command to run...

GitHub Action to update ReadMe File

Updated
3 min read
GitHub Action to update ReadMe File

Keeping your GitHub README updated with your latest blog posts can be boring and repetitive. Here is the solution for it.

In this article, I’ll walk you through how I used two GitHub repositories and GitHub Actions to automatically fetch my Hashnode articles and update my README file.

Problem:

Every time I publish a new article on Hashnode, I have to:

  • Copy the link manually

  • Edit my README file

  • Commit and push the change

Solution:

I split the automation into two repositories:

✅ Repo 1 → Fetch Hashnode Articles

This repo:

  • Uses Hashnode GraphQL API to fetch the latest articles

  • Returns the title of the document along with the article link in markup language

  • It takes updateReadMe(Boolean) as input to update in your README when this action is called.

  • action.yaml file is important in this repo. GitHub will only recognize your repo as an Action if it contains action.yaml

✅ Repo 2 → README Repository

This repo:

  • Contains my profile README

  • Uses GitHub Actions

  • Calls Repo 1

  • Updates README automatically

  • I have configured a cron job to run every Monday at 9 AM to fetch the Hashnode articles and update them in my README file.

  • The GitHub Action will update and add a commit to my README repo.

Architecture Flow:

Wondering to update your Readme File:

  1. Create .github/workflows/hashnode.yaml in your repo.

  2. Add the code below and pass the necessary parameters.

name: Latest Hashnode Posts

on:
  schedule:
    - cron: "30 3 * * 1" // Runs on every Monday 9 AM. Change accordingly based on your need
  workflow_dispatch: # Run workflow manually

jobs:
  update-readme-with-hashnode-blog:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Fetch Hashnode posts
        uses: aishwaryasubbiah/fetch-hashnode-articles@main
        with:
          max_post_count: 5 // Number of post you need as output
          hashnode_url: "”  Pass the hashnode blog url without https://
          updateReadMe: true
          readmePath: "README.md"

      - name: Commit update
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add README.md
          git commit -m "Update blog list" || exit 0
          git push
  1. In your README file, add the code below
<!-- BLOG-POST-LIST:START -->
<!-- BLOG-POST-LIST:END -->
  1. At the specified time, the cron job will be triggered, and the article's title will be updated in your README file.

Parameters:

Param NameDefault ValueDescription
hashnode_url-hashnode url without https:// Example: username.hashnode.dev
max_post_count5The number of posts you need.
updateReadMefalseIf true, update the readMe file
readmePathREADME.mdThe name of your README file