Skip to content

[plan] Apply shellcheck improvements (SC2129 redirects) #9126

@github-actions

Description

@github-actions

Objective

Fix 7 shellcheck warnings (SC2129) across 3 workflows by consolidating multiple redirect operations into grouped commands for better performance and code clarity.

Context

ShellCheck Rule SC2129: "Consider using { cmd1; cmd2; } >> file instead of individual redirects"

Why it matters:

  • Performance: Each redirect opens/closes the file separately
  • Efficiency: Grouped redirects open file once, write all content, close once
  • Code quality: More readable and maintainable

Impact Level: Low - These are style/performance improvements, not breaking errors.

Affected Workflows

Workflow Location Count
beads-worker.lock.yml Line 956 3 warnings
smoke-copilot-no-firewall.lock.yml Various 3 warnings
daily-choice-test.lock.yml Line 981 1 warning

Current Pattern (Inefficient)

# ❌ Multiple redirects - opens file 3 times
echo "line 1" >> output.txt
echo "line 2" >> output.txt
echo "line 3" >> output.txt

Each >> operation:

  1. Opens output.txt
  2. Seeks to end
  3. Writes content
  4. Closes file

Improved Pattern (Efficient)

# ✅ Grouped redirect - opens file once
{
  echo "line 1"
  echo "line 2"
  echo "line 3"
} >> output.txt

Single operation:

  1. Opens output.txt once
  2. Writes all content
  3. Closes file once

Fix Examples

Example 1: Simple echo statements

Before:

echo "Status: success" >> report.txt
echo "Time: $(date)" >> report.txt
echo "Files processed: $count" >> report.txt

After:

{
  echo "Status: success"
  echo "Time: $(date)"
  echo "Files processed: $count"
} >> report.txt

Example 2: Mixed commands

Before:

echo "=== Results ===" >> log.txt
cat results.json >> log.txt
echo "=== End ===" >> log.txt

After:

{
  echo "=== Results ==="
  cat results.json
  echo "=== End ==="
} >> log.txt

Example 3: With variables

Before:

echo "STEP_OUTPUT=$output" >> $GITHUB_ENV
echo "STEP_STATUS=$status" >> $GITHUB_ENV
echo "STEP_TIME=$time" >> $GITHUB_ENV

After:

{
  echo "STEP_OUTPUT=$output"
  echo "STEP_STATUS=$status"
  echo "STEP_TIME=$time"
} >> $GITHUB_ENV

Files to Modify

Markdown source files (fix these, then recompile):

  1. .github/workflows/beads-worker.md

    • Find the section around line 956 in compiled output
    • Consolidate 3 redirect operations
  2. .github/workflows/smoke-copilot-no-firewall.md

    • Find sections with multiple redirects
    • Consolidate 3 redirect operations
  3. .github/workflows/daily-choice-test.md

    • Find the section around line 981 in compiled output
    • Consolidate redirect operation

Validation Steps

  1. Locate the shell script block in markdown source
  2. Identify consecutive lines with >> same_file
  3. Wrap them in { ... } group with single redirect
  4. Recompile: make recompile
  5. Run shellcheck: shellcheck -x .github/workflows/{workflow}.lock.yml or via actionlint
  6. Verify SC2129 warnings are gone

Acceptance Criteria

  • All 7 SC2129 warnings resolved
  • All 3 affected workflows pass shellcheck
  • Redirects properly grouped with { ... } syntax
  • Workflows still function identically
  • No new shellcheck warnings introduced
  • Code is more readable

Testing

# After fixes
make recompile

# Validate with actionlint (includes shellcheck)
actionlint .github/workflows/beads-worker.lock.yml
actionlint .github/workflows/smoke-copilot-no-firewall.lock.yml
actionlint .github/workflows/daily-choice-test.lock.yml

# Or use gh-aw compile
gh aw compile --actionlint .github/workflows/beads-worker.md

Performance Impact

For files with many redirects, the improvement can be measurable:

# Benchmark example (10 redirects)
time for i in {1..10}; do echo "line $i" >> test.txt; done
# Real: 0.012s

time { for i in {1..10}; do echo "line $i"; done } >> test.txt
# Real: 0.003s
# ~4x faster

Additional Improvements

While fixing SC2129, also look for:

  • Unnecessary subshells
  • Inefficient loops with redirects
  • Multiple redirects to different files that could be grouped

References

AI generated by Plan Command for discussion #9119

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions