Automatically display your latest posts on your GitHub Profile README

Created October 21, 2021

Introduction

By creating a repository with the same name as your GitHub username (eg. bobbyiliev/bobbyiliev) you actually create a special repository. Its README.md will appear on your public profile.

In this post I will show you how to automatically display your latest posts on your GitHub Profile README.md file like this:

We will be using a GitHub action provided by Gautam krishna R called blog-post-workflow.

Let's get started!

Prerequisits

Before you get started you would need the following:

Cloning your repository

In order to set that you we will be using GitHub actions in order to automate the process.

The first thing that you would need to do is to clone your repository locally. To do so, visit your profile repo, click on the Code button and copy the link:

Checkout our latest product - the ultimate tailwindcss page creator 🚀

Then head over to your Git terminal and clone the repository:

git clone https://github.com/bobbyiliev/bobbyiliev.git

After that cd into the cloned repo:

cd bobbyiliev

Make sure to change bobbyiliev with your actual username

GitHub Actions

Once we have the project cloned locally, we need to create a .github folder and a workflows folder inside of it, we can use the mkdir command to do so:

mkdir -p .github/workflows

Once the .github/workflows, create a .yaml file with the name of the website that you will be using to import your posts from. For example, I will do this with DevDojo, so the name of the file would be devdojo.yaml:

touch .github/workflows/devdojo.yaml

With your favourite text editor, open the file and add the following content:

name: Latest DevDojo blog post workflow
on:
  schedule:
    # Runs every day
    - cron: '0 0 * * *'
  workflow_dispatch:

jobs:
  update-readme-with-blog:
    name: Update this repo's README with latest blog posts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: gautamkrishnar/[email protected]
        with:
          comment_tag_name: "DEVDOJO"
          feed_list: "https://devdojo.com/feed/bobbyiliev"
          commit_message: "Update devdojo.com blog posts"
          gh_token: ${{ secrets.GITHUB_TOKEN }}

Important: you need to change the feed_list value with the URL to your RSS feed.

In my case I am using DevDojo, so my RSS feed is https://devdojo.com/feed/bobbyiliev. For Dev.to it would be https://dev.to/feed/bobbyiliev and for other providers it might be different.

As you can see under the steps section we are using a GitHub action provided by Gautam krishna R called blog-post-workflow.

The cron: '0 0 * * *' specifies that the action will run every day at midnight.

Update your README.md file

Once you have the GitHub workflow in place, you need to also update your README.md file and add the following in the section where you want your posts to be displayed at:

# 📖 Latest Blog posts
<!-- DEVDOJO:START -->
<!-- DEVDOJO:END -->

The part before the START and END keywords needs to match exactly with the comment_tag_name value from the YAML file above.

Once you make the changes, save the file, commit it and push the changes to GitHub:

git add .
git commit -m "Add DevDojo blog-post-workflow"
git push origin main

With that your README.md profile will be updated every day at midnight.

To manually execute the workflow, go to Actions -> click on the Workflow -> and from the dropdown choose Run Workflow:

This will take a few seconds to run and it will update your README.md file with your latest posts!

As an example you could take a look at my workflows here:

GitHub Workflows Example

Conclusion

If you like this GitHub action, make sure to star it on GitHub here:

Blog post workflow

Hope that you find this useful! If you want to learn more about Git and GitHub check out this free eBook here:

💡 Introduction to Git and GitHub