Skip to content

Commit dbdc407

Browse files
authored
Fix CI workflow for format checking (#60)
- Format check now only runs on pull requests - Comments on PR and tags author - Removes auto-commit behavior that conflicted with branch protection - Main branch pushes only run build/test jobs
1 parent 00829b0 commit dbdc407

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

.github/workflows/ci-cd.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,38 @@ jobs:
4343
name: coverage-report
4444
path: coverage.out
4545

46-
format:
47-
name: Auto-format with gofmt (Linux only)
46+
format-check:
47+
name: Go Format Check
4848
runs-on: ubuntu-latest
49-
if: github.event_name == 'push' && github.actor != 'github-actions[bot]'
49+
if: github.event_name == 'pull_request'
5050
permissions:
51-
contents: write
51+
contents: read
52+
pull-requests: write
5253

5354
steps:
5455
- name: Checkout code
5556
uses: actions/checkout@v4
56-
with:
57-
token: ${{ secrets.GITHUB_TOKEN }}
5857

5958
- name: Set up Go
6059
uses: actions/setup-go@v5
6160
with:
6261
go-version: '1.24.4'
6362

64-
- name: Run gofmt and commit changes if needed
63+
- name: Check Go formatting and comment on PR
6564
run: |
66-
gofmt -w .
67-
if [ -n "$(git status --porcelain)" ]; then
68-
echo "Code was not formatted. Committing changes..."
69-
git config user.name "github-actions[bot]"
70-
git config user.email "github-actions[bot]@users.noreply.github.com"
71-
git add .
72-
git commit -m "chore: auto-format Go code via gofmt"
73-
git push
65+
unformatted=$(gofmt -l .)
66+
if [ -n "$unformatted" ]; then
67+
echo "The following files need formatting:"
68+
echo "$unformatted"
69+
70+
# Get PR author
71+
pr_author="${{ github.event.pull_request.user.login }}"
72+
73+
# Create PR comment
74+
gh pr comment ${{ github.event.number }} --body "@$pr_author Go code formatting is required. Please run \`go fmt ./...\` to format your code and push the changes. Check the [action logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details on which files need formatting."
75+
exit 1
7476
else
75-
echo "Code already properly formatted."
77+
echo "All Go code is properly formatted"
7678
fi
79+
env:
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

internal/backend/collections/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, erro
100100
if err != nil {
101101
return nil, err
102102
}
103-
103+
104104
entities := make([]CollectionEntity, len(collections))
105105
for i, collection := range collections {
106106
entities[i] = CollectionEntity{Collection: collection}
107107
}
108-
108+
109109
return entities, nil
110110
}
111111

internal/backend/collections/models.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func (c CollectionEntity) GetName() string {
1919
return c.Name
2020
}
2121

22-
2322
func (c CollectionEntity) GetCreatedAt() time.Time {
2423
return crud.ParseTimestamp(c.CreatedAt)
2524
}

internal/tui/app/model.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ func (a AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6868
}
6969
case messages.NavigateToView:
7070
a.Views[a.focusedView].OnBlur()
71-
71+
7272
if msg.Data != nil {
7373
err := a.Views[ViewName(msg.ViewName)].SetState(msg.Data)
7474
if err != nil {
7575
log.Error("failed to set view state during navigation", "target_view", msg.ViewName, "error", err)
7676
return a, nil
7777
}
7878
}
79-
79+
8080
a.focusedView = ViewName(msg.ViewName)
8181
a.Views[a.focusedView].OnFocus()
8282
return a, nil
@@ -112,25 +112,25 @@ func (a AppModel) View() string {
112112
header := a.Header()
113113
view := a.Views[a.focusedView].View()
114114
help := a.Help()
115-
115+
116116
if a.errorMsg != "" {
117117
errorBar := styles.ErrorBarStyle.Width(a.width).Render("Error: " + a.errorMsg)
118118
return lipgloss.JoinVertical(lipgloss.Top, header, view, errorBar, help, footer)
119119
}
120-
120+
121121
return lipgloss.JoinVertical(lipgloss.Top, header, view, help, footer)
122122
}
123123

124124
func (a AppModel) Help() string {
125125
viewHelp := a.Views[a.focusedView].Help()
126-
126+
127127
var appHelp []key.Binding
128128
appHelp = append(appHelp, a.keys...)
129-
129+
130130
if a.focusedView == Endpoints {
131131
appHelp = append(appHelp, keybinds.Keys.Back)
132132
}
133-
133+
134134
allHelp := append(viewHelp, appHelp...)
135135
helpStruct := keybinds.Help{
136136
Keys: allHelp,
@@ -197,4 +197,3 @@ func NewAppModel(ctx *Context) AppModel {
197197
}
198198
return model
199199
}
200-

internal/tui/views/collections-view.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ func (c CollectionsView) Update(msg tea.Msg) (ViewInterface, tea.Cmd) {
5555
case messages.ItemAdded:
5656
_, err := c.manager.Create(context.Background(), msg.Item)
5757
if err != nil {
58-
return c, func() tea.Msg {
59-
return messages.ShowError{Message: err.Error()}
58+
return c, func() tea.Msg {
59+
return messages.ShowError{Message: err.Error()}
6060
}
6161
}
62-
return c, func() tea.Msg {
63-
return messages.RefreshItemsList{}
62+
return c, func() tea.Msg {
63+
return messages.RefreshItemsList{}
6464
}
6565
case messages.RefreshItemsList:
6666
c.list.RefreshItems()
@@ -100,7 +100,7 @@ func (c CollectionsView) OnBlur() {
100100

101101
func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoints.EndpointsManager) []list.Item {
102102
opts := make([]list.Item, len(items))
103-
103+
104104
counts, err := endpointsManager.GetCountsByCollections(context.Background())
105105
if err != nil {
106106
for i, item := range items {
@@ -112,12 +112,12 @@ func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoint
112112
}
113113
return opts
114114
}
115-
115+
116116
countMap := make(map[int64]int)
117117
for _, count := range counts {
118118
countMap[count.CollectionID] = int(count.Count)
119119
}
120-
120+
121121
for i, item := range items {
122122
count := countMap[item.GetID()]
123123
opts[i] = optionsProvider.Option{
@@ -126,7 +126,7 @@ func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoint
126126
ID: item.GetID(),
127127
}
128128
}
129-
129+
130130
return opts
131131
}
132132

0 commit comments

Comments
 (0)