Recently, there is a new feature on Github - a profile page for user:
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 PokéAPI 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:
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:
To explain the script, it randomize a number between 1 to 151 (id of gen 1 pokemon), use that id to fetch data from PokéAPI, 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:
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:
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
Discussion
I love the personal touch and dynamicness that this adds to your profile.
I recently found the git-auto-commit-action action super simple to make commits on my behalf.
Automatically Commit changed Files back to Github with Github Actions
git-auto-commit Action
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the commit back to GitHub.
The default committer is "GitHub Actions actions@github.com", and the default author of the commit is "Your GitHub Username github_username@users.noreply.gith...".
This Action has been inspired and adapted from the auto-commit-Action of the Canadian Digital Service and this commit-Action by Eric Johnson.
Usage
Add the following step at the end of your job, after other steps that might add or change files.