Skip to content

Conversation

@gocanto
Copy link
Collaborator

@gocanto gocanto commented Nov 13, 2025

Summary by CodeRabbit

  • Chores
    • Broadened PR event triggers and added write permission for formatting workflow.
    • Simplified conditions to skip formatting when labeled and renamed/streamlined the commit step.
    • Removed dry-run warnings and automated branch/PR creation steps for formatting.
    • Updated CI triggers so tests run only on the main branch.

Updated the deployment workflow to trigger only on pushes to main or master branches, ensuring deployments only occur after code is merged to protected branches.
…present

Modified the Go formatting workflow to:
- Trigger on every PR commit (opened, reopened, synchronize)
- Skip formatting only when PR has 'no-fmt' label
- Auto-commit formatting fixes on draft PRs (respects 'no-fmt' label)
- Removed dependency on 'style' label for auto-commits

This ensures consistent code formatting across all PRs by default, with an opt-out mechanism via the 'no-fmt' label.
Changes:
- Remove 'master' branch from all workflow triggers (deploy.yml, tests.yml)
- Remove push trigger on main from gofmt.yml to prevent auto-formatting on merged PRs
- Clean up gofmt.yml by removing main branch handling logic and PR creation steps

All workflows now only target the 'main' branch, and gofmt only runs on pull requests (unless 'no-fmt' label is present).
@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR updates two GitHub Actions workflows: the gofmt workflow is simplified and its pull_request triggers broadened; the tests workflow removes the master branch from push triggers (now only main).

Changes

Cohort / File(s) Summary
Gofmt workflow
.github/workflows/gofmt.yml
Broadened pull_request event triggers to include opened, reopened, synchronize, labeled, and unlabeled; added pull-requests: write permission; simplified job condition to run only when PR is not labeled no-fmt; removed dry-run warning and removed automated branch creation + PR creation steps on pushes to main; renamed/streamlined commit step to "Commit Formatting Changes".
Tests workflow
.github/workflows/tests.yml
Changed push trigger branches from [main, master] to [main], removing master as a trigger.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Dev as Developer
    participant GH as GitHub Events
    participant Gofmt as gofmt Workflow
    participant Repo as Repository

    Dev->>GH: open/reopen/synchronize PR (or label/unlabel)
    GH->>Gofmt: trigger workflow (pull_request)
    alt PR not labeled "no-fmt"
        Gofmt->>Gofmt: run formatting job
        Gofmt->>Repo: Commit Formatting Changes (if any)
    else PR labeled "no-fmt"
        Gofmt-->>GH: skip formatting job
    end
    Note over Gofmt,Repo: Removed automated main->branch creation and PR opening on push
Loading
sequenceDiagram
    autonumber
    participant Push as Push to main
    participant OldFlow as Old workflow (pre-change)
    participant NewFlow as New workflow (post-change)

    Push->>OldFlow: create formatting branch -> open PR (automated)
    Note right of OldFlow: Automated branch+PR creation existed before

    Push->>NewFlow: no automated branch/PR creation
    Note right of NewFlow: Simplified — no multi-step automation on push
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Files: 2 workflow YAMLs; changes are concentrated and mostly declarative.
  • Pay extra attention to:
    • The pull-requests: write permission scope in gofmt.yml.
    • The label-based condition logic (ensure label name matches repo conventions).
    • Any references to removed branch/PR automation that external tooling might rely on.

Possibly related PRs

  • chore: GitHub Actions #162 — Makes the same workflow changes to .github/workflows/gofmt.yml and tests.yml (trigger broadening, gofmt behavior adjustments, removal of master).
  • ci: run gofmt #99 — Overlaps on gofmt.yml changes: trigger modifications, label gating, and branch/PR automation adjustments.
  • WorK on CI #19 — Related edits to the initial gofmt workflow and commit/PR automation behavior.

Poem

🐰 I hopped through YAML, trimmed a wild branch,
Now PRs wake gofmt with a gentler stance,
Master fades softly, main takes the lead,
Less bustle, more focus — a neat little deed. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'chore: GitHub Actions' is vague and generic, describing only the category of changes without specifying the actual modifications or intent. Revise the title to be more specific, such as 'chore: Restrict GitHub Actions to main branch' or 'chore: Simplify gofmt workflow and remove master branch triggers' to clearly communicate the main changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db2c86f and 844fd07.

📒 Files selected for processing (1)
  • .github/workflows/gofmt.yml (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Removed draft PR restriction from auto-commit logic, allowing gofmt to automatically apply formatting changes on all pull requests (unless 'no-fmt' label is present).

Security: Auto-commits only apply to PRs from the same repository, not forks.
Removed confusing "dry run" step and streamlined the workflow to:
1. Run gofmt which modifies files in place
2. Auto-commit any formatting changes directly to the PR

The git-auto-commit-action automatically detects changes made by gofmt and commits them to the PR branch. If no changes are detected, it skips the commit step.
@gocanto gocanto marked this pull request as ready for review November 13, 2025 06:37
@gocanto gocanto changed the title Restrict GitHub Actions deployments to main branch chore: GitHub Actions Nov 13, 2025
Copy link

@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: 0

🧹 Nitpick comments (2)
.github/workflows/gofmt.yml (2)

13-15: Consider simplifying the job condition.

The condition includes a check for github.event_name == 'pull_request', which is always true since the workflow only triggers on pull_request events. While this is defensive (helpful if push triggers are added later), it can be simplified to just the label check for current code clarity.

If you're confident no push triggers will be added to this workflow, you can simplify to:

  gofmt:
    if: >
-     github.event_name == 'pull_request' &&
-     !contains(github.event.pull_request.labels.*.name, 'no-fmt')
+     !contains(github.event.pull_request.labels.*.name, 'no-fmt')

Alternatively, keep the current form as a defensive guard against future push trigger additions.


37-40: Redundant no-fmt label check in commit step condition.

Line 40 duplicates the no-fmt label check already present in the job-level condition (line 15), making this step condition overly restrictive. Since the job only runs when the label is not present, this additional check is unnecessary.

You can simplify the condition to:

      - name: Commit Formatting Changes
        if: >
-         github.event.pull_request.head.repo.full_name == github.repository &&
-         !contains(github.event.pull_request.labels.*.name, 'no-fmt')
+         github.event.pull_request.head.repo.full_name == github.repository

The fork detection (line 39) is the primary safeguard preventing unwanted commits. Keep that; the label check is already enforced at the job level.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cab2abd and db2c86f.

📒 Files selected for processing (2)
  • .github/workflows/gofmt.yml (3 hunks)
  • .github/workflows/tests.yml (1 hunks)
🔇 Additional comments (2)
.github/workflows/tests.yml (1)

7-7: Verify that the master branch is being phased out before restricting tests to main only.

This change restricts test runs to the main branch, preventing test execution on push to master. If the master branch is still in active use, this is a breaking change that could mask issues.

Please confirm that the master branch is no longer in use or is being actively phased out in your workflow/migration plan.

.github/workflows/gofmt.yml (1)

7-9: Permissions look correct.

The added permissions (contents: write, pull-requests: write) are appropriate for the git-auto-commit-action and align with the workflow's needs to commit formatting changes to pull requests.

@gocanto gocanto marked this pull request as draft November 13, 2025 06:43
Simplified workflow conditions by removing redundancy:
- Job-level: Removed unnecessary github.event_name check (workflow only triggers on PRs)
- Step-level: Removed duplicate no-fmt label check (already enforced at job level)

The workflow now has cleaner logic while maintaining the same behavior:
- Runs on all PRs unless 'no-fmt' label is present
- Auto-commits only to same-repo PRs (not forks)
@gocanto gocanto marked this pull request as ready for review November 13, 2025 06:46
@gocanto gocanto merged commit c5a8715 into main Nov 13, 2025
3 of 4 checks passed
@gocanto gocanto deleted the claude/restrict-deployments-to-main-011CV5QhyZhPwEFxV2jY8KSo branch November 13, 2025 06:46
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