jmalvarez.dev
Menu

Automatically list your latest posts on your GitHub README

Author's avatar
José Miguel Álvarez VañóJuly 19, 2022

If you have a blog like mine and a GitHub profile you can automatically list your latest posts on your GitHub README using a GitHub Action. The only requirement is to have a RSS feed of your blog. To see the final result, go to my GitHub profile and check the section "Latest blog posts".

The GitHub Action that we are going to use is JasonEtco/rss-to-readme@v1.

Setup

The first step is to define the section where the posts are going to be listed in your README. This is how I've done it:

## 📝 Latest blog posts

<!--START_SECTION:feed-->

...

<!--END_SECTION:feed-->

Then, you have to add a .yml file like the following one in the directory .github/workflows. This is going to create a workflow in your repository. The workflow is set to be executed once a day at 8 AM. You can change it if you want.

The only thing you have to change is the feed-url parameter. It has to be the URL of your RSS feed.

name: Update this repo's README
on:
  schedule:
    # Once a day at 8 AM
    - cron: 0 8 * * *
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: JasonEtco/rss-to-readme@v1
        with:
          feed-url: https://www.jmalvarez.dev/feed.xml
          readme-section: feed
          empty-commits: false

If you want, you can specify a different template to render the list. To achieve this you only have to provide a Mustache template in the template parameter. For example:

name: Update this repo's README
on:
  schedule:
    # Once a day at 8 AM
    - cron: 0 8 * * *
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: JasonEtco/rss-to-readme@v1
        with:
          feed-url: https://www.jmalvarez.dev/feed.xml
          readme-section: feed
          empty-commits: false
          template: "> {{ excerpt }}\n\n[Read more!]({{ url }})"

For further personalization check the resources list. I recommend reading the rss-to-readme action documentation to see all the different options that the action offers.

Testing

If you want to test it you can update the workflow to be executed on every push and you can also specify the branch where you are working. This way you can check the final result without updating the GitHub README that appears on your profile. In my case I was working on a branch called add-github-action.

name: Update this repo's README
on: [push]
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: JasonEtco/rss-to-readme@v1
        with:
          feed-url: https://www.jmalvarez.dev/feed.xml
          readme-section: feed
          branch: add-github-action
          empty-commits: false

Resources

José Miguel Álvarez Vañó
© 2022
jmalvarez.dev