การรันโค้ดใน repository

CI/CD สำหรับ Machine Learning

Ravi Bhadauria

Machine Learning Engineer

Shared repository model

  • ผู้ร่วมพัฒนาหลายคนทำงานบน repository เดียวกัน
  • สร้าง feature/topic branch สำหรับงานที่เกี่ยวข้อง
    • เปิด pull request
    • รีวิวโค้ดและเสนอการแก้ไข
    • merge โค้ดจาก branch เข้า main branch
  • การตรวจสอบแบบ CI/CD ช่วยยกระดับคุณภาพโค้ด

ภาพแสดง shared repository model ที่นักพัฒนาหลายคนร่วมกันพัฒนา repository เดียวกัน

CI/CD สำหรับ Machine Learning

สร้าง feature branch

ภาพหน้า landing page ที่ไฮไลต์แท็บ branch

ภาพหน้า branch ที่ไฮไลต์แท็บสร้าง branch ใหม่

CI/CD สำหรับ Machine Learning

สร้าง feature branch

ภาพหน้า landing page ของ repository ที่แสดง feature branch ที่กำลังใช้งาน

CI/CD สำหรับ Machine Learning

เพิ่มโค้ดใน repository

บันทึกเป็น hello_world.py ใน 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 สำหรับ Machine Learning

กำหนดค่า workflow event

  • ระบุ target branch สำหรับ pull request event
on:
  pull_request:
    branches: [ "main" ]
CI/CD สำหรับ Machine Learning

ไวยากรณ์ของ Actions

steps:
  - name: My Action 
    uses: <org_or_user_name>/<reponame>@<version_number>
    with:
      action-argument: value
CI/CD สำหรับ Machine Learning

กำหนดค่า workflow steps และ actions

  • Checkout repository ใน job step
steps:
  - name: Checkout 
    uses: actions/checkout@v3
  • ตั้งค่า Python environment
steps:
  - name: Setup Python
    uses: actions/setup-python@v4
    with:
      python-version: 3.9
CI/CD สำหรับ Machine Learning

รวมทุกอย่างเข้าด้วยกัน

  • Workflow ทำงานเมื่อมี pull request ไปยัง main
  • job build มีสาม step
    • Checkout checkout repository
    • Setup Python ตั้งค่า Python environment
    • Run Python script รันไฟล์ Python
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 สำหรับ Machine Learning

สร้าง PR และเรียกใช้ workflow

ภาพหน้า pull request ที่แสดง workflow กำลังทำงาน

CI/CD สำหรับ Machine Learning

ตรวจสอบ workflow logs

ภาพหน้า workflow logs ที่แสดง step รัน Python script พร้อม step อื่นๆ

CI/CD สำหรับ Machine Learning

มาฝึกกันเถอะ!

CI/CD สำหรับ Machine Learning

Preparing Video For Download...