LetsDevOps: GitHub Actions for Beginner's

Introduction

GitHub Action is open source Fully integrated with GitHub for Setting up CI CD workflow and Deployment Pipelines. It is ready to use without any additional configuration -> Beauty of it.


GitHub Action Provide some additional feature unlike other DevOps Tools.

It helps to trigger the Workflow based on the event occur on Repository.



Architecture




Components of GitHub Actions




Workflow


Workflow terms is used in GitHub Which is similar to Pipeline used in other DevOps Tool. This is the starting point of creating the configurable automated process which runs all steps defined under the Continuous Integration and Continuous Deployment.


In GitHub Action All the CI/CD steps we write in YAML format only.


Note: All the Workflow must be created under .github/workflows

Workflow File type and where to store:




Events

Now to trigger the Workflow we have Events configuration. Event is any specific activity based on that Workflow gets triggered.




GitHub triggered Event: This is one example of Event which will trigger the Workflow when there is Push on Dev branch or Pull request on master branch.


 on: 
    push:
       branches: [ Dev ]
    pull_request:
       branches: [ master ]

GitHub Parametrized Triggered Event


on:
  workflow_dispatch:
    inputs:
      # Name of your Azure ADF
      ADF_NAME:
        description: 'ADF Name to Deploy'
        required: true
        default: 'adf-dev'

      # Name of the publish folder under adf_publish branch
      ADF_PUBLISH_FOLDER:
        description: 'ADF Publish Folder Name in Git 
        required: true
        default: 'adf'

GitHub Scheduled Event


on:
 schedule:
 - cron: 0 12 * * 1

Git Manually Triggered Event

on:
 workflow_dispatch


Strategy

Jobs run on multiple environment.

strategy:
    matrix:
        node-version: [8.x,10.x,12.x]
        os [macos-latest, windows-latest, ubuntu-18.04]

Jobs

Collection of one or more steps is defined as Job. Under the Job all steps run on Runner. All steps can run in a sequence or defined as per the dependency.



Actions

An action can be built in or customized which can be used to perform task on GitHub Action. There are list of action available on the GitHub Marketplace which helps to setup CI/CD.


This gives us flexibility to write our own Custom Action which can be imported through GitHub repository.







Advantages:

  • Activity to perform on the Environment.

  • Build, Test, Deploy Activity through Actions

  • Code can be reused.

  • Storing shared Actions

  • Post your actions to the GITHUB Marketplace


Runners

Each workflow needs some machine to run the steps, that machine is called as Runner in GitHub Actions. Each runner can run single Job at a time.


GitHub provides Linux, Windows and macOS Runner to run the Workflow. We can also created our self Hosted Agent to run the Workflow.


  • GitHub Hosted

  • Self Hosted



Workflow Schema


name: Application-CI #Name of the Workflow
on: # Defined Event Trigger
  push:
    branches: [ Dev ]
jobs: # Jobs under which it runs the Steps
  build:
    runs-on: windows-latest #Runner Declaration
    steps: # Defined Steps
      - uses: actions/checkout@v2
      - name: Run a one-line script
        run: write-host Hello, world!


Demo

In the Demo we are going to cover below.

  1. Overview of the GitHub Action --> You can sign up free if do not have GitHub Account. https://github.com/

  2. Create Repository(Public/Private)

  3. Creating sample Workflow

name: Application-CI #Name of the Workflow
on: # Defined Event Trigger
  push:
    branches: [ Dev ]
jobs: # Jobs under which it runs the Steps
  build:
    runs-on: windows-latest #Runner Declaration
    steps: # Defined Steps
      - uses: actions/checkout@v2
      - name: Run a one-line script
        run: write-host Hello, world!

4. Run the Workflow


Additional Info


GitHub Secrets

  • GITHUB_TOKEN

  • secrets

  • CLI management

  • Limitation

  • API

Secrets

Organization

  • Allow secrete management at Org Level

  • Effectively become repo secrets

  • Not Available for Free Plan


Repository

  • Scoped to repository

  • Can be used to override org secrets

  • Available for free plan

Environment

  • Apply to specific Environment

  • Override org/Repo secrets

  • Only users with env perm can add edit