Skip to content

Add make fmt target for manual code formatting#32

Merged
rustyeddy merged 8 commits into
mainfrom
copilot/add-ci-step-formatting
Nov 20, 2025
Merged

Add make fmt target for manual code formatting#32
rustyeddy merged 8 commits into
mainfrom
copilot/add-ci-step-formatting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 20, 2025

Adds a make fmt target to enable manual code formatting with gofmt.

Changes

  • Makefile: Added fmt target running gofmt -s -w .
  • Applied formatting fixes to existing code across 6 files (cmd, messanger, station, test, utils)

Usage

Developers can now run make fmt manually before committing to format all Go code according to standard Go formatting conventions:

make fmt

This allows developers to maintain consistent code formatting without automated CI workflows that rewrite branches.

Testing

  • ✅ Tests pass after formatting changes
  • make vet passes
  • make fmt successfully formats all Go files
Original prompt

Add a permanent CI step to run 'make fmt' across the repository and automatically commit and push any formatting changes back to the branch. Create the change on the existing branch copilot/add-mqtt-server-shutdown (the same branch that added the MQTT shutdown tests) so it will be included in the open PR (#30).

Make a single, minimal change to the CI workflow file: .github/workflows/ci.yml. Add permissions to allow the workflow to push formatting commits and add a new job called 'fmt' that:

  • checks out the repo with persist-credentials: true
  • runs 'make fmt'
  • if formatting produced changes, configures git user, commits them with message "ci: run make fmt (auto-format)", and pushes back to the current branch

The job should run on ubuntu-latest and use the repository's existing Go setup if necessary. Provide the exact YAML content to add/replace within .github/workflows/ci.yml. Ensure the workflow file includes:

  • top-level permissions: contents: write
  • uses actions/checkout@v4 with persist-credentials: true so the GITHUB_TOKEN can push

Patch to apply (replace or merge into existing workflow):

--- .github/workflows/ci.yml
+++ .github/workflows/ci.yml
@@
+permissions:

  • contents: write

+jobs:

  • fmt:
  • name: Format (make fmt)
  • runs-on: ubuntu-latest
  • steps:
  •  - name: Checkout
    
  •    uses: actions/checkout@v4
    
  •    with:
    
  •      fetch-depth: 0
    
  •      persist-credentials: true
    
  •  - name: Set up Go
    
  •    uses: actions/setup-go@v4
    
  •    with:
    
  •      go-version: '1.21'
    
  •  - name: Run make fmt
    
  •    run: |
    
  •      make fmt
    
  •  - name: Commit and push formatting changes (if any)
    
  •    run: |
    
  •      if [ -n "$(git status --porcelain)" ]; then
    
  •        git config user.name "github-actions[bot]"
    
  •        git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
    
  •        git add -A
    
  •        git commit -m "ci: run make fmt (auto-format)"
    
  •        # Push to the current branch
    
  •        git push
    
  •      else
    
  •        echo "No formatting changes"
    
  •      fi
    
  • Keep existing jobs (build/test/lint) unchanged; they will run after fmt if configured in the current workflow.

Notes:

- This change writes back formatting fixes directly to the branch using the GITHUB_TOKEN. The workflow requires 'contents: write' permission to push.

- If you prefer the workflow to fail instead of auto-pushing, we can change the commit/push step to instead 'exit 1' when formatting is required.

- If the repo supports multiple Go versions, adjust the setup-go version accordingly.

Please create the PR on the branch copilot/add-mqtt-server-shutdown with the above changes to .github/workflows/ci.yml and commit message: "ci: add fmt job to run make fmt and auto-commit formatting".

This pull request was created as a result of the following prompt from Copilot chat.

Add a permanent CI step to run 'make fmt' across the repository and automatically commit and push any formatting changes back to the branch. Create the change on the existing branch copilot/add-mqtt-server-shutdown (the same branch that added the MQTT shutdown tests) so it will be included in the open PR (#30).

Make a single, minimal change to the CI workflow file: .github/workflows/ci.yml. Add permissions to allow the workflow to push formatting commits and add a new job called 'fmt' that:

  • checks out the repo with persist-credentials: true
  • runs 'make fmt'
  • if formatting produced changes, configures git user, commits them with message "ci: run make fmt (auto-format)", and pushes back to the current branch

The job should run on ubuntu-latest and use the repository's existing Go setup if necessary. Provide the exact YAML content to add/replace within .github/workflows/ci.yml. Ensure the workflow file includes:

  • top-level permissions: contents: write
  • uses actions/checkout@v4 with persist-credentials: true so the GITHUB_TOKEN can push

Patch to apply (replace or merge into existing workflow):

--- .github/workflows/ci.yml
+++ .github/workflows/ci.yml
@@
+permissions:

  • contents: write

+jobs:

  • fmt:
  • name: Format (make fmt)
  • runs-on: ubuntu-latest
  • steps:
  •  - name: Checkout
    
  •    uses: actions/checkout@v4
    
  •    with:
    
  •      fetch-depth: 0
    
  •      persist-credentials: true
    
  •  - name: Set up Go
    
  •    uses: actions/setup-go@v4
    
  •    with:
    
  •      go-version: '1.21'
    
  •  - name: Run make fmt
    
  •    run: |
    
  •      make fmt
    
  •  - name: Commit and push formatting changes (if any)
    
  •    run: |
    
  •      if [ -n "$(git status --porcelain)" ]; then
    
  •        git config user.name "github-actions[bot]"
    
  •        git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
    
  •        git add -A
    
  •        git commit -m "ci: run make fmt (auto-format)"
    
  •        # Push to the current branch
    
  •        git push
    
  •      else
    
  •        echo "No formatting changes"
    
  •      fi
    
  • Keep existing jobs (build/test/lint) unchanged; they will run after fmt if configured in the current workflow.

Notes:

- This change writes back formatting fixes directly to the branch using the GITHUB_TOKEN. The workflow requires 'contents: write' permission to push.

- If you prefer the workflow to fail instead of auto-pushing, we can change the commit/push step to instead 'exit 1' when formatting is required.

- If the repo supports multiple Go versions, adjust the setup-go version accordingly.

Please create the PR on the branch copilot/add-mqtt-server-shutdown with the above changes to .github/workflows/ci.yml and commit message: "ci: add fmt job to run make fmt and auto-commit formatting".


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits November 19, 2025 04:43
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CI step to format code and auto-commit changes Add CI job to auto-format Go code with make fmt Nov 20, 2025
Copilot AI requested a review from rustyeddy November 20, 2025 00:51
@rustyeddy
Copy link
Copy Markdown
Owner

@copilot whoops I made a mistake. We don't want to have pipeline runs rewrite to a branch. I should run the fmt outside of the ci/cd pipeline. Can you remove the formatting from the pipeline?

Co-authored-by: rustyeddy <2903425+rustyeddy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot whoops I made a mistake. We don't want to have pipeline runs rewrite to a branch. I should run the fmt outside of the ci/cd pipeline. Can you remove the formatting from the pipeline?

Done! I've removed the CI workflow that auto-committed formatting changes (commit 215eabb).

The make fmt target remains in the Makefile so you can run formatting manually before commits. The formatting changes already applied to the code files are preserved.

Copilot AI changed the title Add CI job to auto-format Go code with make fmt Add make fmt target for manual code formatting Nov 20, 2025
Copilot AI requested a review from rustyeddy November 20, 2025 01:17
Base automatically changed from copilot/add-mqtt-server-shutdown to main November 20, 2025 01:26
@rustyeddy rustyeddy marked this pull request as ready for review November 20, 2025 01:31
Copilot AI review requested due to automatic review settings November 20, 2025 01:31
@rustyeddy rustyeddy merged commit 2613d3a into main Nov 20, 2025
7 checks passed
@rustyeddy rustyeddy deleted the copilot/add-ci-step-formatting branch November 20, 2025 01:31
Copy link
Copy Markdown
Contributor

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

This PR adds a make fmt target to enable manual code formatting using gofmt with simplifications, and applies the formatting to existing code. The PR title focuses on the manual formatting capability, though the description also mentions CI automation that isn't present in the actual changes.

Key Changes:

  • Updated make fmt target to use gofmt -s -w . instead of go fmt ./..., enabling code simplifications
  • Applied formatting fixes to remove unnecessary blank identifiers and trailing whitespace
  • Changes align with repository conventions documented in custom instructions

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
Makefile Changed fmt target from go fmt ./... to gofmt -s -w . to enable simplifications and explicit file-based formatting
cmd/cmd_ticker.go Removed unnecessary blank identifier in range loop (standard gofmt -s simplification)
test/integration/integration_test.go Removed trailing whitespace from closing brace

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