Hello Viwers, I am back again with another blog and the topic name is Github Actions CI CD Pipelines WorkFlows. So in this blog we will consider so many thing about CI/CD pipelines workflows like what is Github Actions, how to use - step by step, can i used github actions for CI/CD, A demo workflows file - How to create, run and check results, Terms: Workflows, Events, Jobs, Steps.
Can i used github actions for CI/CD?
Yes, GitHub Actions is commonly used for Continuous Integration
(CI) and Continuous Deployment (CD) workflows.
What is Github Actions?
GitHub Actions is an automation platform provided by GitHub that
allows you to set up workflows for your software development projects. It
enables you to automate various tasks, such as building, testing, and
deploying your code directly from your GitHub repository.
Key
features of GitHub Actions include:
- Automate SDLC workflows
- Implement CI CD DevOps
Demo
Let's start with the demo how to use github action. Actually you don't got anywhere for using CI/CD, you can use all features in GitHub Action.
Step 1 - Signup and Login to GitHub.com
Step 2 - Create a new Repository
Go to this + Plus button dropdown. Click on new repository.
Now i will called as github-actions and set as public and click on create repository button (when go to scroll down on same page).
Step 3 - In the repo create a folder .github/workflows
here you can either create manually and then commited push to the
repository. or you can go to this action tab.
here you can see the github actions and you can also use templates or use workflows yourself but we will go to setup workflows as yourself.
Step 4 - In the folder create a YAML file with .yml extension
Here this will automatically create .github/workflows folder and the name of main.yml file but this is empty code. yaml is programming language and .yml this is a file format but particular syntax.
Step 5 - Add the content of the workflow in the file
Now content adding time..
Go to this link and copy the syntax of printing of hello world and you can also use online yaml formater online as a precautions of indentation error.
Hello World -
CLICK HERE
YAML Formatter - CLICK HERE
name: hello-world 'on': push jobs: my-job: runs-on: ubuntu-latest steps: - name: my-step run: echo "Hello World!"
Certainly! The YAML code you've provided is a simple GitHub Actions workflow.
Let's break down each part:
```yaml
name: hello-world
```
This sets the name of your workflow. In this case, it's named
"hello-world." This name is just for your reference and doesn't affect the
functionality of the workflow.
```yaml
on: push
```
This specifies the event that triggers the workflow. In this
case, the workflow will be triggered whenever there is a `push` event to the
repository.
```yaml
jobs:
my-job:
runs-on:
ubuntu-latest
steps:
```
Here, you define a job named "my-job" that runs on an
`ubuntu-latest` virtual machine. This means the steps within this job will be
executed on a machine with the latest version of Ubuntu.
```yaml
- name: my-step
run: echo
"Hello World!"
```
Within the job, you define a step named "my-step." This step uses
the `run` key to specify the command that should be executed. In this case,
it's a simple command to echo "Hello World!" to the console.
So,
when a `push` event occurs in your repository, GitHub Actions will execute
this workflow. The workflow consists of one job named "my-job," which runs on
an Ubuntu machine. In that job, there's a single step named "my-step" that
echoes "Hello World!" to the console.
This is a basic example, and
GitHub Actions can be extended to perform more complex workflows, such as
running tests, building and deploying applications, and more, depending on the
needs of your project.
Step 6 - Commit and push the changes
This should start with github actions workflows.
Step 7 - Go to Repo main page and click "ACTIONS TAB"
So this is our workflow
Step 8 - Select the workflow from left sidebar and check the logs
Here is the single job ( i have only one thats why) When we click on this job, here we can see the logs. Here we have a job.
# First it is setup that will the spin up ubuntu system, as you can see, it is running the ubuntu image (operating system).
# Second this is the actual job. By step here it is running, this comment "echo hello world" which is printing hello world.
# Third one is completing the job, doing all the cleanup process.
So, This is how it is running ...ummm looking good LOL ;-)
Also if you want to re-run this job, you can also click on it.
You can also check all types of detals like Usage, Workflow file.
Don't forget to explore more things and forget to share....
Disclaimer