How to maintain your GitHub Profile?

Deepak Moonat 13 Dec, 2021 • 6 min read

This article was published as a part of the Data Science Blogathon

Objective

Hope you all know about GitHub profile? In this blog, you will learn about different GitHub activities. And, how you can manage it?

Prerequisites

  1. Github Account and basic GIT knowledge
  2. A blog profile (for hands-on, not compulsory as it can be replicated to other workflows)

Read this article to know what is Git and GitHub.

Introduction

There is always a need to manage source code repositories such as Github or bitbucket, and then to use that in downstream tasks to manage the integration and delivery pipelines in a project using different services.

Now instead of using different services for Continous Integration and Continous Delivery tasks, we can directly use the Github Actions to execute our development workflows.

Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you’d like, including CI/CD, and combine actions in a completely customized workflow.

Source: article

Github Actions

GitHub Actions are packaged scripts to automate tasks in a software development workflow in GitHub. It can be configured to trigger complex workflows that meet our organization’s needs each time developers check(push/pull/merge) new source code into a specific branch, at timed intervals, or manually. The result is a reliable and sustainable automated workflow which leads to a significant decrease in development time.

We access ”Actions”, we can click on the Actions tab in the repository in which we need to set up the workflow.

In the Actions tab page, we will find different workflows to select whether we want to build and test container and push it to the Google container registry or Amazon container registry, or even IBM and Alibaba. We can even create our own actions as per workflow requirements.

Types of Github Actions

  • Container Actions: The environment is part of the action’s code. These actions can only be run in a Linux environment that GitHub hosts. Container actions support many different languages
  • JavaScript Actions: It doesn’t include the environment in the code. We will have to specify the environment to execute these actions. We can run in a VM in the cloud or on-premises. JavaScript actions support Linux, macOS, and Windows environments

Features

  1. Linux, macOS, Windows, ARM, and containers: Hosted runners for every major OS make it easy to build and test all your projects. Run directly on a VM or inside a container. Use your own VMs, in the cloud or on-prem, with self-hosted runners
  2. Matrix builds: Save time with matrix workflows that simultaneously test across multiple operating systems and versions of your runtime
  3. Any language: GitHub Actions supports Node.js, Python, Java, Ruby, PHP, Go, Rust, .NET, and more. Build, test, and deploy applications in your language of choice
  4. Live logs: See your workflow run in real-time with color and emoji. It’s one click to copy a link that highlights a specific line number to share a CI/CD failure
  5. Built-in secret store: Automate your software development practices with workflow files embracing the Git flow by codifying it in your repository
  6. Multi-container testing: Test your web service and its DB in your workflow by simply adding some docker-compose to your workflow file

GitHub Actions workflow

A GitHub Actions workflow is a process that we set up in our repository to automate software development life-cycle tasks, including GitHub Actions. With a workflow, we can build, test, package, release, and deploy any project on GitHub.
To create a workflow, we add actions to a .yml file in the .github/workflows directory in your GitHub repository.

Example:

name: A Hello World workflow
on: push
jobs:
  build:
    name: Hello world action
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
      with:
        MY_NAME: "XYZ"

name: Used to give a name to the workflow

on: Used to specify the trigger when to run the workflow, It can be events such as push, pull or an event configuration map that schedules a workflow or restricts the execution of a workflow to specific files, tags, or branch changes

jobs: A job is associated with a runner, a workflow must have at least one job. A runner can be GitHub-hosted or self-hosted and the job can run on a machine or in a container

runs-on: Used to specify runner, in the above example we specify to run the job on ubuntu-latest

steps: Used to specify what tasks a job has to complete. In our example, the step uses the action actions/checkout@v1 to check out the repository

with: Used to specify any variable value for the workflow, if the action required some variable then ‘with’ is used to set those variable value

Latest Blog Post Workflow

Let’s take the concepts that we have learned to apply to a real situation. Let say we have a blog site or we write and post blogs to some websites such as Analytics Vidhya, and suppose we need to update our GitHub profile with our latest blog posts. One way is to manually update the GitHub profile when we publish some posts however GitHub Actions can help us to remove the manual intervention.

First of all, to update our GitHub profile we need to create one. We need to create one repository with the same name as our GitHub username, in that repository create a readme.md file and copy the below content and commit the file

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

Once we have created the repository and the readme file, then follow the below steps

  1. Create a .github/workflows directory in the above-created repository
  2. In the .github/workflows directory, create a file named blog-post-workflow.yml
  3. Add below workflow in the file
name: Latest blog post workflow
on:
  schedule: # Run workflow automatically
    - cron: '0 0 * * 1' # Runs every monday
  workflow_dispatch: # Run workflow manually (without waiting for the cron to be called), through the Github Actions Workflow page directly
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:
          feed_list: "https://www.analyticsvidhya.com/blog/author/dmoonat/feed"
          max_post_count: "5"

Most of the attributes we have already discussed, others such as

  • schedule: Used to schedule the workflow based on a cron job, here the cron job is set to trigger the workflow every Monday. For more info on Cron Jobs, check this link
  • workflow_dispatch: Used to run the workflow manually also from the Github Actions page directly

With this workflow, we will update our readme file with our latest blog posts. The workflow runs on ubuntu-latest, it has 2 steps, first, it will check out our code, and then run the blog-post-workflow from gautamkrishnar repository (Person who have created the workflow). We need to pass some values to the workflow variables such as

  1. feed_list: URL from where to fetch the blogs, in this case, I have added my Analytics Vidhya blogs page link with ‘/feed’ appended to it
  2. max_post_count: Maximum posts to fetch and  display

For other options, check this out.

Once we have edited the file, we can commit it. Committing the workflow file in the repository will trigger the push event and run our workflow. To view our workflow, we need to head to the ‘Actions’ tab and click the workflow we want to monitor, we can check the logs of the workflow and can debug if it fails based on it.

GitHub Profile | Workflow
Workflow dispatch

Source: Author [GitHub account]

 

Once the workflow is successful, It will display the blog posts links in the readme file which is displayed on the homepage of the GitHub account. 

GitHub latest blog posts
Source: Author [GitHub account]

 

End Notes

The workflow that we have seen in this blog is a very basic one, with GitHub profile, maintenance actions we can implement advanced workflow for our software development or for our machine learning tasks.

References

https://docs.microsoft.com/en-in/learn/modules/github-actions-automate-tasks/2-github-actions-automate-development-tasks

https://docs.github.com/en/actions/quickstart

https://github.com/gautamkrishnar/blog-post-workflow

The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion. 

Deepak Moonat 13 Dec 2021

Frequently Asked Questions

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

Responses From Readers

Clear