Running repository code

CI/CD for Machine Learning

Ravi Bhadauria

Machine Learning Engineer

Shared repository model

  • Multiple collaborators work on same repository
  • Feature/Topic branches are created for related work
    • Pull requests are opened
    • Code is reviewed and changes are suggested
    • Branch code is merged into main branch
  • CI/CD enabled checks improve code quality

Image of the shared repository model where multiple developers are contributing to a single repository

CI/CD for Machine Learning

Create a feature branch

Image of the landing page highlighting the branch tab

Image of the branch page highlighting the new branch tab

CI/CD for Machine Learning

Create a feature branch

Image of the repository landing page displaying active feature branch

CI/CD for Machine Learning

Add repository code

Save as hello_world.py in the branch

import datetime

def main():
    print("Hello, World!")

    # Get the current time and print it
    current_time = datetime.datetime.now()
    print("Current time:", current_time)

if __name__ == "__main__":
    main()
CI/CD for Machine Learning

Configure workflow event

  • Specify target branch for pull request event
on:
  pull_request:
    branches: [ "main" ]
CI/CD for Machine Learning

Actions syntax

steps:
  - name: My Action 
    uses: <org_or_user_name>/<reponame>@<version_number>
    with:
      action-argument: value
CI/CD for Machine Learning

Configure workflow steps and actions

  • Checking out repository in job step
steps:
  - name: Checkout 
    uses: actions/checkout@v3
  • Setting up python environment
steps:
  - name: Setup Python
    uses: actions/setup-python@v4
    with:
      python-version: 3.9
CI/CD for Machine Learning

Putting it together

  • Workflow triggers on pull request to main
  • build job contains three steps
    • Checkout checks out the repository
    • Setup Python sets up the Python environment
    • Run Python script runs the Python file
name: PR

on:
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.9
      - name: Run Python script
        run: |
          echo hello_world.py 
          python hello_world.py
CI/CD for Machine Learning

Create PR and trigger workflow

Image of pull request page displaying a running workflow

CI/CD for Machine Learning

Inspect workflow logs

Image of the workflow logs page displaying python script step among other steps

CI/CD for Machine Learning

Let's practice!

CI/CD for Machine Learning

Preparing Video For Download...