Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 1, 2020 11:02 am GMT

How to create a self-updating Github Profile

Recently, there is a new feature on Github - a profile page for user:

RageBill's Github Profile

There are a ton of other posts about how to create a Github profile and all that, so I am not going to write a step-by-step guides here.

Instead, I am trying to explain how does a self-updating
Github Profile works.

Taking my own profile as an example, I use PokAPI to fetch and display name and picture of a random gen 1 pokemon. The profile updates once every hour by itself.

So, how does it work? Let me try to explain it as simply as possible.

Special Repository For Github Profile

First, Github has now reserved a special repository for your profile - YOUR_USERNAME/YOUR_USERNAME. In my case, it would be RageBill/RageBill. If you create a README.md file in that repository, you will then see a button in your repository to display it on your profile page like this:

Github Profile Page Button

Ok, now that you know where is the source of the profile page, let's talk about how to make it self-updating.

Writing Script To Generate README.md

For me, I have created a generate.py script in Python to generate a README.md for me:

generate.py content

To explain the script, it randomize a number between 1 to 151 (id of gen 1 pokemon), use that id to fetch data from PokAPI, then write the result into a README.md file.

Use Github Action To Update The Repository

Once we have a script, the only thing we have to do is to make it update itself. The easiest way is to use Github Action.

For me, I have set it up with this yml file.

To highlight, there are two parts that make this work:

main.yml content 1

This parts tells Github Action to run the code on 1) push to master, and 2) once every hour.

Then, after running the script, the profile won't update by itself yet. You have to make it commit the README.md generated:

main.yml content 2

And that's it!

To Recap:

  • There is a special repo YOUR_USERNAME/YOUR_USERNAME for your Github Profile.
  • Write a script in any language (I used Python here) to generate a README.md for you.
  • Configure Github Action to run the script for you.
  • Don't forget to let Github Action commit the change to your repository.
  • You can schedule the Github Action with cron to make the profile update by itself on a constant interval.

Happy coding!

Reference:

Go automate your GitHub profile README
Awesome Github Profile README


Original Link: https://dev.to/ragebill/how-to-create-a-self-updating-github-profile-2m22

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To