Skip to content

Add ShellCheck CI workflow#2

Merged
mlutonsky merged 4 commits intomainfrom
copilot/add-shellcheck-ci-workflow
Mar 14, 2026
Merged

Add ShellCheck CI workflow#2
mlutonsky merged 4 commits intomainfrom
copilot/add-shellcheck-ci-workflow

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 14, 2026

No CI existed in this repo. This adds a GitHub Actions workflow that runs ShellCheck on all shell scripts on every push and PR to main.

Changes

  • .github/workflows/shellcheck.yml: New workflow using actions/checkout@v4 + ludeeus/action-shellcheck@master
    • Scripts without .sh extensions (git-co, git-branch-clean, git-branch-close) are passed via additional_files; idle-power-manager.sh is picked up by the action's default scan
    • permissions: contents: read scopes the GITHUB_TOKEN to the minimum required
Original prompt

Add ShellCheck CI workflow

Add a GitHub Actions workflow file at .github/workflows/shellcheck.yml that runs ShellCheck on all shell scripts in the repository on every push and pull request to main.

The workflow should:

  • Trigger on push and pull_request targeting main
  • Run on ubuntu-latest
  • Use actions/checkout@v4 to check out the code
  • Use ludeeus/action-shellcheck@master to run ShellCheck
  • Target all shell scripts in the repo root: git-co, git-branch-clean, git-branch-close, idle-power-manager.sh

The scripts do not have .sh extensions (except idle-power-manager.sh), so make sure ShellCheck picks them all up — you can set the scandir to . or list files explicitly in the action config.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: How could I improve this repository?

Assistant: Here's a thorough review of your mlutonsky/utils repository with concrete suggestions across several areas:


🏗️ Repository & Project Structure

1. Add a license
The repo has no license file. Anyone who finds it won't know if they can use or adapt the scripts. A permissive license like MIT takes 30 seconds to add.

2. Add a repository description and topics
The GitHub repo has no description or topics set. Adding a one-line description ("Small shell utilities for git workflow and power management") and topics like shell, bash, git, gnome, productivity makes it more discoverable.

3. Add a top-level install.sh script
Every script currently requires a manual ln -s command. A single install.sh that symlinks all scripts to ~/.local/bin/ would make onboarding much easier.

4. Organize scripts into subdirectories (optional, but worth considering)
As the collection grows, a flat root directory will get cluttered. A structure like git/ and system/ would help.


🐚 Script Quality & Robustness

git-co

5. Add set -euo pipefail — None of the scripts use strict mode. git-co has numerous subshell calls and variable expansions that could silently fail.

6. Calling python3 in a loop is expensive
_levenshtein_distance() spawns a new python3 process for every branch, which can be very slow on a repo with many branches. Consider inlining the Levenshtein calculation in pure Bash (it's feasible for small strings), or batching all branch names into a single Python invocation.

7. git pull --all after git switch -c is unexpected
After tracking a new remote branch, git pull --all fetches and pulls all remotes, which is likely unintentional. git pull or even nothing (since git switch -c branch origin/branch already sets up tracking) would be more appropriate.

8. Input validation is missing
No check that $selection is actually a number before the -gt 0 comparison — this can produce a cryptic Bash error ([: foo: integer expression expected).

git-branch-clean

9. Uses git branch -D (force delete) instead of -d
-D will delete branches even if they have unmerged commits. Since the intent is to clean up branches whose remote is gone (presumably merged), -d is safer and will warn if something looks wrong.

10. No exit code on fetch failure
If git fetch --prune fails (e.g., no network), the script silently continues and may incorrectly delete branches. It should check the exit code:

git fetch --prune || { echo "fatal: failed to fetch from origin"; exit 1; }

git-branch-close

11. Already solid! This is the most robust of the three git scripts — good use of || { ... ; exit 1; } error handling throughout.

12. Minor: could add a --dry-run flag to preview what would happen without making any changes.

idle-power-manager.sh

13. Log rotation is missing
The log file grows unboundedly. With CHECK_INTERVAL=30 it writes ~2 lines/minute → ~1 MB/day. Consider capping the log size or using logger to send output to systemd journal instead (which journalctl already manages).

14. switch_profile success check is fragile

if echo "$result" | grep -q "true"; then

This would match any string containing "true" (e.g., an error message that says "profile 'true-performance' not found"). Checking the exit code of gdbus call directly would be more reliable.

15. No DBUS_SESSION_BUS_ADDRESS fallback
When run as a systemd user service, DBUS_SESSION_BUS_ADDRESS is usually inherited, but it's not guaranteed. A fallback like:

export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/$(id -u)/bus}"

…would make the service more resilient.


✅ Testing & CI

16. Add a GitHub Actions workflow
There's no CI at all. Even a simple ShellCheck workflow would catch common bash bugs automatically:

name: ShellCheck
on: [push, pull_request]
job...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: mlutonsky <423848+mlutonsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ShellCheck CI workflow for shell scripts Add ShellCheck CI workflow Mar 14, 2026
Copilot AI requested a review from mlutonsky March 14, 2026 18:04
@mlutonsky mlutonsky marked this pull request as ready for review March 14, 2026 18:05
Copilot AI review requested due to automatic review settings March 14, 2026 18:05
@mlutonsky
Copy link
Copy Markdown
Owner

mlutonsky commented Mar 14, 2026

@copilot When I ran the GH action, it failed on some scripts. Also fix the scripts according to the shellcheck

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial CI to the repo by introducing a GitHub Actions workflow that runs ShellCheck against the repository’s shell scripts on pushes and PRs to main.

Changes:

  • Add a new GitHub Actions workflow to run ShellCheck on ubuntu-latest.
  • Configure the workflow to include non-.sh scripts via additional_files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…in git-co

Co-authored-by: mlutonsky <423848+mlutonsky@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Mar 14, 2026

@copilot When I ran the GH action, it failed on some scripts. Also fix the scripts according to the shellcheck

Fixed in cf45f11. Two issues addressed:

  1. Workflow action tagludeeus/action-shellcheck@v2.0.0@2.0.0 (the release tag has no v prefix, which caused the "unable to find version" error)
  2. git-co ShellCheck warnings — fixed all 7 findings:
    • SC2155: split local var=$(...) into separate local var / var=$(...) declarations (6 instances)
    • SC2162: added -r to read to prevent backslash mangling (1 instance)

git-branch-clean, git-branch-close, and idle-power-manager.sh were already clean.

Copilot AI requested a review from mlutonsky March 14, 2026 18:15
@mlutonsky mlutonsky merged commit fc47161 into main Mar 14, 2026
1 check passed
@mlutonsky mlutonsky deleted the copilot/add-shellcheck-ci-workflow branch March 14, 2026 18:44
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.

3 participants