Skip to content

Commit 9377baf

Browse files
committed
chore: lint and ci fixes
1 parent 40c48b6 commit 9377baf

File tree

15 files changed

+80
-68
lines changed

15 files changed

+80
-68
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
path: |
6060
~/go/pkg/mod
6161
~/.cache/go-build
62-
key: ${{ runner.os }}-go-${{ hashFiles('backend/go.sum') }}
62+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
6363
restore-keys: |
6464
${{ runner.os }}-go-
6565
@@ -96,7 +96,7 @@ jobs:
9696
path: |
9797
~/go/pkg/mod
9898
~/.cache/go-build
99-
key: ${{ runner.os }}-go-${{ hashFiles('backend/go.sum') }}
99+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
100100
restore-keys: |
101101
${{ runner.os }}-go-
102102
@@ -119,6 +119,16 @@ jobs:
119119
with:
120120
bun-version: latest
121121

122+
- name: Cache Bun dependencies
123+
uses: actions/cache@v4
124+
with:
125+
path: |
126+
~/.bun/install/cache
127+
ui/node_modules
128+
key: ${{ runner.os }}-bun-${{ hashFiles('ui/bun.lock') }}
129+
restore-keys: |
130+
${{ runner.os }}-bun-
131+
122132
- name: Install dependencies
123133
working-directory: ui
124134
run: bun install

.github/workflows/publish.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
path: |
3131
~/go/pkg/mod
3232
~/.cache/go-build
33-
key: ${{ runner.os }}-go-${{ hashFiles('backend/go.sum') }}
33+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3434
restore-keys: |
3535
${{ runner.os }}-go-
3636
@@ -51,6 +51,17 @@ jobs:
5151
with:
5252
bun-version: latest
5353

54+
- name: Cache Bun dependencies
55+
if: matrix.component == 'frontend'
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/.bun/install/cache
60+
ui/node_modules
61+
key: ${{ runner.os }}-bun-${{ hashFiles('ui/bun.lock') }}
62+
restore-keys: |
63+
${{ runner.os }}-bun-
64+
5465
- name: Install frontend dependencies
5566
if: matrix.component == 'frontend'
5667
working-directory: ui

GITHUB_ACTIONS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ The workflow intelligently runs jobs based on which files changed:
5151

5252
**Features:**
5353
-**Fast PR checks**: Only runs relevant jobs
54-
- 🔄 Caching of Go modules and build artifacts
54+
- 🔄 **Dependency caching**:
55+
- Go modules (`~/go/pkg/mod`) and build artifacts (`~/.cache/go-build`)
56+
- Bun dependencies (`~/.bun/install/cache` and `ui/node_modules`)
5557
- 🚀 Parallel execution of independent jobs
5658
- 🐳 Docker layer caching for faster builds
5759
- 🔍 Always runs full suite on master branch
@@ -116,6 +118,7 @@ The workflow intelligently runs jobs based on which files changed:
116118
- 🔒 **Protected by tests**: Docker push only happens if all tests pass
117119
- 🎯 **Build from tag**: Ensures Docker image is built from tagged commit
118120
- 📦 **Dual tagging**: Pushes both version-specific and `latest` tags
121+
- 🔄 **Dependency caching**: Go and Bun dependencies cached for faster builds
119122
- 📝 **Auto-generated release notes**: GitHub automatically generates release notes from commits since last release
120123
- 🐳 **Complete installation guide**: Includes Docker and Docker Compose installation instructions
121124

LINTING.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ When you run `git commit`, the hook will **CHECK ONLY** (not auto-fix):
105105

106106
1. **Backend (.go files)**:
107107
- Run `gofumpt` to check formatting
108-
- **Fails if code is not formatted**
108+
- Run `golangci-lint` to check code quality
109+
- **Fails if code is not formatted OR has linting errors**
109110

110111
2. **Frontend (.ts, .tsx, .js, .jsx, .json, .css files)**:
111112
- Run Biome CI check (formatter + linter)
@@ -114,16 +115,20 @@ When you run `git commit`, the hook will **CHECK ONLY** (not auto-fix):
114115

115116
### If the commit fails:
116117

117-
1. **Format your code manually**:
118+
1. **Format and fix linting errors**:
118119
```bash
119-
# Backend
120+
# Backend - Format code
120121
cd backend && make fmt
121122

122-
# Frontend
123+
# Backend - Check for lint errors
124+
cd backend && make lint
125+
# (Fix any lint errors manually)
126+
127+
# Frontend - Auto-fix formatting and linting
123128
cd ui && bun run check
124129
```
125130

126-
2. **Stage the formatted files**:
131+
2. **Stage the fixed files**:
127132
```bash
128133
git add .
129134
```
@@ -134,9 +139,10 @@ When you run `git commit`, the hook will **CHECK ONLY** (not auto-fix):
134139
```
135140

136141
This ensures:
137-
- Developers are aware of formatting issues before committing
142+
- Developers are aware of formatting AND linting issues before committing
138143
- CI validation is consistent with local pre-commit checks
139144
- No surprise auto-formatting in commits
145+
- Code quality is maintained from the first commit
140146

141147
## CI/CD Integration
142148

backend/.golangci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ run:
66

77
linters:
88
disable:
9-
- exportloopref # Deprecated since Go 1.22
109
- tenv # Deprecated, replaced by usetesting
10+
- gofumpt # Use standalone gofumpt to avoid version conflicts
11+
- gofmt # Use standalone gofumpt to avoid version conflicts
12+
- usetesting # Best practice suggestion, not critical
1113

1214
enable:
1315
# Critical linters
@@ -19,8 +21,6 @@ linters:
1921
- unused # Check for unused code
2022

2123
# Code quality
22-
- gofmt # Check formatting
23-
- gofumpt # Stricter gofmt
2424
- goimports # Check imports formatting
2525
- misspell # Find commonly misspelled words
2626
- unconvert # Unnecessary type conversions
@@ -32,7 +32,6 @@ linters:
3232
- typecheck # Type check
3333
- whitespace # Detect leading/trailing whitespace
3434
- copyloopvar # Replace exportloopref
35-
- usetesting # Replace tenv
3635

3736
linters-settings:
3837
errcheck:

backend/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ install-tools: ## Install development tools (golangci-lint, gofumpt)
1818
@go install mvdan.cc/gofumpt@latest
1919
@echo "Tools installed successfully!"
2020

21-
lint: ## Run golangci-lint
21+
lint: ## Run golangci-lint for linting and static analysis
2222
@echo "Running golangci-lint..."
2323
@$(GOLANGCI_LINT) run ./...
2424

2525
fmt: ## Format code with gofumpt
2626
@echo "Formatting code with gofumpt..."
2727
@$(GOFUMPT) -l -w .
2828

29-
fmt-check: ## Check if code is formatted
29+
fmt-check: ## Check if code is formatted with gofumpt
3030
@echo "Checking code formatting..."
3131
@$(GOFUMPT) -l . | grep . && echo "Code is not formatted. Run 'make fmt' to fix." && exit 1 || echo "Code is formatted correctly."
3232

backend/internal/api/directory.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"html/template"
77
"io/fs"
8+
"log/slog"
89
"net/http"
910
"os"
1011
"path/filepath"
@@ -153,7 +154,10 @@ func renderDirectoryListing(c *gin.Context, path string, files []FileInfo) {
153154
}
154155

155156
c.Header("Content-Type", "text/html; charset=utf-8")
156-
tmpl.Execute(c.Writer, data)
157+
if err := tmpl.Execute(c.Writer, data); err != nil {
158+
slog.Error("failed to execute template", slog.Any("error", err))
159+
ErrorResponse(c, http.StatusInternalServerError, ErrCodeInternalError, "Failed to generate directory listing")
160+
}
157161
}
158162

159163
// WalkDirectory recursively walks a directory and returns all files.

backend/internal/api/directory_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,3 @@ func TestDirectoryHandlerDirectorySizeDisplay(t *testing.T) {
419419
t.Error("HTML should show '7 B' for file size")
420420
}
421421
}
422-
423-
// Helper function for min/max.
424-
func min(a, b int) int {
425-
if a < b {
426-
return a
427-
}
428-
return b
429-
}
430-
431-
func max(a, b int) int {
432-
if a > b {
433-
return a
434-
}
435-
return b
436-
}

backend/internal/db/sqlite.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ const (
2020
isoSelectFields = `id, name, version, arch, edition, file_type, filename, file_path, download_link,
2121
size_bytes, checksum, checksum_type, download_url, checksum_url,
2222
status, progress, error_message, created_at, completed_at`
23-
24-
isoInsertFields = `id, name, version, arch, edition, file_type, filename, file_path, download_link,
25-
size_bytes, checksum, checksum_type, download_url, checksum_url,
26-
status, progress, error_message, created_at, completed_at`
27-
28-
isoUpdateFields = `name = ?, version = ?, arch = ?, edition = ?, file_type = ?,
29-
filename = ?, file_path = ?, download_link = ?,
30-
size_bytes = ?, checksum = ?, checksum_type = ?,
31-
download_url = ?, checksum_url = ?, status = ?, progress = ?,
32-
error_message = ?, completed_at = ?`
3323
)
3424

3525
// DB wraps the SQLite database connection.
@@ -219,7 +209,7 @@ func (db *DB) GetISO(id string) (*models.ISO, error) {
219209
// ListISOs retrieves all ISOs ordered by created_at DESC.
220210
func (db *DB) ListISOs() ([]models.ISO, error) {
221211
query := fmt.Sprintf("SELECT %s FROM isos ORDER BY created_at DESC", isoSelectFields)
222-
rows, err := db.conn.Query(query)
212+
rows, err := db.conn.Query(query) //nolint:sqlclosecheck // False positive: rows are closed via deferred closure below
223213
if err != nil {
224214
return nil, fmt.Errorf("failed to query ISO list: %w", err)
225215
}

backend/internal/download/worker.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ func (w *Worker) download(ctx context.Context, iso *models.ISO, destPath string)
145145
err := httputil.DownloadFileWithProgress(ctx, iso.DownloadURL, destPath, 32*1024, func(downloaded, total int64) {
146146
// Update database with total size on first callback
147147
if iso.SizeBytes == 0 && total > 0 {
148-
w.db.UpdateISOSize(iso.ID, total)
148+
if err := w.db.UpdateISOSize(iso.ID, total); err != nil {
149+
slog.Warn("failed to update ISO size", slog.Any("error", err))
150+
}
149151
iso.SizeBytes = total
150152
}
151153

@@ -192,17 +194,23 @@ func (w *Worker) verifyChecksum(iso *models.ISO, filepath string) error {
192194
}
193195

194196
// Update database with verified checksum
195-
w.db.UpdateISOChecksum(iso.ID, actualChecksum)
197+
if err := w.db.UpdateISOChecksum(iso.ID, actualChecksum); err != nil {
198+
slog.Warn("failed to update ISO checksum", slog.Any("error", err))
199+
}
196200
iso.Checksum = actualChecksum
197201

198202
return nil
199203
}
200204

201205
// updateStatus updates the ISO status and triggers progress callback.
202206
func (w *Worker) updateStatus(isoID string, status models.ISOStatus, progress int, errorMsg string) {
203-
w.db.UpdateISOStatus(isoID, status, errorMsg)
207+
if err := w.db.UpdateISOStatus(isoID, status, errorMsg); err != nil {
208+
slog.Warn("failed to update ISO status", slog.Any("error", err))
209+
}
204210
if progress >= 0 {
205-
w.db.UpdateISOProgress(isoID, progress)
211+
if err := w.db.UpdateISOProgress(isoID, progress); err != nil {
212+
slog.Warn("failed to update ISO progress", slog.Any("error", err))
213+
}
206214
}
207215

208216
if w.progressCallback != nil {

0 commit comments

Comments
 (0)