กลับไปหน้าสูตร
#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> --failedrerun เฉพาะ 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=maintrigger manual
gh workflow run ci.yml -f env=stagingtrigger พร้อม input

Logs Strategy

Goalวิธีทำ
หา step ที่ fail จริงscroll จากท้ายขึ้นบน
แยก infra vs app errorเช็ก setup/tool install ก่อน
map เวลา failดู timestamps ใน step
isolate flakyrerun 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 deniedtoken scope ไม่พอ / file perms
Module not foundlockfile mismatch / cache เก่า
Command not foundruntime/toolchain ไม่ติดตั้ง
tests fail only in CIenv แตกต่าง local
timeoutnetwork/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 versioncompare matrix entries
fail เฉพาะ OSตรวจ path/separator/shell
nondeterministicpin 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 จาก forkwrite 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

StepAction
1ระบุ run-id ที่ fail ล่าสุด
2ดึง logs และ pinpoint step
3classify: infra/tool/app/test
4patch แบบ minimal
5rerun failed jobs
6ถ้าผ่าน ให้เพิ่ม guard/preventive check