Hope you all know about GitHub profile? In this blog, you will learn about different GitHub activities. And, how you can manage it?
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.
Source: article
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
Features
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
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
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
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
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.
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.