リポジトリのコードを実行する

Machine Learning のための CI/CD

Ravi Bhadauria

Machine Learning Engineer

共有リポジトリモデル

  • 複数のコラボレーターが同じリポジトリで作業します
  • 関連する作業ごとにフィーチャー / トピックブランチを作成します
    • プルリクエストを作成します
    • コードをレビューし、変更を提案します
    • ブランチのコードを main ブランチにマージします
  • CI/CD による自動チェックでコード品質を向上します

複数の開発者が1つのリポジトリで共同作業する共有リポジトリモデルの画像

Machine Learning のための CI/CD

フィーチャーブランチを作成する

ブランチタブを強調表示したランディングページの画像

新しいブランチタブを強調表示したブランチページの画像

Machine Learning のための CI/CD

フィーチャーブランチを作成する

アクティブなフィーチャーブランチを表示したリポジトリのランディングページの画像

Machine Learning のための CI/CD

リポジトリにコードを追加する

ブランチ内に hello_world.py として保存します

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()
Machine Learning のための CI/CD

ワークフローイベントを設定する

  • プルリクエストイベントの対象ブランチを指定します
on:
  pull_request:
    branches: [ "main" ]
Machine Learning のための CI/CD

Actions の構文

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

ワークフローのステップとアクションを設定する

  • ジョブステップでリポジトリをチェックアウトします
steps:
  - name: Checkout 
    uses: actions/checkout@v3
  • Python 環境をセットアップします
steps:
  - name: Setup Python
    uses: actions/setup-python@v4
    with:
      python-version: 3.9
Machine Learning のための CI/CD

全体をまとめる

  • ワークフローは main へのプルリクエストでトリガーされます
  • build ジョブには3つのステップがあります
    • Checkout がリポジトリをチェックアウトします
    • Setup Python が Python 環境をセットアップします
    • 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
Machine Learning のための CI/CD

PR を作成してワークフローをトリガーする

実行中のワークフローを表示したプルリクエストページの画像

Machine Learning のための CI/CD

ワークフローログを確認する

他のステップとともに Python スクリプトのステップを表示したワークフローログページの画像

Machine Learning のための CI/CD

練習しましょう!

Machine Learning のための CI/CD

Preparing Video For Download...