Skip to content

Commit 4a76752

Browse files
committed
fix: boolean comparison gotcha in github action expressions
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 9e70984 commit 4a76752

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.claude/skills/github-actions.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,33 @@ Brief description of what the action does.
427427

428428
## Common Gotchas
429429

430-
1. **Expression evaluation in descriptions**: Don't use `${{ }}` in action.yml description fields
431-
2. **Race conditions**: Always use optimistic execution + error handling, never check-then-act
432-
3. **Secret exposure**: Never use `secrets[inputs.name]` - always use explicit secret parameters
433-
4. **Branch deletion**: Use `wait-pending-jobs` before merging to prevent failures in non-required jobs
434-
5. **Idempotency**: `gh pr merge --auto` is NOT idempotent - handle "Merge already in progress" error
435-
6. **TOCTOU vulnerabilities**: State can change between check and action - handle at runtime
430+
1. **Boolean input comparisons**: GitHub Actions inputs are strongly typed, with no "JS-like" truthy logic
431+
```yaml
432+
# ❌ WRONG - Boolean true is NOT equal to string 'true'
433+
on:
434+
workflow_call:
435+
inputs:
436+
enable-feature:
437+
type: boolean
438+
default: true
439+
440+
jobs:
441+
my-job:
442+
if: ${{ inputs.enable-feature == 'true' }} # FALSE when input is boolean true!
443+
444+
# ✅ CORRECT - Handle both boolean and string values
445+
if: ${{ inputs.enable-feature == 'true' || inputs.enable-feature == true }}
446+
447+
# Note: In bash, this works fine because bash converts to string:
448+
if [[ '${{ inputs.enable-feature }}' == 'true' ]]; then # Works in bash
449+
```
450+
451+
2. **Expression evaluation in descriptions**: Don't use `${{ }}` in action.yml description fields
452+
3. **Race conditions**: Always use optimistic execution + error handling, never check-then-act
453+
4. **Secret exposure**: Never use `secrets[inputs.name]` - always use explicit secret parameters
454+
5. **Branch deletion**: Use `wait-pending-jobs` before merging to prevent failures in non-required jobs
455+
6. **Idempotency**: `gh pr merge --auto` is NOT idempotent - handle "Merge already in progress" error
456+
7. **TOCTOU vulnerabilities**: State can change between check and action - handle at runtime
436457

437458
## Testing Workflows
438459

.github/workflows/auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
contents: write
6969
pull-requests: write
7070
runs-on: ubuntu-latest
71-
if: ${{ inputs.enable-organization-bot == 'true' && github.event.pull_request.user.login == inputs.organization-bot }}
71+
if: ${{ (inputs.enable-organization-bot == 'true' || inputs.enable-organization-bot == true) && github.event.pull_request.user.login == inputs.organization-bot }}
7272
env:
7373
PR_URL: ${{ github.event.pull_request.html_url }}
7474
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)