GitHub Actions in Automation: Display Latest Blog Posts and Badges on your GitHub Profile
Tags: devops, productivity, github, githubactions
Published: 2023-07-25 08:11:17

Whenever I publish a blog post here on Dev Community, or achieve a new badge from Credly, I have to manually update my GitHub profile to display these updates. It's not the most exciting task and can be a drain on productivity. 

There has to be a way to automate the boring stuffs, right?  Isn’t that what developers do?

The answer is yes! This is where GitHub Actions comes in.

![el-profesor-la-casa-de-papel.gif](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u469hzkuraynb2oq6qdo.gif)


In this blog post, we will explore GitHub Actions automation solution to eliminate this repetitive process.

- [What is GitHub Actions?](#GitHub)
- [Steps to auto-update Dev.to Blog Posts on GitHub Profile](#Devto)
- [Steps to auto-update Credly Badges on GitHub](#Credly)
- [Conclusion](#conclusion)


<a name="GitHub"></a> 
## What is GitHub Actions?
[GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline.

GitHub Actions helps you automate processes in your GitHub repository using workflows. [Workflows](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#workflows) are configurable-automated processes that will run one or more jobs. Workflows are defined by a YAML file checked in to your repository and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule. Learn how to write GitHub Actions YAML files in the [GitHub Tutorial](https://github.com/padok-team/github-actions-tutorial). 

Let's get into it.
The code used in this blog post can be found on my [GitHub repository](https://github.com/paschalogu/paschalogu/tree/main)

<a name="Devto"></a> 
### Steps to auto-update Dev.to Blog Posts on GitHub Profile:

a.) Edit your special repository README file on GitHub `<username>/<username>/README.md`. Add the following section to your **README.md** file:

```bash
---
## Latest Blog Posts
<!-- BLOG-POST-LIST:START -->
<!-- BLOG-POST-LIST:END -->
```

b.) On this special repository, create a folder named `.github` and create `workflows` folder inside if it doesn't already exist.
c.) Create a new file named `blogpost-update.yml` inside this workflows directory. Copy and paste the below YAML code inside the file you just created:

![GitHub workflows](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6qeh22h0hrcju6mmsnk.png)    

```bash
name: Latest blog post workflow
on:
  schedule: # Run workflow automatically
    - cron: '0 * * * *' # Runs every hour, on the hour
  workflow_dispatch: # Run workflow manually (without waiting for the cron to be called), through the Github Actions Workflow page directly
permissions:
  contents: write # To write the generated contents to the readme

jobs:
  update-readme-with-blog:
    name: Update this repo README with latest blog posts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master
        with:
          feed_list: "https://dev.to/feed/<devto username>"
```

d.) Replace the feed_list URL with your own dev.to RSS feed.
e.) Save the changes and commit your code. You can either allow this workflow to run automatically, or you can manually trigger this workflow.

Here are some other popular blog sources you may want to automate:

Dev.to: `https://dev.to/feed/username`

Medium: `https://medium.com/feed/@username`

Hashnode: `https://@username.hashnode.dev/rss.xml`

WordPress: `https://www.example.com/feed/`

YouTube Channel Video: `https://www.youtube.com/feeds/videos.xml?channel_id=channelId` 


<a name="Credly"></a> 
### Steps to auto-update Credly Badges on GitHub:

a.) Edit your special repository README file on GitHub <username>/<username>/README.md.
b.) Add the following section to your **README.md** file:

```bash

---
## View my verified badges
<!--START_SECTION:badges-->
<!--END_SECTION:badges-->
```

c.) Create a GitHub workflow YAML file, `badge-update.yml`. Copy the below code and paste it to the new workflow YAML file you created.

```bash
name: Update Credly Badges

on:
  schedule:
    # Runs at 2am UTC
    - cron: "0 2 * * *"
  workflow_dispatch: # Run workflow manually (without waiting for the cron to be called), through the Github Actions Workflow page directly
permissions:
  contents: write # To write the generated contents to the readme
  
jobs:
  update-readme:
    name: Update Readme with badges
    runs-on: ubuntu-latest
    steps:
      - name: Badges - Readme
        uses: pemtajo/badge-readme@main
        with:       
          CREDLY_USER: <credly username> # optional, but default will use the same from github
```

d.) Replace the <credly username> with your own credly username.
e.) Save this change and commit your code. You can either allow this workflow to run automatically, or you can manually trigger it.

Here is how my GitHub Profile looks after running the workflows.


![GitHub ReadMe.md](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivyb5zcuwyztip6fe4go.png)

<a name="Conclusion"></a> 
### Conclusion

In this blog post, we introduced GitHub Actions, defined GitHub Actions workflows, dived into the steps to auto-update Dev.To Blog Posts on GitHub Profile and steps to auto-update Credly badges on GitHub Profile. GitHub Actions is a helpful tool to automate processes and save time on repetitive tasks. 

Thanks for reading. Let me know if you found this helpful. You are welcome to follow me on [LinkedIn](https://www.linkedin.com/in/paschal-ogu/) and [Twitter @Paschal_ik](https://twitter.com/Paschal_ik).