How to maintain your GitHub Profile?
Hope you all know about GitHub profile? In this blog, you will learn about different GitHub activities. And, how you can manage it?
- Github Account and basic GIT knowledge
- 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.
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.
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
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
Matrix builds: Save time with matrix workflows that simultaneously test across multiple operating systems and versions of your runtime
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
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
Built-in secret store: Automate your software development practices with workflow files embracing the Git flow by codifying it in your repository
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
name: A Hello World workflow on: push jobs: build: name: Hello world action runs-on: ubuntu-latest steps: - uses: actions/[email protected] 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/[email protected] 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
- Create a .github/workflows directory in the above-created repository
- In the .github/workflows directory, create a file named blog-post-workflow.yml
- 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/[email protected] - uses: gautamkrishnar/[email protected] 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
- 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
- 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.
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.
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.
The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion.