Skip to content
CodeSook
CodeSook

03. What is Github Actions?


GitHub Actions คืออะไร 🤖

GitHub Actions เป็น CI/CD (Continuous Integration/Continuous Deployment) service ของ GitHub ที่ใช้สำหรับ automate workflows ⚙️ ต่างๆ ที่เกี่ยวข้องกับ GitHub repository

graph LR
    A[📝 Push Code] --> B[🔔 Trigger Event]
    B --> C[🆕 Create Fresh Environment]
    C --> D[📥 Checkout Code]
    D --> E[⚙️ Run Workflow Steps]
    E --> F[✅ Complete & Cleanup]

    style A fill:#89b4fa,stroke:#cdd6f4,stroke-width:2px,color:#000000
    style B fill:#f38ba8,stroke:#cdd6f4,stroke-width:2px,color:#11111b
    style C fill:#fab387,stroke:#cdd6f4,stroke-width:2px,color:#11111b
    style D fill:#a6e3a1,stroke:#cdd6f4,stroke-width:2px,color:#11111b
    style E fill:#cba6f7,stroke:#cdd6f4,stroke-width:2px,color:#11111b
    style F fill:#94e2d5,stroke:#cdd6f4,stroke-width:2px,color:#11111b

หลักการทำงาน 🔧

  • GitHub Action เป็น virtual machine (หรือ container) ที่ GitHub จัดเตรียมให้ 💻
  • เมื่อ workflow ถูกเรียกใช้ GitHub จะ สร้าง environment เปล่าๆ ขึ้นมาใหม่ 🆕
  • Repository ไม่ได้ clone มาให้อัตโนมัติ - เราต้องใช้ action actions/checkout เพื่อ clone code มาเอง 📥

ส่วนใหญ่เราจะใช้ github action ทำงานประมาณนี้ ✨

  • Automated Testing 🧪 - รัน test อัตโนมัติเมื่อมี push/PR
  • Deployment 🚀 - deploy แอปไปยัง server
  • Code Quality 🔍 - ตรวจสอบ code style, security
  • Release Management 📦 - สร้าง release และ publish packages

จุดสำคัญที่ต้องจำ 📝

  • Github actions จะให้ Environment เปล่าๆมาเลย 🗂️ - ทุกครั้งที่รันจะได้ machine ใหม่
  • ต้อง checkout ⬇️ หรือต้อง clone code มาเองในทุกครั้ง - ใช้ actions/checkout เพื่อดึง code มา
  • Workflow file 📄 - เขียนใน .github/workflows/ เป็น YAML