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
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
2οΈβ£ Most Common Failure Patterns (Real World)
β Missing code
package.json not found
Cause:
-
actions/checkoutmissing
Fix:
- uses: actions/checkout@v4
β Dependency failures
Cannot find module
Causes:
- wrong Node version
-
npm installinstead ofnpm ci - broken lockfile
β Secrets not available
API_KEY is undefined
Causes:
- forked PR
- wrong secret name
- missing
environment
β Permission errors
403 Resource not accessible by integration
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"
Print GitHub context (very useful)
- run: echo "${{ toJson(github) }}"
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
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'
Debug it:
- run: echo "Ref is $GITHUB_REF"
Common mistake:
main β refs/heads/main
7οΈβ£ Debugging Secrets Safely
Never print secret values.
Instead, check presence:
- run: echo "Secret exists: ${{ secrets.API_KEY != '' }}"
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)
Tips:
- check which combination failed
- reduce matrix size when debugging
- disable
fail-fasttemporarily
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)
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)