GitHub Actions 入門

Machine Learning 的 CI/CD

Ravi Bhadauria

Machine Learning Engineer

什麼是 GitHub Actions?

  • GitHub Actions(GHA):用於自動化「pipelines」的 CI/CD 平台
  • Pipeline:一連串步驟,表示工作與資料的流程
Machine Learning 的 CI/CD

什麼是 GitHub Actions?

一張汽車組裝線的圖片:工人在不同站點執行安裝引擎、裝輪胎、噴漆等任務。

Machine Learning 的 CI/CD

什麼是 GitHub Actions?

Github Actions 為軟體專案建立一系列定義好的動作或步驟,例如檢出儲存庫、建置程式碼、執行測試或部署應用程式。

1 https://medium.com/empathyco/applying-ci-cd-using-github-actions-for-android-1231e40cc52f
Machine Learning 的 CI/CD

GHA 元件:Event

  • Event:在儲存庫中的特定活動,會觸發 workflow 執行
    • Push
    • Pull Request
    • 開啟 issue
Machine Learning 的 CI/CD

GHA 元件:Workflow

  • Workflow:會執行一個或多個 jobs 的自動化流程
    • 以 YAML 檔定義
    • event 自動觸發
      • 也可手動執行
    • 放在儲存庫的 .github/workflows 目錄
    • 可定義多個 workflows
Machine Learning 的 CI/CD

GHA 元件:Steps 與 Actions

  • Steps:個別的工作單位
    • 依序執行,依賴前一步
    • 在同一台機器上跑,可共享資料
    • 工作單位範例
      • 編譯應用程式、shell 指令稿
      • Action:GHA 平台專用的應用程式
        • 例如檢出 repo、在 PR 留言
Machine Learning 的 CI/CD

GHA 元件:Jobs 與 Runners

  • Job:由多個 steps 組成
    • 各 job 彼此獨立
    • 可平行執行
    • 由稱為 runners 的運算機器執行
Machine Learning 的 CI/CD

簡單的 GHA workflow

一張示意圖:儲存庫中的 push 事件觸發一個 workflow,單一 job 在 Ubuntu Linux runner 上執行。此 job 有兩個步驟:檢出 repo 與執行 Python 程式碼。

  • Event:Push
  • Job:在 Ubuntu runner 上執行,包含兩個 steps
    • Action:Checkout Repo
    • Run Python Code
Machine Learning 的 CI/CD

整體串起來

一張典型的 GitHub Action workflow 元件圖,展示平行的 jobs 與序列的 steps 執行。

Machine Learning 的 CI/CD

一起來練習吧!

Machine Learning 的 CI/CD

Preparing Video For Download...