Skip to content

chore: Enhance Rubocop workflow#2123

Draft
mrhoribu wants to merge 7 commits intomasterfrom
chore/workflow-rubocop-automation
Draft

chore: Enhance Rubocop workflow#2123
mrhoribu wants to merge 7 commits intomasterfrom
chore/workflow-rubocop-automation

Conversation

@mrhoribu
Copy link
Contributor

@mrhoribu mrhoribu commented Nov 4, 2025

Added permissions for GitHub Actions and improved the workflow to handle changed files more effectively, including auto-correction and committing changes.


Important

Enhances Rubocop workflow with permissions, improved file change detection, and automated corrections and commits, while respecting protected branches.

  • Permissions:
    • Added contents: write permission to .github/workflows/rubocop_syntax_checker.yaml.
  • File Change Detection:
    • Improved detection of changed files using git diff and filtering for .rb, .rbw, and .lic extensions.
    • Handles new branches by comparing with the default branch.
  • Autocorrection and Commit:
    • Runs rubocop -a on changed files and commits changes if not on protected branches (master or main).
    • Configures Git user for commits as github-actions[bot].
    • Skips auto-commit on protected branches and logs errors if changes are needed.
  • Misc:
    • Updated job steps for clarity and added logging for actions taken.

This description was created by Ellipsis for 6f54897. You can customize this summary. It will automatically update as commits are pushed.

Added permissions for GitHub Actions and improved the workflow to handle changed files more effectively, including auto-correction and committing changes.
ellipsis-dev[bot]

This comment was marked as outdated.

@mrhoribu

This comment was marked as outdated.

ellipsis-dev[bot]

This comment was marked as outdated.

Refactor GitHub Actions workflow to improve push handling for Rubocop autocorrections, including better error handling for protected branches.
@mrhoribu

This comment was marked as outdated.

ellipsis-dev[bot]

This comment was marked as outdated.

@mrhoribu

This comment was marked as outdated.

ellipsis-dev[bot]

This comment was marked as outdated.

@mrhoribu mrhoribu marked this pull request as draft November 4, 2025 16:44
Updated Rubocop workflow to simplify branch handling and remove unnecessary checks.
@mrhoribu
Copy link
Contributor Author

mrhoribu commented Nov 4, 2025

@ellipsis remove previous comments and review again

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 6f54897 in 4 minutes and 39 seconds. Click for details.
  • Reviewed 162 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. .github/workflows/rubocop_syntax_checker.yaml:21
  • Draft comment:
    Consider using a semantic version tag (e.g. 'v5.0.0') instead of a commit SHA for actions/checkout for better maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. .github/workflows/rubocop_syntax_checker.yaml:40
  • Draft comment:
    Ensure that the default branch detection via 'git symbolic-ref' reliably works in all repository configurations.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. .github/workflows/rubocop_syntax_checker.yaml:53
  • Draft comment:
    Verify that including files with the '.lic' extension in the Rubocop filtering is intentional.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. .github/workflows/rubocop_syntax_checker.yaml:68
  • Draft comment:
    Autocorrect errors are being suppressed with a warning. Confirm that continuing execution despite autocorrect issues is acceptable.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. .github/workflows/rubocop_syntax_checker.yaml:80
  • Draft comment:
    Double-check that skipping auto-commit on 'master' and 'main' aligns with your branch protection policy.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
6. .github/workflows/rubocop_syntax_checker.yaml:99
  • Draft comment:
    When pushing changes, consider more granular error handling and cleanup (e.g. removing temporary files) to make debugging easier on push failures.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_rjdhZCGlljL3Y3rv

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced code style checking workflow with improved branch handling and file change detection logic.
    • Updated workflow protections to safely handle protected branches.
    • Fixed formatting in utility script.

Walkthrough

The GitHub Actions workflow for Rubocop syntax checking was restructured with enhanced permissions and a multi-step process. Changes include workflow-level write permissions, improved checkout authentication, explicit base reference determination, changed file detection using git diff, conditional autocorrect execution, guarded commit operations with protected branch protections, and updated reporting logic.

Changes

Cohort / File(s) Summary
Rubocop Workflow Enhancement
.github/workflows/rubocop_syntax_checker.yaml
Restructured workflow with added permissions, enhanced checkout, base reference detection logic, changed file computation, conditional autocorrect with protected branch safeguards, and improved summary reporting.
Script Formatting
scripts/go2.lic
Minor indentation adjustment to chained .each block; no functional changes.

Sequence Diagram

sequenceDiagram
    actor GitHub as GitHub Events
    participant Workflow as Rubocop Workflow
    participant Git as Git Commands
    participant Rubocop as Rubocop Tool
    participant GitOps as Commit/Push
    
    GitHub->>Workflow: Trigger (push/pull_request)
    Workflow->>Git: Checkout with GITHUB_TOKEN
    Workflow->>Workflow: Determine base reference
    Workflow->>Git: Detect changed .rb/.rbw/.lic files
    alt Changed files detected
        Workflow->>Rubocop: Run autocorrect
        alt Not protected branch
            Workflow->>GitOps: Commit and push changes
        else Protected branch (master/main)
            Workflow->>Workflow: Skip or warn
        end
    end
    Workflow->>Rubocop: Run checks on changed files
    Workflow->>Workflow: Report results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: Enhance Rubocop workflow' directly and clearly summarizes the main change: enhancements to the Rubocop workflow configuration.
Description check ✅ Passed The description comprehensively explains the changes: permissions additions, improved file detection, autocorrection with protected branch handling, and configuration details—all aligned with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/workflow-rubocop-automation
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/rubocop_syntax_checker.yaml:
- Around line 104-125: The current push error handling in the git push block
treats protected-branch rejections as a warning and exits 0, which allows
subsequent RuboCop steps to run against unpushed local commits; update the
handler in the block that inspects PUSH_EXIT_CODE and /tmp/push_output.txt so
that when grep detects "protected branch|permission|prohibited|rejected" it
emits the warning messages but then exits non‑zero (exit 1) instead of exit 0.
Keep the existing echo "::warning::" lines for context, but change the final
control flow so protected/permission push failures fail the job (use exit 1) —
this affects the git push handling around the PUSH_EXIT_CODE logic and the grep
check that reads /tmp/push_output.txt.
- Around line 60-61: The git diff command currently uses --diff-filter=ACM and
lacks rename detection; update the invocation used in the rubocop_syntax_checker
workflow (the git diff --name-only --diff-filter=ACM -z "${{
steps.base_ref.outputs.compare_ref }}" HEAD | grep -zE ...) to include renamed
files and detect renames by adding R to the diff-filter and the -M flag (i.e.,
use --diff-filter=ACMR and include -M immediately after git diff) so renamed
.rb, .rbw, and .lic files are captured for RuboCop checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b77d68ec-5acd-4dad-b03d-b1096aab8a18

📥 Commits

Reviewing files that changed from the base of the PR and between f5be376 and d277e2a.

📒 Files selected for processing (3)
  • .github/workflows/rubocop_syntax_checker.yaml
  • scripts/bodega.lic
  • scripts/go2.lic

Comment on lines +60 to +61
git diff --name-only --diff-filter=ACM -z "${{ steps.base_ref.outputs.compare_ref }}" HEAD | \
grep -zE '\.(rb|rbw|lic)$' > /tmp/changed_files.txt || true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's understand the git diff filter flags
git diff --help | grep -A 20 "diff-filter" || echo "Checking git documentation..."

Repository: elanthia-online/scripts

Length of output: 211


🏁 Script executed:

# Let's also examine the full workflow file to understand the context
cat -n .github/workflows/rubocop_syntax_checker.yaml | head -80

Repository: elanthia-online/scripts

Length of output: 3484


🌐 Web query:

git diff --diff-filter flags documentation ACM ACMR renamed files

💡 Result:

git diff --diff-filter=<flags> lets you include or exclude paths by change type. The flag letters mean: Added, Copied, Deleted, Modified, Renamed, Type-changed, Unmerged, Xunknown, Broken pairing. You can combine them (e.g. ACMR). You can also lowercase a letter to exclude that type (e.g. --diff-filter=ad excludes added+deleted). An optional * means “all-or-none”. [1]

About renamed files (R)

  • R entries only appear if rename detection is enabled (e.g. -M / --find-renames, or your config enables it). If rename detection is off, you won’t get R even if a rename happened. [1]

Common examples

# Only renamed paths (plus show old/new names)
git diff -M --name-status --diff-filter=R <rev1> <rev2>

# Added, Copied, Modified, Renamed (exclude Deletes)
git diff -M --name-status --diff-filter=ACMR <rev1> <rev2>

# Everything except Added and Deleted
git diff --diff-filter=ad <rev1> <rev2>

Docs: diff-options (covers --diff-filter and -M/--find-renames). [1]

Sources
[1] Git documentation: diff options (--diff-filter, -M/--find-renames, exclude via lowercase, *). (git-scm.com)

Citations:


Include renamed files in the diff filter and enable rename detection.

--diff-filter=ACM excludes R (renamed files), and without the -M flag, git diff won't detect renames at all. Both changes are needed to ensure renamed .rb, .rbw, and .lic files are checked by RuboCop.

🛠️ Suggested change
-          git diff --name-only --diff-filter=ACM -z "${{ steps.base_ref.outputs.compare_ref }}" HEAD | \
+          git diff -M --name-only --diff-filter=ACMR -z "${{ steps.base_ref.outputs.compare_ref }}" HEAD | \
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
git diff --name-only --diff-filter=ACM -z "${{ steps.base_ref.outputs.compare_ref }}" HEAD | \
grep -zE '\.(rb|rbw|lic)$' > /tmp/changed_files.txt || true
git diff -M --name-only --diff-filter=ACMR -z "${{ steps.base_ref.outputs.compare_ref }}" HEAD | \
grep -zE '\.(rb|rbw|lic)$' > /tmp/changed_files.txt || true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/rubocop_syntax_checker.yaml around lines 60 - 61, The git
diff command currently uses --diff-filter=ACM and lacks rename detection; update
the invocation used in the rubocop_syntax_checker workflow (the git diff
--name-only --diff-filter=ACM -z "${{ steps.base_ref.outputs.compare_ref }}"
HEAD | grep -zE ...) to include renamed files and detect renames by adding R to
the diff-filter and the -M flag (i.e., use --diff-filter=ACMR and include -M
immediately after git diff) so renamed .rb, .rbw, and .lic files are captured
for RuboCop checks.

Comment on lines +104 to +125
if git add -u && git commit -m "Auto-fix: Apply rubocop autocorrections [skip ci]"; then
# Attempt to push and capture the exit code
if git push origin "HEAD:${{ github.ref_name }}" 2>&1 | tee /tmp/push_output.txt; then
echo "Successfully pushed autocorrect changes"
else
PUSH_EXIT_CODE=$?

# Check if push failed due to protected branch or permissions (exit code 1)
# GitHub's push rejection for protected branches typically uses exit code 1
if [ $PUSH_EXIT_CODE -eq 1 ]; then
# Additional check: look for common protected branch indicators in output
if grep -qiE "(protected branch|permission|prohibited|rejected)" /tmp/push_output.txt; then
echo "::warning::Cannot push to protected branch or insufficient permissions."
echo "::warning::Rubocop fixes were not committed. Please apply rubocop fixes manually or adjust branch protection rules."
exit 0
fi
fi

# For any other push failure, report as error
echo "::error::Failed to push changes (exit code: $PUSH_EXIT_CODE)"
cat /tmp/push_output.txt
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don't let an unpushable autofix commit report success.

By this point the fixes are already committed locally. Returning 0 on a push rejection lets the later RuboCop step run against that local-only commit, so the job can go green while the branch still lacks the fixes. Since master and main are already gated above, this path should fail instead of warning-only.

🛠️ Suggested change
-                  if grep -qiE "(protected branch|permission|prohibited|rejected)" /tmp/push_output.txt; then
-                    echo "::warning::Cannot push to protected branch or insufficient permissions."
-                    echo "::warning::Rubocop fixes were not committed. Please apply rubocop fixes manually or adjust branch protection rules."
-                    exit 0
+                  if grep -qiE "(protected branch|permission|prohibited|rejected)" /tmp/push_output.txt; then
+                    echo "::error::Autocorrect changes were committed locally but could not be pushed back to ${{ github.ref_name }}."
+                    echo "::error::Please apply the fixes locally or update branch protection/permissions."
+                    exit 1
                   fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/rubocop_syntax_checker.yaml around lines 104 - 125, The
current push error handling in the git push block treats protected-branch
rejections as a warning and exits 0, which allows subsequent RuboCop steps to
run against unpushed local commits; update the handler in the block that
inspects PUSH_EXIT_CODE and /tmp/push_output.txt so that when grep detects
"protected branch|permission|prohibited|rejected" it emits the warning messages
but then exits non‑zero (exit 1) instead of exit 0. Keep the existing echo
"::warning::" lines for context, but change the final control flow so
protected/permission push failures fail the job (use exit 1) — this affects the
git push handling around the PUSH_EXIT_CODE logic and the grep check that reads
/tmp/push_output.txt.

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