Skip to content
Merged
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
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches: [master, rewrite-modern]
pull_request:
workflow_dispatch:

permissions:
contents: read

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

jobs:
go:
name: Go tests and checks
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: backend/go.mod
check-latest: true
cache-dependency-path: backend/go.mod
- name: Check formatting
run: test -z "$(gofmt -l *.go)"
- name: Test with race detector
run: go test -race -shuffle=on -count=1 ./...
- name: Vet
run: go vet ./...
- name: Check Go vulnerabilities
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
"$(go env GOPATH)/bin/govulncheck" ./...

go-lint:
name: Go lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: backend/go.mod
check-latest: true
cache-dependency-path: backend/go.mod
- uses: golangci/golangci-lint-action@v9
with:
version: v2.15.0
working-directory: backend

frontend:
name: Frontend tests and build
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- run: npm ci
- run: npm test
- run: npm run typecheck
- run: npm run build
- run: npm audit --audit-level=moderate

docker:
name: Docker images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: docker build -t githubble-backend:ci ./backend
- run: docker build -t githubble-frontend:ci ./frontend
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Compose. Never put a GitHub token into `NEXT_PUBLIC_*` variables.

## Local development

Requires Go 1.26+ and Node.js 22.12+.
Requires Go 1.26.9+ and Node.js 22.12+.

```sh
cd backend
Expand Down Expand Up @@ -57,3 +57,7 @@ not include token values or event payloads.
cd backend && go test -race ./... && go vet ./...
cd frontend && npm test && npm run typecheck && npm run build
```

GitHub Actions runs these checks on pull requests and pushes to `master` or
`rewrite-modern`, plus Go lint/vulnerability scanning, npm audit, and both
Docker builds. No GitHub API token is needed for CI; images are not published.
4 changes: 4 additions & 0 deletions backend/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "2"

linters:
default: standard
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ---- build stage ----
FROM golang:1.26-alpine AS build
FROM golang:1.26.9-alpine AS build
WORKDIR /app
COPY go.mod ./
RUN go mod download
Expand Down
10 changes: 5 additions & 5 deletions backend/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func (f *fetcher) poll(ctx context.Context) error {
case http.StatusNotModified:
f.broker.publish(ssePayload{Event: "ratelimits", Data: []byte(fmt.Sprintf("token-%d/%s/%s", f.idx+1, resp.Header.Get("X-RateLimit-Remaining"), resp.Header.Get("X-RateLimit-Limit")))})
f.publishChecked()
resp.Body.Close()
_ = resp.Body.Close()
slog.InfoContext(ctx, "github_feed_unchanged", "poll_interval_seconds", int(f.interval.Seconds()), "rate_remaining", f.remaining, "rate_limit", f.limit)
return nil
case http.StatusOK:
var events []json.RawMessage
err = json.NewDecoder(io.LimitReader(resp.Body, 8<<20)).Decode(&events)
resp.Body.Close()
_ = resp.Body.Close()
if err != nil {
return fmt.Errorf("decode events page %d: %w", page, err)
}
Expand All @@ -134,7 +134,7 @@ func (f *fetcher) poll(ctx context.Context) error {
}
case http.StatusForbidden, http.StatusTooManyRequests:
reset, err := strconv.ParseInt(resp.Header.Get("X-RateLimit-Reset"), 10, 64)
resp.Body.Close()
_ = resp.Body.Close()
if err == nil && reset > time.Now().Unix() {
f.resetAt[f.idx] = time.Unix(reset, 0).Add(time.Second)
} else {
Expand All @@ -144,13 +144,13 @@ func (f *fetcher) poll(ctx context.Context) error {
f.idx = (f.idx + 1) % len(f.tokens)
return nil
case http.StatusUnauthorized:
resp.Body.Close()
_ = resp.Body.Close()
f.resetAt[f.idx] = time.Now().Add(time.Hour)
slog.ErrorContext(ctx, "github_token_rejected", "token_index", f.idx+1, "page", page)
f.idx = (f.idx + 1) % len(f.tokens)
return nil
default:
resp.Body.Close()
_ = resp.Body.Close()
return fmt.Errorf("unexpected status %s", resp.Status)
}
}
Expand Down
10 changes: 5 additions & 5 deletions backend/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestFetcherPollDeduplicatesAndOrders(t *testing.T) {
}
w.Header().Set("X-RateLimit-Remaining", "42")
w.Header().Set("X-RateLimit-Limit", "5000")
fmt.Fprint(w, feed)
_, _ = fmt.Fprint(w, feed)
}))
defer srv.Close()
b := newBroker()
Expand Down Expand Up @@ -67,11 +67,11 @@ func TestFetcherFindsStarsBeyondFirstPageAndRespectsPollInterval(t *testing.T) {
return
}
w.Header().Set("ETag", `"feed-v1"`)
fmt.Fprint(w, `[{"id":"3","type":"PushEvent"}]`)
_, _ = fmt.Fprint(w, `[{"id":"3","type":"PushEvent"}]`)
case "2":
fmt.Fprint(w, `[{"id":"2","type":"WatchEvent"}]`)
_, _ = fmt.Fprint(w, `[{"id":"2","type":"WatchEvent"}]`)
case "3":
fmt.Fprint(w, `[{"id":"1","type":"ForkEvent"}]`)
_, _ = fmt.Fprint(w, `[{"id":"1","type":"ForkEvent"}]`)
default:
t.Errorf("unexpected page %q", r.URL.Query().Get("page"))
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestFetcherRotatesRateLimitedToken(t *testing.T) {
w.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(w, `[]`)
_, _ = fmt.Fprint(w, `[]`)
}))
defer srv.Close()
f, _ := newFetcher([]string{"exhausted", "working"}, newBroker())
Expand Down
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func run() error {
mux := http.NewServeMux()
mux.Handle("/sse", b)
mux.HandleFunc("/healthz", func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("ok"))
_, _ = rw.Write([]byte("ok"))
})

srv := &http.Server{Addr: "0.0.0.0:3003", Handler: mux, ReadHeaderTimeout: 5 * time.Second}
Expand Down
4 changes: 2 additions & 2 deletions backend/sse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSSEBroadcastAndDisconnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if got := resp.Header.Get("Content-Type"); got != "text/event-stream" {
t.Fatalf("Content-Type = %q", got)
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestSSEReplaysRecentEventsToNewClient(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
scanner := bufio.NewScanner(resp.Body)
var events []string
for scanner.Scan() {
Expand Down
Loading