Skip to content

Fix SC2129 shellcheck errors: use brace group redirects#572

Open
thpierce wants to merge 2 commits intomainfrom
fix-SC2129-shellcheck-errors
Open

Fix SC2129 shellcheck errors: use brace group redirects#572
thpierce wants to merge 2 commits intomainfrom
fix-SC2129-shellcheck-errors

Conversation

@thpierce
Copy link
Contributor

Summary

This PR fixes all SC2129 shellcheck warnings by replacing multiple individual redirects with brace group redirects, following shellcheck best practices.

What Changed

Before (SC2129 violation):

echo "VAR1=value1" >> $GITHUB_ENV
echo "VAR2=value2" >> $GITHUB_ENV
echo "VAR3=value3" >> $GITHUB_ENV

After (SC2129 compliant):

{
  echo "VAR1=value1"
  echo "VAR2=value2"
  echo "VAR3=value3"
} >> $GITHUB_ENV

Files Modified

Configuration:

  • .github/workflows/pr-build.yml: Removed SC2129 from ignore list and comment

Workflow Files (17 files):

  1. .github/workflows/dotnet-ec2-adot-sigv4-test.yml (line 144-147)
  2. .github/workflows/dotnet-ec2-asg-test.yml (line 193-197)
  3. .github/workflows/dotnet-ec2-default-test.yml (line 183-186)
  4. .github/workflows/dotnet-ec2-nuget-test.yml (line 165-168)
  5. .github/workflows/dotnet-ec2-windows-test.yml (line 182-186)
  6. .github/workflows/java-ec2-adaptive-sampling-test.yml (line 135-139)
  7. .github/workflows/java-ec2-adot-sigv4-test.yml (line 166-169)
  8. .github/workflows/java-ec2-asg-test.yml (line 213-217)
  9. .github/workflows/java-ec2-default-test.yml (line 204-207)
  10. .github/workflows/java-ec2-ubuntu-test.yml (line 176-179)
  11. .github/workflows/node-ec2-adot-sigv4-test.yml (line 159-162)
  12. .github/workflows/node-ec2-asg-test.yml (line 196-200)
  13. .github/workflows/node-ec2-default-test.yml (line 197-200)
  14. .github/workflows/python-ec2-adaptive-sampling-test.yml (line 142-146)
  15. .github/workflows/python-ec2-asg-test.yml (line 216-220)
  16. .github/workflows/python-ec2-default-test.yml (line 206-209)
  17. .github/workflows/python-ec2-genesis-test.yml (line 71-79)

Why This Change is Safe

This is a code quality improvement with no functional impact:

  1. Identical Behavior: Brace group redirects produce exactly the same output as multiple individual redirects
  2. Same Exit Codes: Both patterns preserve command exit codes identically
  3. Same File Operations: Both create/append to files in the same way
  4. No Logic Changes: Only the redirect syntax changed; all commands remain identical

Testing

Actionlint Validation

Command used:

actionlint -color -ignore SC2086 -ignore SC2004 -ignore SC2016 -ignore SC2010 -ignore SC2015 -ignore SC2260 -ignore SC2046 -ignore SC2181 .github/workflows/*.yml

Result: ✅ Exit code 0 (all SC2129 errors resolved)

Behavioral Tests

All tests passed confirming identical behavior:

Test 1: Basic multiple redirects

  • ✅ PASS: Basic redirects produce identical output

Test 2: Command substitution

  • ✅ PASS: Command substitution works identically (e.g., terraform output)

Test 3: Mixed variables and command substitution

  • ✅ PASS: Mixed variables work identically

Test 4: Exit code preservation on success

  • ✅ PASS: Exit codes match on success (both 0)

Test 5: File creation behavior

  • ✅ PASS: Both create files identically

Test 6: Append to existing file

  • ✅ PASS: Append behavior identical

What Each Test Validates

  1. Output Equivalence: Verifies byte-for-byte identical file content
  2. Command Substitution: Tests $(terraform output ...) patterns used in workflows
  3. Variable Expansion: Tests $var patterns used in workflows
  4. Exit Codes: Confirms error handling behavior is preserved
  5. File Operations: Validates append mode works identically
  6. Edge Cases: Tests file creation when file doesn't exist

Impact Assessment

Category: Code Quality Improvement

Risk Level: Minimal

  • No functional changes to workflow logic
  • No changes to environment variable values
  • No changes to command execution order
  • Comprehensive testing confirms behavioral equivalence

Benefits:

  • Cleaner, more maintainable code
  • Follows shellcheck best practices
  • Reduces technical debt
  • One less ignored shellcheck rule

Additional Notes

  • This change affects only the syntax of how environment variables are written to $GITHUB_ENV
  • All workflow functionality remains unchanged
  • The brace group pattern is more efficient (opens file once vs multiple times)
  • This is part of the systematic effort to remove shellcheck suppressions (see TODO comment in pr-build.yml)

Replace multiple individual redirects (>> file) with brace group redirects
({ cmd1; cmd2; } >> file) to improve code quality and follow shellcheck
best practices.

Changes:
- Converted all instances of multiple echo >> $GITHUB_ENV to brace groups
- Removed SC2129 from actionlint ignore list in pr-build.yml

Files modified:
- .github/workflows/pr-build.yml (removed SC2129 from ignore list)
- .github/workflows/dotnet-ec2-adot-sigv4-test.yml (line 144-147)
- .github/workflows/dotnet-ec2-asg-test.yml (line 193-197)
- .github/workflows/dotnet-ec2-default-test.yml (line 183-186)
- .github/workflows/dotnet-ec2-nuget-test.yml (line 165-168)
- .github/workflows/dotnet-ec2-windows-test.yml (line 182-186)
- .github/workflows/java-ec2-adaptive-sampling-test.yml (line 135-139)
- .github/workflows/java-ec2-adot-sigv4-test.yml (line 166-169)
- .github/workflows/java-ec2-asg-test.yml (line 213-217)
- .github/workflows/java-ec2-default-test.yml (line 204-207)
- .github/workflows/java-ec2-ubuntu-test.yml (line 176-179)
- .github/workflows/node-ec2-adot-sigv4-test.yml (line 159-162)
- .github/workflows/node-ec2-asg-test.yml (line 196-200)
- .github/workflows/node-ec2-default-test.yml (line 197-200)
- .github/workflows/python-ec2-adaptive-sampling-test.yml (line 142-146)
- .github/workflows/python-ec2-asg-test.yml (line 216-220)
- .github/workflows/python-ec2-default-test.yml (line 206-209)
- .github/workflows/python-ec2-genesis-test.yml (line 71-79)

Testing: Comprehensive behavioral tests confirm identical functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant