Adding blog posts to your GitHub README with GitHub Actions

July 16, 2021 by Anuraj

GitHub GitHubActions

This article will discuss about adding your blog posts to your Github readme with Github Actions. You can add a README file to a repository to communicate important information about your project. You can find for more details about the GitHub readme from here

I was looking into some automation aspect related to GitHub readme automation - I was looking into some solution using Azure Functions and Logic Apps. And I found few solutions as well. But later I found one simple solution using GitHub Actions. Here is the GitHub Action which will run every day and use your blog RSS feed and update your Readme file.

First you need to modify the Readme.md file like this.

### Recent Blog posts
<!-- BLOGPOSTS:START -->
<!-- BLOGPOSTS:END -->

Next you can create an GitHub Action and add the following code.

name: Blog posts on ReadMe
on:
  schedule:
    # Runs every day at 9am UTC
    - cron: '0 4 * * *'

jobs:
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - uses: actions/checkout@v2
      - name: Get RSS Feed
        uses: kohrongying/readme-the-rss@master
        with:
          feed_url: https://dotnetthoughts.net/feed
          count: 10
      - name: Commit file changes
        run: |
            git config --global user.name 'anuraj'
            git config --global user.email 'anuraj@example.com'
            git add .
            git diff --quiet --cached || git commit -m "Update README"    
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

And here is the screenshot of the GitHub Action running.

Github Action Running

And here is the Updated Readme file.

Updated Readme file

This way you will be able to update your blog posts automatically in to your GitHub readme file with the help of GitHub Actions.

Happy Programming :)

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub