Experiment 2
CI/CD with GitHub Actions
Objective: To automate ML training/testing pipeline using GitHub Actions.
This experiment continues from Experiment 1. Make sure you have completed it first.
Resources
Note on Script Names
In the Lab Manual, you might see train.py. Here, we are using specific script names: linear-regression.py and logistic-regression.py to run multiple models.
Procedure
1. Create Workflow Folder
Inside your mlops-lab folder, create the following folder structure:
ml_pipeline.yml
linear-regression.py
logistic-regression.py
requirements.txt
2. Create Workflow File
Create a file named ml_pipeline.yml inside .github/workflows/ and paste:
name: ML Pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Linear Regression
run: python linear-regression.py
- name: Run Logistic Regression
run: python logistic-regression.py3. Push to GitHub
- Open GitHub Desktop.
- You should see the new
.githubfolder with the workflow file. - Add a summary (e.g., "Add CI/CD pipeline").
- Click Commit to main.
- Click Push origin.
4. Verify Pipeline
- Go to your repository on github.com.
- Click on the Actions tab.
- You should see your "ML Pipeline" running.
- Click on it to view the logs and verify both scripts executed successfully.
Verify Pipeline
Github --> Actions --> All workflows (workflow run) --> ml_pipeline.yml
on: push
build
Reference Output
Output Document
View Document
Author: Aamir Sarang