A Deep dive into DevOps #4
Introduction to GitHub actions and how it works π
What is GitHub actions?
GitHub Actions is an innovative platform designed specifically for continuous integration (CI) and continuous delivery (CD) on GitHub repositories. GitHub Actions allows developers to define custom workflows for building, testing, and deploying applications all within the same codebase.
GitHub Actions is based on the same technology as Docker containers, and this allows developers to launch multiple operating system environments in parallel. This technology provides a high degree of flexibility, and developers can use it to build numerous applications for many languages. Besides, many pre-built Actions are available from the GitHub marketplace that one can use to automate their workflows.
Key Features of GitHub Actions
Below are some key features of GitHub Actions to help developers automate their workflows:
Workflows
Workflows are the core of GitHub Actions. They relate to all the automation aspects: building, testing, releasing, and collaborating that make up the development lifecycle. A workflow is an automated process that runs in response to a trigger event in the repository. Trigger events could be pushed, pull requests, issue creation, or deletion.
Actions
GitHub Actions are standalone tasks that you can combine to create workflows. These tasks are reusable and modular, and they can be developed by a group of developers, which saves time and helps promote collaboration. GitHub has provided developers with many ready-made code snippets, known as actions, that can be used to automate specific tasks quickly.
Building Code
Building code refers to the process of collecting the necessary packages and dependencies required to convert the source code into an executable application. This process is crucial for ensuring that the app is free from any bugs and errors before it goes through testing.
Testing Code
Testing code is perhaps the most important aspect of the development lifecycle. With GitHub Actions, you can perform CI testing for a variety of use cases, including unit tests, integration tests, and acceptance tests.
Publishing Code
Once you have tested the code and are confident that everything is working correctly, the next step is to deploy the code to a distribution site. For instance, you can publish to an app store, website, or hosting service.
How GitHub Actions Works π€
At a high level, GitHub Actions is designed to execute workflows in response to specific events triggered by the repository. There are two key components of a GitHub Actions workflow:
Events: An action workflow is triggered by one or more events. These events could be a variety of actions performed on the repository, such as pull requests, push events, issue creation or deletion, and more.
Jobs and Actions: A job represents a set of steps that are run in parallel as part of a workflow. The steps are defined by actions, which are the individual units of work that GitHub Actions runs. Actions are self-contained units of scripts, commands, and code that can be combined to create custom workflows.
In practice, the process of setting up and running a GitHub Actions workflow involves defining a series of jobs, each of which consists of one or more actions. Actions can run on different platforms such as Windows, Linux, and macOS. Each action is a self-contained unit that performs a specific task or set of tasks, such as building code, running tests, deploying code, and more.
Example Workflow
Here is an example of a typical GitHub Actions workflow:
name: Build and Test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm run test
In this example, a workflow is defined that runs when someone pushes code to the repository. The workflow defines a single job called "build", which runs on an 'ubuntu-latest' runner. The job has three steps: checkout the code, install dependencies, build the code, and run tests.
Well, let's keep it to here only as we will be going to learn how we can create our custom actions and CI/CD pipelines where we will be going to learn about that in detail how it will create a GitHub runner server for each job in a workflow and how it will execute them π
I have to leave as I am going to explore more on the official document π
will you join me?
Let's go πββοΈ
Golden Rule π
No other references are better than official documentation π₯
If you have got something interesting make sure you react and follow if you haven't π