GitHub Actions
Continuous Integration and Delivery (CI/CD) has revolutionized the software development process, enabling teams to deliver high-quality products efficiently and frequently. Automation testers play a crucial role in this process by ensuring that every code change is thoroughly tested before deployment. GitHub Actions, integrated seamlessly with GitHub repositories, provides a powerful platform for automating these testing processes. In this blog, we'll explore how automation testers can leverage GitHub Actions to configure CI/CD pipelines effectively.=
In this article, I will cover the following topics
What is GitHub Actions
GitHub Actions is a continuous integration (build, test, merge) and continuous delivery(automatically release to the repository) (CI/CD) platform. It automates and executes the software development workflows right from GitHub. It helps to customize how actions work and automate tasks all along in the software development lifecycle.
With GitHub Actions, you can build, test, and publish across multiple platforms, operating systems, and languages all within the same workflow and then see the status checks displayed within the pull request.
GitHub Actions works with various languages and frameworks, and its configurations are in YAML.
One example of GitHub Actions is :
If you’ve configured GitHub Actions in your Git repository and you push code to the remote branch, the GitHub Action will automatically trigger the predefined workflow.
It supports various events such as opening pull requests, merging code, or pushing to a branch, making it a powerful and flexible tool for different scenarios. GitHub Actions, being event-driven, responds to these events by executing the specified workflows.
Github Actions uses .yml syntax to define the events, jobs, and steps.
Components Of GitHub Actions:
Components of GitHub Actions include workflows, events, and actions. These components enable the creation of powerful automation pipelines for building, testing, and deploying projects on GitHub.
Below is a detailed explanation of the components of GitHub Actions:
1.Events :
Events is an activity that triggers a workflow to run. Events can be triggered by opening a pull request, merging a pull request, etc. It can be configured to run on schedule.
2. Workflows (Jobs, Runner, Steps) :
Job is a set of steps in a workflow that execute on the same runner
Runner is a server that runs your workflows when they’re triggered. Each runner can run a single job at a time.
3. Actions:
It is a custom application/command for the GitHub Actions platform that performs a complex but frequently repeated task that automates the workflow process.
How to set up GitHub action in GitHub repository:
Pre-Requisite: GitHub Account, to create and run a GitHub Actions workflow. GitHub Actions uses YAML syntax to define the workflow.
In the below section, I have discussed, how we can add GitHub Action to the GitHub repository. I have taken an example of my GitHub repository which already has some code pushed in to master branch.
In the GitHub repository, one needs to create.github/workflows/directory and add a .yml file.
There are two ways to create a *.yml file
a. Go to repository
b. Click on Add File > Create New File
领英推荐
c. Enter .github/workflows/maven.yml ( It has to be in the same sequence. You can pass any name of your choice for .ym file)
d. Now, you can add the code to the maven.yml file and commit changes to your GitHub repository
Sample Code :
# This workflow will build a Java project with Maven and cache/restore any dependencies to improve the workflow execution time
name: GitHub Actions Demo Test Execution
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '*/15 * * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn clean install
2. Through Terminal:
a. Clone your GitHub repository into your system (git clone [Githubrepo])
b. Navigate to your GitHub repo (cd githubactions). Create a directory .github (command: mkdir .github)
*githubactions is the repository name used here
c. Go to .github (cd .github)
d. Create a folder workflow (command: mkdir workflows)
e. Go to workflows (cd workflows)
f. Create *.yml file (command: vi main.yml). You can give any name. I have created a file as main.yml
# This workflow will build a Java project with Maven and cache/restore any dependencies to improve the workflow execution time
name: GitHub Actions Demo Test Execution
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '*/15 * * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn clean install
How to view GitHub action activity:
Once the GitHub actions are configured and start running, you can view each step’s activity on GitHub.
Under “Workflow runs”, click the name of the run you want to see.
One can view the result of each step by clicking on the workflow
I hope you have enjoyed the article. Thanks for reading !!
Thanks, Sameer Wadhwa for the guidance and motivation