Yesterday's tip on multi-line if statements in GitHub Actions got pretty far down in the weeds with how GitHub evaluates expressions.
Maybe you were wondering how I figured that out?
As with debugging application code, there are different approaches.
Usually step one is the simple dd()
approach, or in the context of GitHub Actions, just echo
ing out everything you can think of.
I'll admit, I start here. But if after a few attempts, I'm not making progress, I reach for a more powerful tool: step debugging.
I gave a whole talk about this in the context of Xdebug and a Laravel application, but what about GitHub Actions?
We can't attach to their process and literally step through it like application code, but we can get pretty close!
GitHub Actions has step debug logging which is extremely helpful. It breaks everything down token by token, making it easy to see where things are going wrong.
For example, from yesterday's tip, here's what the debug logging looked like for just my single if
check:
##[debug]Evaluating condition for step: 'Deploy to staging if develop branch'
##[debug]Evaluating: (success() && format('{0}
##[debug]', (((github.event_name == 'workflow_dispatch') && ... trimmed for length ...
##[debug]Evaluating And:
##[debug]..Evaluating success:
##[debug]..=> true
##[debug]..Evaluating format:
##[debug]....Evaluating String:
##[debug]....=> '{0}
##[debug]'
##[debug]....Evaluating Or:
##[debug]......Evaluating And:
##[debug]........Evaluating Equal:
##[debug]..........Evaluating Index:
##[debug]............Evaluating github:
##[debug]............=> Object
##[debug]............Evaluating String:
##[debug]............=> 'event_name'
##[debug]..........=> 'push'
##[debug]..........Evaluating String:
##[debug]..........=> 'workflow_dispatch'
##[debug]........=> false
##[debug]......=> false
##[debug]......Evaluating And:
##[debug]........Evaluating Equal:
##[debug]..........Evaluating Index:
##[debug]............Evaluating Index:
##[debug]..............Evaluating github:
##[debug]..............=> Object
##[debug]..............Evaluating String:
##[debug]..............=> 'event'
##[debug]............=> Object
##[debug]............Evaluating String:
##[debug]............=> 'name'
##[debug]..........=> null
##[debug]..........Evaluating String:
##[debug]..........=> 'workflow_run'
##[debug]........=> false
##[debug]......=> false
##[debug]....=> false
##[debug]..=> 'false
##[debug]'
##[debug]=> 'false
##[debug]'
##[debug]Expanded: (true && 'false
##[debug]')
##[debug]Result: 'false
##[debug]'
##[debug]Starting: Deploy to staging if develop branch
Whoa, that's a lot of detail, but it shows exactly where things are going wrong.
This isn't something you'll use a lot, but it comes in very handy when you need it.
Here to help,
Joel
P.S. Don't leave security as an afterthought. Start thinking about it now.