You MUST Learn CI/CD with Github Actions. 😎
GitHub Actions workflow is a typical setup for automating the process of building, testing, and deploying code, ensuring that only code that passes all tests gets deployed to production. 💡
1. Workflow :
✅ The title at the top (
2. Trigger (
✅ The
3. Jobs:
✅ The
3.1 Build Job: ✅
-
- ✅Steps:
1. Checkout Repository: Uses the
2. Set up Node.js: Uses the
3. Install Dependencies: Runs
4. Run Tests: Executes
3.2 Deploy Job: ✅
-
-
- Steps: ✅
1. Deploy to Production:
The
GitHub Actions workflow is a typical setup for automating the process of building, testing, and deploying code, ensuring that only code that passes all tests gets deployed to production. 💡
1. Workflow :
✅ The title at the top (
name: CI/CD with GitHub Actions
) indicates the name of the workflow. This name helps to identify the workflow among others in the repository.2. Trigger (
on
):✅ The
on
keyword specifies the event that triggers this workflow. In this case, the workflow is triggered by a push
event to the main
branch. This means that whenever a commit is pushed to the main
branch, the workflow will run automatically.3. Jobs:
✅ The
jobs
section defines the tasks that will be executed in this workflow. There are two jobs defined here: build
and deploy
.3.1 Build Job: ✅
-
runs-on:
specifies the virtual environment where the job will run. Here, ubuntu-latest
means it will run on the latest version of Ubuntu provided by GitHub Actions.- ✅Steps:
1. Checkout Repository: Uses the
actions/checkout@v2
action to clone the repository's code into the workflow environment. 2. Set up Node.js: Uses the
actions/setup-node@v3
action to install Node.js version 14, preparing the environment to run Node.js commands. 3. Install Dependencies: Runs
npm install
to install the project's dependencies defined in package.json
. 4. Run Tests: Executes
npm test
to run the project's tests. 3.2 Deploy Job: ✅
-
needs:
specifies that the deploy
job depends on the success of the build
job. It will only run if the build
job completes successfully.-
runs-on:
Like the build
job, the deploy
job also runs on ubuntu-latest
.- Steps: ✅
1. Deploy to Production:
The
run
block contains a simple shell script that checks if the build
job was successful. If it was, it echoes "Deployment logic goes here" (which is where you would put the actual deployment commands). If the build failed, it outputs "Build failed, skipping deployment".❤4