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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dist/
*.pem
console.yaml
web/node_modules/
internal/admin/ui/assets/
internal/admin/ui/index.html
22 changes: 5 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@ on:
branches: [ "main" ]

jobs:
# The admin UI isn't committed; the binary and the admin tests embed it,
# so it's built (and type-checked) before lint and tests.
ci:
uses: divmora/.github/.github/workflows/go-ci.yml@main
with:
go-version: '1.27'

# The admin UI's build output is committed (the binary embeds it), so
# check it type-checks and matches web/src.
web:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: npm
cache-dependency-path: web/package-lock.json
- run: make web
- name: Committed build is up to date
run: git diff --exit-code -- internal/admin/ui || (echo "::error::run 'make web' and commit internal/admin/ui" && exit 1)
node-version: '24'
node-cache-dependency-path: web/package-lock.json
pre-build-command: make web
4 changes: 4 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
uses: divmora/.github/.github/workflows/docker-publish.yml@main
with:
enable-go-quality: true
# The admin UI isn't committed: build it before lint and tests.
node-version: '24'
node-cache-dependency-path: web/package-lock.json
pre-build-command: make web
go-version: '1.27'
sha: ${{ inputs.sha || '' }}
tag_name: ${{ inputs.tag_name || '' }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ coverage.html
*.kubeconfig
web/node_modules/
web/dist/
# The admin UI is built from web/ (make web) and embedded at build time;
# only the placeholder that keeps go:embed compiling is committed.
/internal/admin/ui/*
!/internal/admin/ui/.keep
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ before:
hooks:
- go mod tidy
- go mod verify
# The admin UI isn't committed: build it so the binaries embed it.
- make web

builds:
- id: console
Expand Down
8 changes: 5 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ internal/settings/ runtime settings: config file seeds the database, admin pa
internal/server/ webhooks (GitHub, GitLab, Bitbucket), command parsing, queue + history, jobs.go
(targets, per-job config/secrets), status dashboard
internal/admin/ OIDC sign-in (code flow + PKCE + nonce), DB sessions, CSRF, admin JSON API;
embeds ui/ (the built admin app, committed so `go build` needs no Node)
embeds ui/ (the built admin app; not committed: only ui/.keep is, and a
build without it serves a "UI not built" page)
web/ admin app source: React + TypeScript + Vite. `make web` builds it into
internal/admin/ui; CI fails if the committed build is stale
internal/admin/ui; the Dockerfile, GoReleaser (before hook) and CI build it
internal/store/ PostgreSQL: repos, overrides, jobs + results, sessions, audit, model
profiles, settings; migrations under an advisory lock. storetest/ = fake
```
Expand Down Expand Up @@ -97,7 +98,8 @@ Changing this contract means changing the bot's CLI too; keep them in step.
## Admin UI

React + TypeScript + Vite, styled with **Tailwind CSS v4 and shadcn/ui** (Radix primitives, Lucide
icons). Change `web/src`, run `make web`, commit both `web/` and `internal/admin/ui`.
icons). Change `web/src` and run `make web` to see it in a local build; commit only `web/`
(`internal/admin/ui` is ignored, except `.keep`, which `web/public/.keep` restores on each build).

- `web/src/components/ui/` holds shadcn components (`npx shadcn@<pinned> add <name>`). After adding
one, check its imports: utilities come from `@/lib/utils`. The CLI has written `from "cn"` and
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
# can bump it.
FROM ghcr.io/divmora/code-review-bot:0.5.0 AS bot

# The admin UI (web/) is built here and embedded by the Go build below.
FROM --platform=$BUILDPLATFORM node:24-bookworm-slim AS web
WORKDIR /src/web
COPY web/package.json web/package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY web/ ./
RUN npm run build

FROM --platform=$BUILDPLATFORM golang:1.27-bookworm AS builder
ARG TARGETOS
ARG TARGETARCH
Expand All @@ -13,6 +21,7 @@ WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY --from=web /src/internal/admin/ui ./internal/admin/ui
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
go build -trimpath -ldflags "-s -w -X github.com/divmora/code-review-console/internal/version.Version=${VERSION}" \
-o /out/code-review-console ./cmd/console
Expand Down
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,31 @@ LDFLAGS := -s -w -X github.com/divmora/code-review-console/internal/version.Vers
BOT_DIR ?= ../code-review-bot

# Admin UI: web/ (React + Vite) builds into internal/admin/ui, which the
# binary embeds. The build output is committed so `go build` alone works.
# binary embeds. The build output isn't committed: build, test and lint
# build it first when it's missing (`make web` rebuilds it after changes).
UI_INDEX := internal/admin/ui/index.html

web:
@cd web && npm ci --no-audit --no-fund && npm run build

$(UI_INDEX):
@$(MAKE) --no-print-directory web

# Vite dev server on :5173, proxying the API to a console on :8080.
web-dev:
@cd web && npm run dev

build:
build: $(UI_INDEX)
@go build -trimpath -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/console

clean:
@rm -rf bin/ dist/ coverage.out coverage.html

test:
test: $(UI_INDEX)
@go test -race ./...

# PostgreSQL integration tests against a throwaway container.
test-db:
test-db: $(UI_INDEX)
@docker run -d --rm --name crc-test-pg -e POSTGRES_PASSWORD=test -e POSTGRES_DB=console -p 127.0.0.1:55434:5432 postgres:17 >/dev/null
@until docker exec crc-test-pg pg_isready -U postgres -q; do sleep 1; done
@CODEREVIEW_TEST_DATABASE_URL=postgres://postgres:test@127.0.0.1:55434/console go test -race -count=1 ./... ; s=$$?; docker stop crc-test-pg >/dev/null; exit $$s
Expand All @@ -39,7 +45,7 @@ test-e2e:
fmt:
@gofmt -w .

lint:
lint: $(UI_INDEX)
@golangci-lint run ./... || go vet ./...

docker-build:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ Provider keys and cloud credentials (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEM
## Development

```bash
make build # bin/code-review-console
make web # rebuild the admin UI (web/ → internal/admin/ui, commit the result)
make build # bin/code-review-console (builds the admin UI first if it's missing; needs Node.js)
make web # rebuild the admin UI (web/ → internal/admin/ui, embedded; not committed)
make web-dev # admin UI dev server on :5173, proxying to a console on :8080
make test # unit tests
make test # unit tests (the admin tests need the built UI; make builds it)
make test-db # + PostgreSQL integration tests (Docker)
make test-e2e # + end-to-end with the real codereview CLI (local + docker executors)
```
Expand Down
13 changes: 11 additions & 2 deletions internal/admin/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
"github.com/divmora/code-review-console/internal/version"
)

// ui is the admin single-page app, built from web/ by `make web`.
// ui is the admin single-page app, built from web/ by `make web` before
// `go build` (the Dockerfile, GoReleaser and CI do). It isn't committed:
// a fresh checkout has only ui/.keep, and the panel then says to build it.
//
//go:embed all:ui
var uiFS embed.FS
Expand Down Expand Up @@ -66,11 +68,18 @@ func (f filesOnly) Open(name string) (fs.File, error) {
func mustRead(name string) []byte {
b, err := uiFS.ReadFile(name)
if err != nil {
panic("admin UI not built: " + err.Error() + " (run make web)")
return uiMissing
}
return b
}

// uiMissing is served for the panel when the binary was built without the
// admin UI (go build from a checkout, before make web).
var uiMissing = []byte(`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Admin UI not built</title></head>
<body><h1>The admin UI isn't in this build</h1><p>This binary was built without the admin panel's web app.
Run <code>make web</code> (needs Node.js) and then <code>make build</code>, or use a release binary or the Docker image.
The API and webhooks work without it.</p></body></html>`)

// uiCSP allows only the app's own files: no inline scripts or styles.
const uiCSP = "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"

Expand Down
17 changes: 17 additions & 0 deletions internal/admin/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package admin

import (
"fmt"
"os"
"testing"
)

// The admin tests serve the real UI, which isn't committed: say how to
// build it instead of failing test by test.
func TestMain(m *testing.M) {
if _, err := uiFS.ReadFile("ui/index.html"); err != nil {
fmt.Fprintln(os.Stderr, "admin tests need the admin UI: run `make web` (or `make test`) first")
os.Exit(1)
}
os.Exit(m.Run())
}
Empty file added internal/admin/ui/.keep
Empty file.
5 changes: 0 additions & 5 deletions internal/admin/ui/assets/favicon.svg

This file was deleted.

Loading
Loading