DEV Community

Cover image for Automatically display your latest posts on your GitHub Profile README
Bobby Iliev
Bobby Iliev

Posted on • Originally published at devdojo.com

Automatically display your latest posts on your GitHub Profile README

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:

  • A GitHub account and a GitHub public profile repository. If you do not have one yet, you can follow the steps on how to create it here: Create a GitHub Profile README.md with widgets
  • You would also need a blog with an RSS feed. If you already have a DevDojo account or a DEV account you should be all set!

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:

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

git clone https://github.com/bobbyiliev/bobbyiliev.git
Enter fullscreen mode Exit fullscreen mode

After that cd into the cloned repo:

cd bobbyiliev
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master
        with:
          comment_tag_name: "DEVDOJO"
          feed_list: "https://devdojo.com/feed/bobbyiliev"
          commit_message: "Update devdojo.com blog posts"
          gh_token: ${{ secrets.GITHUB_TOKEN }}
Enter fullscreen mode Exit fullscreen mode

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 -->
Enter fullscreen mode Exit fullscreen mode

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:

  • Stage the files:
git add .
Enter fullscreen mode Exit fullscreen mode
  • Commit your changes:
git commit -m "Add DevDojo blog-post-workflow"
Enter fullscreen mode Exit fullscreen mode
  • Push your changes to GitHub:
git push origin main
Enter fullscreen mode Exit fullscreen mode

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

Discussion (2)

Collapse
luuuuuis profile image
Luis

Alternatively you could name your repository ".github". Same effect

Collapse
bobbyiliev profile image
Bobby Iliev Author

This is a good tip! Thank you for sharing it.