GitHub Actions CI Pipeline Documentation
This document provides a comprehensive explanation of the GitHub Actions CI pipeline, detailing each command and step used in the workflow configuration file. The pipeline is designed to run tests across multiple operating systems when code is pushed to the main
branch or when a pull request is made to the main
branch.
Workflow Configuration File
name: BE-SMIT-B-11
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm install
Explanation of Commands
name: BE-SMIT-B-11
Purpose: Defines the name of the workflow. This name will appear in the GitHub Actions interface.
Value:
BE-SMIT-B-11
– This is a custom name chosen for the workflow.
on:
Purpose: Specifies the events that trigger the workflow.
Sub-commands:
push:
: Triggers the workflow when code is pushed to themain
branch.pull_request:
: Triggers the workflow when a pull request is made to themain
branch.
jobs:
- Purpose: Defines the jobs that make up the workflow. Each job contains a set of steps that GitHub Actions will execute.
build:
- Purpose: This is the name of the job that is defined. It will run the specified tasks on different operating systems.
strategy:
Purpose: Specifies the strategy for running the job across a matrix of different environments.
Sub-commands:
matrix:
: Defines the set of different environments (in this case, operating systems) on which the job will run.os: [ubuntu-latest, windows-latest, macos-latest]
: Specifies that the job should run on the latest versions of Ubuntu, Windows, and macOS.
runs-on: ${{ matrix.os }}
Purpose: Instructs GitHub Actions to run the job on the operating system specified in the matrix.
Value:
${{ matrix.os }}
– This dynamically refers to each operating system listed in thematrix
.
steps:
- Purpose: Lists the steps that will be executed in the job.
- name: Checkout code
Purpose: Checks out the repository's code so that the workflow can access it.
Command:
uses: actions/checkout@v2
uses
: Specifies that the step uses thecheckout
action from GitHub's marketplace.@v2
: Indicates that version 2 of thecheckout
action should be used.
- name: Set up Node.js
Purpose: Sets up the Node.js environment.
Command:
uses: actions/setup-node@v2
uses
: Specifies that the step uses thesetup-node
action from GitHub's marketplace.@v2
: Indicates that version 2 of thesetup-node
action should be used.
with:
: Provides additional configuration for thesetup-node
action.node-version: '18'
: Specifies that Node.js version 18 should be used.
- name: Install dependencies
Purpose: Installs the project dependencies defined in the
package.json
file.Command:
run: npm install
run
: Executes the command within the CI environment.npm install
: Runs the Node Package Manager (npm) to install the project dependencies.
Summary
This GitHub Actions CI pipeline runs on multiple operating systems (Ubuntu, Windows, and macOS) when code is pushed or a pull request is made to the main
branch. It sets up a Node.js environment, checks out the code, installs dependencies, and ensures that the project can run successfully across different platforms. This setup helps in maintaining consistency and detecting issues across various environments early in the development cycle.