0% found this document useful (0 votes)
90 views

Learn GitHub Actions

Uploaded by

degeek.dev
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Learn GitHub Actions

Uploaded by

degeek.dev
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Thank You

Roadmap
Blue is the colour of the
clear sky and the deep Red is the colour of Black is the color of
sea danger and courage ebony and of outer space

1 3 5

2 4 6

Yellow is the color of gold, White is the color of milk Blue is the colour of the
butter and ripe lemons and fresh snow clear sky and the deep
sea

3
Learning GitHub
Actions
Git Overview
Git
✘ Git is a distributed version control system (DVCS) that allows
multiple developers or other contributors to work on a project.

✘ It provides a way to work with one or more local branches and push
them to a remote repository.

✘ Git is responsible for everything GitHub-related that happens


locally on your computer. Key features provided by Git include:
Common Git Commands
git init git clone git checkout
to start a new empty repository or used for downloading the latest to switch the branch that you are
to reinitialize an existing one in the version of a remote project to the currently working on
project root. local machine

git commit git pull git push


To save changes or take a snapshot changes from the remote to upload local repository content
of the current state of the branch, repository and merge any remote to a remote repository
changes in the current local branch

8
Git
git status
git add .
git commit -m "commit message"
git pull
git push
git log
git branch
git checkout
git merge
Git Architecture
GitHub
GitHub is a cloud platform that uses Git as its core technology. It
simplifies the process of collaborating on projects and provides a
website, command-line tools, and overall flow that allows developers
and users to work together. GitHub acts as the "remote repository" in
the Git section.
Key features provided by GitHub include
✘ Issues
✘ Discussions
✘ Pull requests
✘ Notifications
✘ Labels
✘ Actions
✘ Forks
✘ Projects
Key features provided by GitHub include
Issues Blue Red
Is the color of gold, butter and ripe Is the colour of the clear sky and the Is the color of blood, and because of
lemons. In the spectrum of visible deep sea. It is located between this it has historically been
light, yellow is found between green violet and green on the optical associated with sacrifice, danger
and orange. spectrum. and courage.

Yellow Blue Red


Is the color of gold, butter and ripe Is the colour of the clear sky and the Is the color of blood, and because of
lemons. In the spectrum of visible deep sea. It is located between this it has historically been
light, yellow is found between green violet and green on the optical associated with sacrifice, danger
and orange. spectrum. and courage.

13
GitHub
GitHub is a development platform that enables you to host and review
code, manage projects, and build software alongside 50 million
developers.
Issues
Issues are where most of the communication between a project's
consumers and development team occurs.

An issue can be created to discuss a broad set of topics, including bug


reports, feature requests, documentation clarifications, and more.

Once an issue has been created, it can be assigned to owners, labels,


projects, and milestones. You can also associate issues with pull
requests and other GitHub items to provide future traceability.
Commits
✘ A commit is a change to one or more files on a branch. Every time a
commit is created, it's assigned a unique ID and tracked, along with
the time and contributor.

✘ This provides a clear audit trail for anyone reviewing the history of a
file or linked item, such as an issue or pull request.
Discussions
GitHub Discussions is a collaborative communication forum for the
community around an open source project. Community members can
ask and answer questions, share updates, have open-ended
conversations, and follow along on decisions affecting the community's
way of working.
Pull Requests
A pull request is the mechanism used to signal that the commits from
one branch are ready to be merged into another branch.
GitHub Tags
Tags are associated with commits, so you can use a tag to mark an
individual point in your repository's history, including a version number
for a release.
Labels
Labels provide a way to categorize and organize issues and pull
requests in a repository.

As you create a GitHub repository several labels will automatically be


added for you and new ones can also be created.

Examples: bug, documentation, duplicate, help wanted, enhancement,


question
Introduction to Workflows
Understanding GitHub Actions
✘ GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform
that allows you to automate your build, test, and deployment pipeline.

✘ You can create workflows that build and test every pull request to your repository, or
deploy merged pull requests to production.

✘ GitHub Actions goes beyond just DevOps and lets you run workflows when other
events happen in your repository.
What is GitHub Action Workflow
✘ A workflow is a configurable automated process
that will run one or more jobs.

✘ Workflows are defined by a YAML file checked in to


your repository

✘ With a workflow, you can build, test, package,


release, and deploy any project on GitHub.
Common DevOps Tasks
✘ Add new contributors

✘ Close stale issues & PRs

✘ Pull request

✘ Organizational tasks: Issue created by users

✘ Label the issue { minor, major, reproducible, priority etc. }

✘ Fix the issue and raise a PR

✘ Verify PR and merge the code to master

✘ New release with a version number

✘ Build pipeline to test, and build code


GitHub Action Workflow
Work + Flow
Steps
Triggers Uses Action1
Event Workflows
Action2

Action3
ü GitHub Action Workflow Directory: .github/workflows/
ü File Extension: .yml

Build Test Deploy

Add Label

Project XYZ Workflows


Components of GitHub Action
Workflow

Vijay Saini
Events
✘ An event is a specific activity in a repository that triggers a workflow run.

✘ For example, activity can originate from GitHub when someone creates a pull
request, opens an issue, or pushes a commit to a repository.

✘ You can also trigger a workflow run on a schedule, by posting to a REST API, or
manually.
GitHub Jobs
GitHub Jobs
A job is a set of steps in a workflow that execute on the same runner.
Each step is either a shell script that will be executed, or an action that
will be run.
Step
Steps can run commands, run setup tasks, or run an action

Checkout Repository

Build Application

Test Application

Upload Artifacts

GitHub Action Job


What is GitHub Action
✘ An action is a custom application for the GitHub Actions platform that
performs a complex but frequently repeated task. Use an action to help
reduce the amount of repetitive code that you write in your workflow files.

✘ An action can pull your git repository from GitHub, set up the correct
toolchain for your build environment, or set up the authentication to your
cloud provider.
What is GitHub Action
✘ GitHub Actions helps you automate your software development workflows
from within GitHub. You can deploy workflows in the same place where you
store code and collaborate on pull requests and issues.

✘ GitHub Actions optimize code delivery time from idea to deployment on a


community-powered platform.
✘ Workflow is an automated process that you
GitHub Workflow set up in your GitHub repository.
Summary ✘ A workflow needs to have at least one job
and can be triggered by different events.
✘ You can build, test, package, release, or
deploy any project on GitHub with a
workflow.
Lessons Learned
✘ How to create a workflow

✘ Event Trigger

✘ Job

✘ Step

✘ Runner

✘ How to run a workflow

✘ View Workflow run logs


Git Action
GitHub Action
An action is a custom application for the GitHub Actions platform that
performs a complex but frequently repeated task.

Use an action to help reduce the amount of repetitive code that you
write in your workflow files.

You can write your own actions, or you can find actions to use in your
workflows in the GitHub Marketplace.
GitHub Action
dd
GitHub Runner
Runners
✘ A runner is a server that runs your workflows when they're triggered.
Each runner can run a single job at a time.

✘ GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners


to run your workflows.

✘ Each workflow run executes in a fresh, newly-provisioned virtual


machine.
Runner Types
GitHub Hosted Runner Self Hosted Runner
✘ GitHub automatically provisions a new ✘ A self-hosted runner is a system that you
VM with Ubuntu Linux, Windows, or deploy and manage to execute jobs from
macOS operating systems GitHub Actions

✘ Machine maintenance and upgrades are ✘ Customizable to your hardware, operating


taken care by GitHub system, software, and security requirements

✘ Free GitHub plan + per-minute rates ✘ Are free to use with GitHub Actions

✘ Provide a clean instance for every job ✘ Don't need to have a clean instance for every
execution. job execution.
Why Self-hosted Runners
✘ Software Dependency

✘ VM Size and Configuration

✘ Secure Access & Networking

✘ Large Workload Support


Programming Variable
Variables are used to store information to be referenced and manipulated in a program.

ApplicationService = ‘http://github-action-is-awesome.com’
Create http://github-action-is-awesome.com
Deploy my app to http://github-action-is-awesome.com o Create ApplicationService
Perform UAT on http://github-action-is-awesome.com o Deploy my app to ApplicationService
Perform Load testing on http://github-action-is-awesome.com o Perform UAT on ApplicationService
o Perform Load testing on ApplicationService
Environment Variables
We can use environment variables to store information that you want to reference in your workflow.
GitHub Secretes
Secrets are encrypted environment variables that you create in an
organization, repository, or repository environment. The secrets that
you create are available to use in GitHub Actions workflows.

GitHub uses a libsodium sealed box to help ensure that secrets are
encrypted before they reach GitHub and remain encrypted until you
use them in a workflow.
GitHub Environments
Using environments for deployment

We can configure environments with protection rules and secrets.

A workflow job that references an environment must follow any


protection rules for the environment before running or accessing the
environment's secrets.
GitHub Secretes
APP_SECRET

PRODUCTION_APP_SECRET

STAGE_APP_SECRET

QA_APP_SECRET

UAT_APP_SECRET

DEV_APP_SECRET
GitHub Environments
Environments are used to describe a general deployment target like
production, staging, or development.

You can configure environments with protection rules and secrets. A workflow
job that references an environment must follow any protection rules for the
environment before running or accessing the environment's secrets.
Artifacts
Artifacts
Artifacts allow us to share data between jobs in a workflow and store data once that
workflow has completed.

These are some of the common artifacts that we can upload:


○ Log files and core dumps
○ Test results, failures, and screenshots
○ Binary or compressed files
○ Stress test performance output and code coverage results
Artifacts
Uploading files: Give the uploaded file a name and upload the data
before the job ends.

Downloading files: You can only download artifacts that were uploaded
during the same workflow run. When you download a file, you can
reference it by name.
Artifacts
Infra Automation
Infrastructure Requirement

Resource Specification

1 Storage Account SKU: Standard_LRS, kind: StorageV2

2 Container Registry SKU: Basic, adminUserEnabled: true

3 Service Bus Namespace Default ( Basic Tier )

4 App Service Plan SKU: Basic, Kind: Linux

5 Web App Runtime: .Net 7


Infrastructure as a code

✘ Infrastructure as code (IaC) uses DevOps methodology and versioning with


a descriptive model to define and deploy infrastructure

✘ define all infrastructure as version-controlled text files

✘ automate deployment and provisioning


Challenges in Manual Infra Deployment

✘ Inconsistencies in Deployments

✘ Repetitive & Complex Process

✘ Labor Intensive

✘ Human Error

✘ Slow Process
Why Infrastructure as a code ?
✘ Avoid manual configuration to enforce consistency

✘ Idempotence

✘ IaC boosts productivity through automation

✘ Faster speed and consistency


Local Envt Setup for Bicep development and deployment

VS Code + Bicep Extension

AZ CLI + Bicep Module

https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/install
Bicep Decompile vs Build

# Convert ARM to Bicep

az bicep decompile --file azuredeploy.json

# Convert Bicep to ARM

az bicep build --file .\keyvault.bicep


Infra Deployment Automation

GitHub
IaC Setup Action
Template Authentication Workflow
Azure AD service principals for automation authentication

Create a service principal and configure its access to resource group:

az ad sp create-for-rbac --name github-devops-app --role contributor --scopes


/subscriptions/<subscription-d>/resourceGroups/<rg name> --sdk-auth

Note : It is always a good practice to grant minimum access.


Continuous Integration
What is Continuous Integration

Continuous integration is a DevOps software development practice


where developers regularly merge their code changes into a central
repository, after which automated builds and tests are run.

Continuous integration most often refers to the build or integration


stage of the software release process.
CI : dotnet project example
Set up
Dotnet a .NET CLI
Setup environme
Restores
nt for use
the
Dotnet dependen
Restore cies and
Builds a
tools of a
project
project.
and all of
Dotnet Build
its
dependen
executes
cies.
unit tests
Dotnet Test
Publishes
in a given
the
solution
applicatio
Dotnet
n and its
Publish
dependen
cies to a
Git Ignore

.gitignore file is a text file that tells Git which files or folders to ignore in
a project.

A local . gitignore file is usually placed in the root directory of a project.


You can also create a global . gitignore file and any entries in that file
will be ignored in all of your Git repositories.

dotnet new gitignore


Continuous Deployment
CICD Workflow for
Deploying Docker Container
What is Continuous Deployment

Continuous deployment (CD) is the practice of using automation to


publish and deploy software updates. As part of the typical CD process,
the code is automatically built and tested before deployment.
CI CD Workflow
CICD Workflow for Deploying
Docker Container
Requirement

Your client TechSckool Ltd is building a microservices-based platform


and wants you to design a GitHub Action Workflow to Build and deploy
a Dotnet application’s container to an Azure Web App.

You must use Azure Container Registry to manage container.


GitHub Action for Docker Deployment

Login to Deploy
Setup Docker Docker
Docker the
Docker Build Push
Registry image
custom actions

Vijay Saini
custom actions
Actions are individual tasks that you can combine to create jobs and customize your workflow. You can
create your own actions, or use and customize actions shared by the GitHub community.
Composite Actions
A composite action allows you to combine multiple workflow steps within one action. For example, you
can use this feature to bundle together multiple run commands into an action, and then have a
workflow that executes the bundled commands as a single step using that action. To see an example,
check out "Creating a composite action".

You might also like