DEV Community

Cover image for GitHub Actions: From Zero to Production(EP9)πŸš€
Vishwark
Vishwark

Posted on

GitHub Actions: From Zero to Production(EP9)πŸš€

Episode 9 – Debugging & Troubleshooting GitHub Actions

If you’ve written a few GitHub Actions workflows, you’ve probably faced this situation:

❌ The workflow failed
❓ The error message makes no sense
πŸ˜• Re-running sometimes β€œfixes” it

This episode is about debugging GitHub Actions effectively β€” the skill that separates someone who knows the syntax from someone who can operate CI/CD in real projects.


Why Debugging Matters

CI/CD pipelines:

  • run on remote machines
  • use ephemeral environments
  • rely on permissions and secrets
  • fail silently sometimes

That means:

Debugging is not optional β€” it’s a core skill.


1️⃣ How to Read GitHub Actions Logs Properly

When a workflow fails, always follow this order:

Actions tab
 β†’ Workflow run
   β†’ Job
     β†’ Step
Enter fullscreen mode Exit fullscreen mode

What to focus on:

  • ❗ The first error, not the last line
  • ❌ Exit codes (exit 1, command failed)
  • 🧱 Which step failed (step names matter!)
  • ⏱️ Sudden slow steps (performance issues)

πŸ‘‰ Always name your steps clearly:

- name: Install dependencies
  run: npm ci
Enter fullscreen mode Exit fullscreen mode

2️⃣ Most Common Failure Patterns (Real World)

❌ Missing code

package.json not found
Enter fullscreen mode Exit fullscreen mode

Cause:

  • actions/checkout missing

Fix:

- uses: actions/checkout@v4
Enter fullscreen mode Exit fullscreen mode

❌ Dependency failures

Cannot find module
Enter fullscreen mode Exit fullscreen mode

Causes:

  • wrong Node version
  • npm install instead of npm ci
  • broken lockfile

❌ Secrets not available

API_KEY is undefined
Enter fullscreen mode Exit fullscreen mode

Causes:

  • forked PR
  • wrong secret name
  • missing environment

❌ Permission errors

403 Resource not accessible by integration
Enter fullscreen mode Exit fullscreen mode

Causes:

  • missing permissions
  • read-only GITHUB_TOKEN
  • restricted fork context

3️⃣ Debugging with Logs (Safely)

Print environment details

- run: |
    echo "Branch: $GITHUB_REF"
    echo "Actor: $GITHUB_ACTOR"
Enter fullscreen mode Exit fullscreen mode

Print GitHub context (very useful)

- run: echo "${{ toJson(github) }}"
Enter fullscreen mode Exit fullscreen mode

This helps you understand:

  • which event triggered the workflow
  • branch vs PR context
  • actor permissions

4️⃣ Enable Debug Mode (Powerful Feature)

GitHub supports debug logging via secrets.

Add repository secrets:

ACTIONS_STEP_DEBUG = true
ACTIONS_RUNNER_DEBUG = true
Enter fullscreen mode Exit fullscreen mode

What you get:

  • condition evaluations
  • cache hit/miss logs
  • detailed action internals

⚠️ Remove after debugging β€” logs become noisy.


5️⃣ Reruns: Use Them Correctly

GitHub allows:

  • Re-run all jobs
  • Re-run failed jobs

Reruns are useful for:

  • flaky network issues
  • temporary outages
  • transient errors

❗ If reruns β€œfix” issues often, your pipeline is not deterministic.


6️⃣ Debugging if: Conditions

Steps silently skip if conditions fail.

Example:

if: github.ref == 'refs/heads/main'
Enter fullscreen mode Exit fullscreen mode

Debug it:

- run: echo "Ref is $GITHUB_REF"
Enter fullscreen mode Exit fullscreen mode

Common mistake:

main β‰  refs/heads/main
Enter fullscreen mode Exit fullscreen mode

7️⃣ Debugging Secrets Safely

Never print secret values.

Instead, check presence:

- run: echo "Secret exists: ${{ secrets.API_KEY != '' }}"
Enter fullscreen mode Exit fullscreen mode

Checklist:

  • correct secret name
  • correct scope (repo vs environment)
  • environment specified
  • not a fork PR

8️⃣ Debugging Matrix Jobs

Matrix jobs fail independently.

Example job name:

test (ubuntu-latest, node 20)
Enter fullscreen mode Exit fullscreen mode

Tips:

  • check which combination failed
  • reduce matrix size when debugging
  • disable fail-fast temporarily

9️⃣ Senior-Level Debugging Habits ⭐

βœ… Small, focused steps
βœ… One responsibility per step
βœ… Explicit permissions
βœ… Log context early
βœ… Avoid long inline scripts
βœ… Fail fast, not silently

Boring pipelines are good pipelines.


Final Mental Model (Lock This In)

Failure
  β†’ Identify step
    β†’ Identify cause
      β†’ Fix root problem (not symptoms)
Enter fullscreen mode Exit fullscreen mode

If you follow this flow, debugging becomes predictable.


What’s Next?

πŸ‘‰ Episode 10 (Final):
Production CI/CD for Frontend Apps (GitHub Pages, React & Vite)

We’ll bring everything together:

  • clean CI
  • protected CD
  • real deployment patterns

This final episode turns knowledge into production-ready confidence πŸš€


Thanks for reading!
Debug with confidence πŸ‘‹

Top comments (0)