Skip to content

Consolidate consecutive shell redirects to fix SC2129 warnings#9153

Merged
pelikhan merged 2 commits intomainfrom
copilot/apply-shellcheck-improvements
Jan 6, 2026
Merged

Consolidate consecutive shell redirects to fix SC2129 warnings#9153
pelikhan merged 2 commits intomainfrom
copilot/apply-shellcheck-improvements

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 6, 2026

Shellcheck SC2129 warns about inefficient consecutive redirects to the same file. Each >> operation opens/closes the file separately; grouped redirects open once, write all, close once.

Changes

pkg/workflow/mcp_servers.go

  • Consolidated 2 consecutive redirects to $GITHUB_OUTPUT into single grouped command
  • Applies to all workflows using MCP servers with safe-inputs

github/workflows/daily-choice-test.md

  • Consolidated 3 consecutive redirects to $GITHUB_STEP_SUMMARY into single grouped command

Pattern

Before:

echo "safe_inputs_api_key=${API_KEY}" >> "$GITHUB_OUTPUT"
echo "safe_inputs_port=${PORT}" >> "$GITHUB_OUTPUT"

After:

{
  echo "safe_inputs_api_key=${API_KEY}"
  echo "safe_inputs_port=${PORT}"
} >> "$GITHUB_OUTPUT"

Eliminates all SC2129 warnings across 125 workflows (verified with shellcheck).

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Apply shellcheck improvements (SC2129 redirects)</issue_title>
<issue_description>## 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

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ShellCheck warnings by consolidating redirects Consolidate consecutive shell redirects to fix SC2129 warnings Jan 6, 2026
Copilot AI requested a review from mnkiefer January 6, 2026 18:13
@pelikhan pelikhan marked this pull request as ready for review January 6, 2026 18:15
@pelikhan pelikhan merged commit bb3ef97 into main Jan 6, 2026
69 checks passed
@pelikhan pelikhan deleted the copilot/apply-shellcheck-improvements branch January 6, 2026 18:15
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.

[plan] Apply shellcheck improvements (SC2129 redirects)

3 participants