กลับไปหน้าสูตร
#github#actions#workflow#cheatsheet
GitHub Actions Workflow Debugging Cheatsheet
คู่มือ debug GitHub Actions แบบจัดเต็ม: run analysis, logs, rerun, matrix failures, artifacts, permissions และ flaky CI
11 มีนาคม 2569อ่านประมาณ 3 นาที
สารบัญสูตร
Quick Triage with gh
| Command | ใช้ทำอะไร |
|---|---|
gh run list --limit 20 | ดู runs ล่าสุด |
gh run view <run-id> | ดู run summary |
gh run view <run-id> --log | ดู logs ทั้งหมด |
gh run rerun <run-id> | rerun ทั้ง workflow |
gh run rerun <run-id> --failed | rerun เฉพาะ jobs ที่ fail |
gh run cancel <run-id> | ยกเลิก run |
Workflow Inspection
| Command | ใช้ทำอะไร |
|---|---|
gh workflow list | ดู workflows |
gh workflow view ci.yml | ดู workflow config |
gh workflow run ci.yml -f ref=main | trigger manual |
gh workflow run ci.yml -f env=staging | trigger พร้อม input |
Logs Strategy
| Goal | วิธีทำ |
|---|---|
| หา step ที่ fail จริง | scroll จากท้ายขึ้นบน |
| แยก infra vs app error | เช็ก setup/tool install ก่อน |
| map เวลา fail | ดู timestamps ใน step |
| isolate flaky | rerun failed jobs compare logs |
Enable Debug Logging
| วิธี | รายละเอียด |
|---|---|
| Secrets | ตั้ง ACTIONS_RUNNER_DEBUG=true |
| Secrets | ตั้ง ACTIONS_STEP_DEBUG=true |
| ใน workflow | เพิ่ม set -euxo pipefail ใน shell steps |
Common Failure Patterns
| อาการ | Root cause ที่เจอบ่อย |
|---|---|
Permission denied | token scope ไม่พอ / file perms |
Module not found | lockfile mismatch / cache เก่า |
Command not found | runtime/toolchain ไม่ติดตั้ง |
| tests fail only in CI | env แตกต่าง local |
| timeout | network/dependency install ช้า |
Cache Debug
| Check | คำอธิบาย |
|---|---|
| cache key stable ไหม | อย่าใช้ key กว้างเกิน |
| restore key ถูกไหม | เสี่ยงดึง cache ผิดเวอร์ชัน |
| lockfile เปลี่ยนแล้ว key เปลี่ยนไหม | ต้องผูกกับ lockfile hash |
| stale cache | ลอง disable cache เทียบผล |
Matrix Build Debug
| ปัญหา | วิธีเช็ก |
|---|---|
| fail เฉพาะ node version | compare matrix entries |
| fail เฉพาะ OS | ตรวจ path/separator/shell |
| nondeterministic | pin versions ของ tools |
Artifacts / Evidence
| Command | ใช้ทำอะไร |
|---|---|
gh run download <run-id> | ดาวน์โหลด artifacts |
| อัปโหลด logs/report | เก็บหลักฐานสำหรับทีม review |
| เก็บ test report | ใช้เปรียบเทียบ run-to-run |
Permissions Model
| เรื่อง | แนวทาง |
|---|---|
GITHUB_TOKEN permissions | ระบุ permissions: ชัดใน workflow |
| PR จาก fork | write permissions ถูกจำกัด |
| release/publish jobs | ใช้ PAT/OIDC ตาม policy |
Workflow Hardening
| แนวทาง | ประโยชน์ |
|---|---|
| fail fast | รู้ปัญหาเร็ว |
| concurrency groups | กัน run ซ้อน branch เดียว |
| retry policy | ลด flaky จาก network |
| timeout-minutes | ป้องกัน stuck jobs |
| explicit shell | ลดพฤติกรรมต่าง platform |
Minimal Debug Step Snippet
- name: Debug env
run: |
set -euxo pipefail
node -v
npm -v
git rev-parse --short HEAD
env | sort
Incident Playbook
| Step | Action |
|---|---|
| 1 | ระบุ run-id ที่ fail ล่าสุด |
| 2 | ดึง logs และ pinpoint step |
| 3 | classify: infra/tool/app/test |
| 4 | patch แบบ minimal |
| 5 | rerun failed jobs |
| 6 | ถ้าผ่าน ให้เพิ่ม guard/preventive check |