Menjalankan kode repositori

CI/CD untuk Machine Learning

Ravi Bhadauria

Machine Learning Engineer

Model repositori bersama

  • Banyak kolaborator bekerja pada repositori yang sama
  • Branch fitur/topik dibuat untuk pekerjaan terkait
    • Pull request dibuka
    • Kode ditinjau dan perubahan disarankan
    • Kode branch digabung ke branch main
  • Pemeriksaan CI/CD meningkatkan kualitas kode

Gambar model repositori bersama tempat banyak developer berkontribusi ke satu repositori

CI/CD untuk Machine Learning

Buat branch fitur

Gambar halaman beranda yang menyorot tab branch

Gambar halaman branch yang menyorot tab branch baru

CI/CD untuk Machine Learning

Buat branch fitur

Gambar halaman beranda repositori yang menampilkan branch fitur aktif

CI/CD untuk Machine Learning

Tambah kode repositori

Simpan sebagai hello_world.py di 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 untuk Machine Learning

Konfigurasi event workflow

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

Sintaks action

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

Konfigurasi langkah dan action workflow

  • Checkout repositori di langkah job
steps:
  - name: Checkout 
    uses: actions/checkout@v3
  • Menyiapkan lingkungan Python
steps:
  - name: Setup Python
    uses: actions/setup-python@v4
    with:
      python-version: 3.9
CI/CD untuk Machine Learning

Menggabungkannya

  • Workflow dipicu saat pull request ke main
  • Job build berisi tiga langkah
    • Checkout mengambil repositori
    • Setup Python menyiapkan lingkungan Python
    • Run Python script menjalankan file 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 untuk Machine Learning

Buat PR dan picu workflow

Gambar halaman pull request yang menampilkan workflow berjalan

CI/CD untuk Machine Learning

Periksa log workflow

Gambar halaman log workflow yang menampilkan langkah skrip Python di antara langkah lain

CI/CD untuk Machine Learning

Ayo berlatih!

CI/CD untuk Machine Learning

Preparing Video For Download...