Skip to content

Jedidiah-Solomon/Github_Actions

Repository files navigation

CI/CD, which stands for continuous integration and continuous delivery/deployment, aims to streamline and accelerate the software development lifecycle.

  1. CI/CD Basics: CI (Continuous Integration): This means automatically testing and building your code whenever a new change (like a commit or pull request) is made. This helps in identifying issues early, ensuring the code works well together. CD (Continuous Delivery or Continuous Deployment): After the code is tested, it's automatically prepared for deployment (or actually deployed to production). Continuous Delivery stops at preparing for deployment, while Continuous Deployment automates the full release process.

  2. GitHub Actions: GitHub Actions is a CI/CD platform that automates tasks (like testing, building, and deploying your code). It allows you to set up workflows that run when certain events occur in your GitHub repository.

    Continuous integration (CI) refers to the practice of automatically and frequently integrating code changes into a shared source code repository. Continuous delivery and/or deployment (CD) is a 2 part process that refers to the integration, testing, and delivery of code changes. Continuous delivery stops short of automatic production deployment, while continuous deployment automatically releases the updates into the production environment.

    Key Terms in GitHub Actions: Here’s a breakdown of the core components:

Workflows: A workflow is an automated process that you define in your repository. It is defined by a YAML file located in the .github/workflows directory. Each workflow consists of one or more jobs.

Events: These are specific triggers that start a workflow. For example:

push: A workflow can be triggered when code is pushed to the repository. pull_request: A workflow can run when a pull request is created or updated. schedule: You can schedule workflows to run at specific times (e.g., daily builds). Jobs: A job is a set of steps that run on the same runner. Jobs run in parallel by default, but you can set dependencies between jobs if needed.

Steps: A job consists of steps, and each step is a task that can run commands or use actions. For example, installing dependencies, running tests, or deploying code can each be separate steps.

Actions: Actions are reusable commands that automate tasks. GitHub provides a marketplace for pre-built actions, but you can also create your own. An action could be something like "Checkout the code" or "Run a Node.js build".

Runners: A runner is the machine that runs your workflows. GitHub provides hosted runners (virtual machines) by default, but you can also set up self-hosted runners.

Example Workflow: Let’s walk through a very basic example of a CI workflow in GitHub Actions.

When you push code to your repository (event), it will trigger a job to run (like running tests). This job will consist of steps (like setting up your environment, installing dependencies, and running tests). The runner will execute these steps. Here’s an example of a simple GitHub Actions YAML file:

# .github/workflows/ci.yml

name: CI Workflow

on:
  push:        # This workflow will run when code is pushed
  pull_request: # Or when a pull request is created

jobs:
  build:
    runs-on: ubuntu-latest   # The runner will be an Ubuntu virtual machine

    steps:
    - name: Checkout code    # Step 1: Check out the code from the repository
      uses: actions/checkout@v2

    - name: Set up Node.js    # Step 2: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install dependencies # Step 3: Install dependencies
      run: npm install

    - name: Run tests          # Step 4: Run tests
      run: npm test

Explanation: on: Specifies the events that trigger this workflow (push and pull request). jobs: This workflow has a job called "build". runs-on: The job will run on a hosted Ubuntu runner. steps: The individual steps the job will run, including: Checkout the code from the repository. Set up Node.js. Install project dependencies. Run tests using the npm test command. Summary of Key Points: Workflows: Automated processes triggered by events. Events: Things like pushing code, creating pull requests, or scheduling tasks. Jobs: Group of steps that run on the same machine. Steps: Individual tasks within a job (like running tests or deploying code). Runners: Machines that execute the steps. Actions: Reusable commands or scripts that can be plugged into workflows. This is just the foundation! Let me know when you're ready to dive deeper into writing more complex workflows or using advanced features like environment variables, matrix builds, or deployment automation.

  1. .github/workflows/ci.yml Layman: This is just the file path where the configuration file is stored. It's inside the .github folder under workflows and is named ci.yml. This file contains instructions for GitHub Actions. Developer: This YAML file is located in .github/workflows/, which is where GitHub stores workflow configurations for automating tasks in your repository.
  2. name: CI Workflow Layman: This gives a name to the workflow. It’s called "CI Workflow". The name helps identify what the workflow is for. Developer: The name key defines the title of the workflow. "CI Workflow" is how this process will be referred to in the GitHub Actions dashboard.
  3. on: Layman: This specifies when the workflow should run. Developer: The on key defines the events that will trigger the workflow to start. In this case, it's triggered by a push or pull_request.
  4. push: Layman: The workflow will run when new code is added (pushed) to the repository. Developer: The push event triggers the workflow every time a commit is pushed to the repository.
  5. pull_request: Layman: The workflow will also run when someone opens or updates a pull request (which is a way of proposing changes to the code). Developer: This triggers the workflow whenever a pull request is opened, updated, or synchronized with the branch.
  6. jobs: Layman: This is the start of where the real tasks are defined. The workflow will perform a series of tasks called "jobs". Developer: The jobs section defines one or more jobs that the workflow will run. Each job is a set of instructions that run on a virtual environment.
  7. build: Layman: This is the name of the job. We are calling it "build" because it will check and build the code. Developer: This is the ID of the job. Jobs run independently of each other unless dependencies are specified. In this example, it is called "build".
  8. runs-on: ubuntu-latest Layman: The tasks will run on a virtual machine (like a computer in the cloud), and it will use the latest version of the Linux Ubuntu operating system. Developer: The job will execute on a GitHub-hosted runner running the latest version of Ubuntu. GitHub-hosted runners are virtual machines provided by GitHub.
  9. steps: Layman: These are the steps the job will follow to complete the task. Each step is like a single action in the process. Developer: The steps key lists the individual actions that will be run sequentially within the job.
    • name: Checkout code Layman: The first step is to get the latest version of the code from the repository. Developer: This step gives the step a name, "Checkout code", for clarity. It will use a predefined action to check out the repository’s code.
  10. uses: actions/checkout@v2 Layman: This tells GitHub to use an existing tool called "checkout" to download the code. It’s like saying, "Go get the code so we can work on it." Developer: The uses key specifies that this step will use the action from the GitHub Actions marketplace: actions/checkout@v2. This action is necessary to fetch the repository code so it can be used in subsequent steps.
    • name: Set up Node.js Layman: The next step is to set up Node.js, which is a platform that helps us run JavaScript code. Developer: This step is named "Set up Node.js" to indicate that it will prepare the environment for running Node.js applications.
  11. uses: actions/setup-node@v2 Layman: This step uses a tool called "setup-node" to install Node.js. Developer: The uses key points to another pre-built action, actions/setup-node@v2, which installs Node.js on the runner.
  12. with: Layman: This is where we give more details about how to set up Node.js. Developer: The with key specifies additional options for the action. In this case, we're specifying the version of Node.js we want to install.
  13. node-version: "14" Layman: We’re telling it to install version 14 of Node.js. Developer: This specifies that Node.js version 14 will be installed on the runner. You can change this to any version you want.
    • name: Install dependencies Layman: The next step is to install the necessary tools (called dependencies) that our code needs to work. Developer: The step is labeled "Install dependencies", indicating that it will install all required packages from the package.json file.
  14. run: npm install Layman: This command runs something called npm install, which will download and install all the required dependencies. Developer: The run key defines a shell command to be executed. Here, npm install will install all the packages defined in package.json.
    • name: Run tests Layman: This step runs tests to make sure the code works correctly. Developer: This step is labeled "Run tests", indicating that it will execute the tests defined for the project.
  15. run: npm test Layman: This command runs the tests using npm test to check if everything is working fine. Developer: The run key defines a shell command, and npm test runs the test scripts defined in the project’s package.json. Summary for Layman: This file defines a set of steps that run automatically when new code is added (or a pull request is made). It checks out the code, sets up a Node.js environment, installs the necessary tools, and runs tests to make sure everything is working properly.

Summary for Developer: This CI workflow is triggered by push and pull_request events, runs on an Ubuntu runner, checks out the code, sets up Node.js version 14, installs dependencies using npm install, and runs tests using npm test.

NODE NPM

"dependencies": {
  "express": "^4.21.0"
}

express: "^4.21.0" This specifies that your project depends on Express.js version 4.21.0, with the caret (^) meaning it will accept patch and minor updates (e.g., 4.21.1, 4.22.0), but not major updates (5.x.x).

  1. Understanding Semantic Versioning (SemVer): Express uses semantic versioning, which follows the format MAJOR.MINOR.PATCH:

MAJOR: Increments when there are incompatible changes that might break backward compatibility (e.g., moving from 4.x.x to 5.x.x). MINOR: Increments when new features are added in a backward-compatible manner (e.g., 4.21.0 to 4.22.0). PATCH: Increments when backward-compatible bug fixes are made (e.g., 4.21.0 to 4.21.1). 2. The Caret (^) Symbol: The caret (^) before the version number indicates how version updates should be handled. Specifically, ^4.21.0 means: You can install any version that is greater than or equal to 4.21.0 but less than 5.0.0. This includes any minor updates or patch fixes: Patch Updates: 4.21.1, 4.21.2, etc. Minor Updates: 4.22.0, 4.23.0, etc. It will not accept a major update that might introduce breaking changes, such as 5.0.0. 3. Examples of Acceptable Versions: Allowed: 4.21.0 (exact version) 4.21.1 (patch update) 4.22.0 (minor update) 4.99.9 (further minor updates) Not Allowed: 5.0.0 (major update) 6.0.0 (any future major versions) 4. Benefits: Using ^ allows your project to benefit from bug fixes and new features without breaking compatibility, which is essential for maintaining stability in your application.

About

CI/CD repo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published