Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 232 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
name: CI

on:
push:
branches:
- main
- 'dev/**'
- 'feat/**'
- 'fix/**'
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26.2'
cache: true

- name: Check gofmt
run: |
unformatted="$(gofmt -l . | grep -v '^web/' | grep -v '^video-cong-nghe/' || true)"
if [ -n "$unformatted" ]; then
echo "::error::The following files are not gofmt-formatted:"
echo "$unformatted"
echo ""
echo "Run 'gofmt -w .' (or 'make fmt') and commit the result."
exit 1
fi
echo "All Go files are gofmt-formatted."

# go vet (and go build) must type-check main.go, which go:embed's the
# frontend build output (web/static/**/*.min.*). Those files are
# gitignored, so they only exist after a frontend build — without this
# step the embed directive fails with "no matching files found".
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Build frontend assets (required by go:embed)
run: |
cd web
chmod +x build-frontend.sh
./build-frontend.sh

- name: Verify go:embed prerequisites
run: |
missing=0
for p in web/static/css/*.min.css web/static/css/tailwind.css \
web/static/js/*.min.js web/static/themes/*.min.css \
web/static/locales/*.min.json web/static/fonts web/static/webfonts; do
if ! ls -d $p >/dev/null 2>&1; then
echo "::error::go:embed prerequisite missing after frontend build: $p"
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo ""
echo "main.go embeds these paths. A common cause is a dependency"
echo "upgrade that changed its file layout (Font Awesome dropping"
echo "webfonts/). Check web/bun.lock is committed and used."
exit 1
fi
echo "All go:embed prerequisites present."
shell: bash

- name: go vet
run: go vet ./...

test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26.2'
cache: true

# main.go go:embed's the frontend build output, so it must exist before
# anything compiles. The embedded assets are platform-independent, so
# building them on Linux once per job is enough.
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Build frontend assets (required by go:embed)
run: |
cd web
chmod +x build-frontend.sh
./build-frontend.sh
shell: bash

- name: Debug font layout (temporary)
run: |
echo "--- node_modules fontawesome version ---"
cat web/node_modules/@fortawesome/fontawesome-free/package.json 2>/dev/null | grep '"version"' || echo "package.json not found"
echo "--- node_modules webfonts dir ---"
ls -la web/node_modules/@fortawesome/fontawesome-free/webfonts/ 2>&1 | head -10 || echo "no webfonts in node_modules"
echo "--- static dir listing ---"
ls -la web/static/ 2>&1 | head -20
echo "--- static/css listing ---"
ls -la web/static/css/ 2>&1 | head -20
echo "--- url() refs in built css ---"
grep -o 'url([^)]*woff[^)]*)' web/static/css/style.min.css 2>/dev/null | head -5 || echo "no woff refs in css"
shell: bash

- name: Verify go:embed prerequisites
run: |
missing=0
for p in web/static/css/*.min.css web/static/css/tailwind.css \
web/static/js/*.min.js web/static/themes/*.min.css \
web/static/locales/*.min.json web/static/fonts web/static/webfonts; do
if ! ls -d $p >/dev/null 2>&1; then
echo "::error::go:embed prerequisite missing after frontend build: $p"
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo ""
echo "main.go embeds these paths. A common cause is a dependency"
echo "upgrade that changed its file layout (Font Awesome dropping"
echo "webfonts/). Check web/bun.lock is committed and used."
exit 1
fi
echo "All go:embed prerequisites present."
shell: bash

- name: Download modules
run: go mod download

- name: Build
run: go build -o /dev/null ./...
shell: bash

- name: Run tests
run: go test -race -count=1 ./...
shell: bash

coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26.2'
cache: true

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Build frontend assets (required by go:embed)
run: |
cd web
chmod +x build-frontend.sh
./build-frontend.sh

- name: Verify go:embed prerequisites
run: |
missing=0
for p in web/static/css/*.min.css web/static/css/tailwind.css \
web/static/js/*.min.js web/static/themes/*.min.css \
web/static/locales/*.min.json web/static/fonts web/static/webfonts; do
if ! ls -d $p >/dev/null 2>&1; then
echo "::error::go:embed prerequisite missing after frontend build: $p"
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo ""
echo "main.go embeds these paths. A common cause is a dependency"
echo "upgrade that changed its file layout (Font Awesome dropping"
echo "webfonts/). Check web/bun.lock is committed and used."
exit 1
fi
echo "All go:embed prerequisites present."

- name: Generate coverage profile
run: go test -count=1 -covermode=atomic -coverprofile=coverage.out ./...

- name: Print coverage summary
run: |
go tool cover -func=coverage.out | tail -n 1
echo ""
echo "### Coverage by package" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
go test -count=1 -cover ./... 2>/dev/null | grep -E '^(ok|\?)' >> "$GITHUB_STEP_SUMMARY" || true
echo '```' >> "$GITHUB_STEP_SUMMARY"

- name: Upload coverage profile
uses: actions/upload-artifact@v4
with:
name: coverage-profile
path: coverage.out
retention-days: 14
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Thumbs.db
# Go dependencies
vendor/

# Test artifacts
coverage.out
coverage.html
*.test

# Tailwind & Frontend
tailwindcss
static/css/tailwind.css
Expand Down
39 changes: 36 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build run test clean fmt tidy frontend docker-build help
.PHONY: build run test test-race cover vet fmt fmt-check check clean tidy frontend docker-build help

DEFAULT_API_ID ?= $(shell grep -E "^API_ID=" .env 2>/dev/null | cut -d= -f2)
DEFAULT_API_HASH ?= $(shell grep -E "^API_HASH=" .env 2>/dev/null | cut -d= -f2)
Expand All @@ -18,7 +18,12 @@ help:
@echo " make run Build and run application locally"
@echo " make frontend Build frontend assets in web directory"
@echo " make test Run unit tests for all packages"
@echo " make fmt Format Go source code"
@echo " make test-race Run unit tests with the race detector"
@echo " make cover Run tests and report per-function coverage"
@echo " make vet Run go vet on all packages"
@echo " make fmt Format Go source code (gofmt -w)"
@echo " make fmt-check Verify Go source is gofmt-formatted (no writes)"
@echo " make check Run the full local CI gate: fmt-check + vet + test"
@echo " make tidy Tidy Go modules"
@echo " make clean Clean build artifacts and temporary files"
@echo " make docker-build Build Docker image locally with default API credentials"
Expand All @@ -40,9 +45,37 @@ test:
@echo "===> Running tests..."
go test ./...

test-race:
@echo "===> Running tests with race detector..."
go test -race -count=1 ./...

cover:
@echo "===> Running tests with coverage..."
go test -count=1 -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | tail -n 1
@echo "===> Full profile written to coverage.out (view with: go tool cover -html=coverage.out)"

vet:
@echo "===> Running go vet..."
go vet ./...

fmt:
@echo "===> Formatting Go code..."
go fmt ./...
gofmt -w $$(git ls-files '*.go' | grep -v '^web/' || find . -name '*.go' -not -path './web/*' -not -path './.git/*')

fmt-check:
@echo "===> Checking gofmt..."
@unformatted="$$(gofmt -l . | grep -v '^web/' | grep -v '^video-cong-nghe/' || true)"; \
if [ -n "$$unformatted" ]; then \
echo "The following files are not gofmt-formatted:"; \
echo "$$unformatted"; \
echo "Run 'make fmt' and commit the result."; \
exit 1; \
fi; \
echo "All Go files are gofmt-formatted."

check: fmt-check vet test
@echo "===> All local CI checks passed."

tidy:
@echo "===> Running go mod tidy..."
Expand Down
2 changes: 1 addition & 1 deletion api/handlers_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (h *Handler) handleGetBotUserSettings(c *gin.Context) {
botPoolUploadFolder = "TelegramUpload"
}
c.JSON(http.StatusOK, gin.H{
"telegram_user_id": telegramUserID,
"telegram_user_id": telegramUserID,
"bot_pool_upload_folder": botPoolUploadFolder,
})
}
Expand Down
2 changes: 0 additions & 2 deletions api/handlers_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,5 +494,3 @@ func (h *Handler) handleGetShares(c *gin.Context) {
"files": files,
})
}


6 changes: 3 additions & 3 deletions api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ func gzipMiddleware() gin.HandlerFunc {

// Avoid compressing stream, download, WebDAV, S3, WebSocket, and large comic/epub page binary data
path := c.Request.URL.Path
if strings.Contains(path, "/stream") ||
strings.Contains(path, "/dl") ||
if strings.Contains(path, "/stream") ||
strings.Contains(path, "/dl") ||
strings.Contains(path, "/download/") ||
strings.Contains(path, "/cbz/page") ||
strings.Contains(path, "/epub/resource") ||
Expand All @@ -358,7 +358,7 @@ func gzipMiddleware() gin.HandlerFunc {

c.Header("Content-Encoding", "gzip")
c.Header("Vary", "Accept-Encoding")

c.Writer = &gzipResponseWriter{c.Writer, gz}
c.Next()
}
Expand Down
Loading
Loading