Add CLAUDE.md with project guidance and update CI workflow for improved coverage and Docker build
This commit is contained in:
@@ -16,12 +16,45 @@ jobs:
|
|||||||
go-version: '1.26'
|
go-version: '1.26'
|
||||||
- name: Run tests with coverage
|
- name: Run tests with coverage
|
||||||
run: |
|
run: |
|
||||||
go test -v -coverprofile=coverage.out ./...
|
go test -v -coverprofile=coverage.out -coverpkg=./... ./...
|
||||||
go tool cover -func=coverage.out | tee coverage.txt
|
go tool cover -func=coverage.out | tee coverage.txt
|
||||||
cov=$(go tool cover -func=coverage.out | grep total: | awk '{print substr($3, 1, length($3)-1)}')
|
cov=$(go tool cover -func=coverage.out | grep total: | awk '{print substr($3, 1, length($3)-1)}')
|
||||||
cov=${cov%.*}
|
cov=${cov%.*}
|
||||||
if [ "$cov" -lt 80 ]; then
|
if [ "$cov" -lt 80 ]; then
|
||||||
echo "::warning::Test coverage is below 80% ($cov%)"
|
echo "::warning::Test coverage is below 80% ($cov%)"
|
||||||
fi
|
fi
|
||||||
- name: Build Docker image
|
- name: Build binary
|
||||||
run: docker build -t diun-webhook-dashboard .
|
run: go build ./...
|
||||||
|
|
||||||
|
docker:
|
||||||
|
runs-on: dind
|
||||||
|
needs: build-test
|
||||||
|
if: gitea.event_name == 'push'
|
||||||
|
container:
|
||||||
|
image: docker:cli
|
||||||
|
services:
|
||||||
|
dind:
|
||||||
|
image: docker:dind
|
||||||
|
options: --privileged
|
||||||
|
env:
|
||||||
|
DOCKER_TLS_CERTDIR: ""
|
||||||
|
env:
|
||||||
|
DOCKER_HOST: tcp://dind:2375
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Log in to Gitea registry
|
||||||
|
run: |
|
||||||
|
REGISTRY="${{ gitea.server_url }}"
|
||||||
|
REGISTRY="${REGISTRY#https://}"
|
||||||
|
REGISTRY="${REGISTRY#http://}"
|
||||||
|
echo "${{ secrets.GITEA_TOKEN }}" | docker login "$REGISTRY" -u "${{ gitea.actor }}" --password-stdin
|
||||||
|
- name: Build and push
|
||||||
|
run: |
|
||||||
|
REGISTRY="${{ gitea.server_url }}"
|
||||||
|
REGISTRY="${REGISTRY#https://}"
|
||||||
|
REGISTRY="${REGISTRY#http://}"
|
||||||
|
IMAGE="$REGISTRY/${{ gitea.repository }}"
|
||||||
|
docker build -t "$IMAGE:${{ gitea.sha }}" -t "$IMAGE:latest" .
|
||||||
|
docker push "$IMAGE:${{ gitea.sha }}"
|
||||||
|
docker push "$IMAGE:latest"
|
||||||
6
.idea/copilot.data.migration.ask2agent.xml
generated
Normal file
6
.idea/copilot.data.migration.ask2agent.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Ask2AgentMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
40
CLAUDE.md
Normal file
40
CLAUDE.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all tests with coverage
|
||||||
|
go test -v -coverprofile=coverage.out -coverpkg=./... ./...
|
||||||
|
|
||||||
|
# Run a single test
|
||||||
|
go test -v -run TestWebhookHandler ./test/diunwebhook/
|
||||||
|
|
||||||
|
# Run the app locally
|
||||||
|
go run ./cmd/diunwebhook/
|
||||||
|
|
||||||
|
# Build Docker image
|
||||||
|
docker build -t diun-webhook-dashboard .
|
||||||
|
|
||||||
|
# Run with Docker Compose
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
CI warns (but does not fail) when coverage drops below 80%.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
The app is a minimal Go HTTP server that receives [DIUN](https://crazymax.dev/diun/) webhook events and exposes them via a JSON API and static HTML dashboard. All state is in-memory (no persistence).
|
||||||
|
|
||||||
|
**Package layout:**
|
||||||
|
- `pkg/diunwebhook/` — core library: `DiunEvent` struct, in-memory `updates` map (guarded by `sync.Mutex`), and HTTP handlers (`WebhookHandler`, `UpdatesHandler`)
|
||||||
|
- `cmd/diunwebhook/main.go` — wires the handlers and static file server onto `net/http`'s default mux, listens on `:8080`
|
||||||
|
- `test/diunwebhook/` — external test package (`package diunwebhook_test`) that imports `pkg/diunwebhook`; uses `httptest` for handler tests
|
||||||
|
- `static/` — served verbatim at `/`
|
||||||
|
|
||||||
|
**Key data flow:**
|
||||||
|
1. DIUN POSTs JSON to `/webhook` → `WebhookHandler` decodes into `DiunEvent` → stored in `updates[event.Image]` (latest event per image wins)
|
||||||
|
2. Dashboard JS polls `GET /api/updates` → `UpdatesHandler` returns full map as JSON
|
||||||
|
|
||||||
|
**Test helpers exposed from the library package** (not part of the public API, only for tests): `GetUpdatesMap()`, `UpdatesReset()`, `UpdateEvent()`.
|
||||||
Reference in New Issue
Block a user