Vendor the front-end assets and drop the third-party CDN dependencies (BootstrapCDN is being sunset): the bootstrap 4.0.0 css/js, jquery 3.2.1 slim, and popper 1.12.9 now live under static/ and are served from the app, byte-for-byte identical to the previous SRI-pinned files. Migrate CI from Drone to a Gitea Actions workflow that runs docker build . on push, with the checkout action pinned by SHA. Bring the repo up to standard: - add REPO_POLICIES.md, .editorconfig, .dockerignore, .golangci.yml, and a comprehensive root-anchored .gitignore - rewrite the Makefile with the required test/lint/fmt/fmt-check/check/ docker/hooks targets (golangci-lint, 30s test timeout, verbose rerun on failure, check modifies nothing) - rewrite the Dockerfile as a hash-pinned multistage build: a lint stage (golangci-lint), a glibc build+test stage (the legacy sqlite driver needs cgo+glibc), and a debian-slim runtime carrying the binary, templates, and static assets - add real tests for the hn package - bring the code into golangci-lint (default: all) compliance: fix the malformed gorm struct tags, check previously-ignored errors, dispatch the zerolog error event, avoid a uint->Duration overflow, split long functions, and add doc comments — all behaviour-preserving - expand the README with the required sections
79 lines
2.0 KiB
Makefile
79 lines
2.0 KiB
Makefile
# for development, db in cwd
|
|
export DATABASE_PATH := ./storage.sqlite
|
|
|
|
VERSION := $(shell git rev-parse --short HEAD)
|
|
BUILDARCH := $(shell uname -m)
|
|
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
|
|
|
|
FN := server
|
|
IMAGENAME := sneak/orangesite
|
|
|
|
GOLDFLAGS += -X main.Version=$(VERSION)
|
|
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
|
|
GOFLAGS := -ldflags "$(GOLDFLAGS)"
|
|
|
|
.PHONY: default run debug build clean \
|
|
test lint fmt fmt-check check docker hooks \
|
|
docker-dist docker-push
|
|
|
|
default: run
|
|
|
|
# --- development ---------------------------------------------------------
|
|
|
|
run: build
|
|
./$(FN)
|
|
|
|
debug: build
|
|
GOTRACEBACK=all DEBUG=1 ./$(FN)
|
|
|
|
build:
|
|
go build -o $(FN) $(GOFLAGS) ./cmd/$(FN)
|
|
|
|
clean:
|
|
-rm -f ./$(FN)
|
|
|
|
# --- required policy targets ---------------------------------------------
|
|
|
|
# run tests quietly; on failure, rerun verbosely for diagnostics
|
|
test:
|
|
@go test -timeout 30s ./... || \
|
|
{ echo "--- Rerunning with -v for details ---"; \
|
|
go test -timeout 30s -v ./...; exit 1; }
|
|
|
|
lint:
|
|
golangci-lint run ./...
|
|
|
|
fmt:
|
|
gofmt -s -w .
|
|
|
|
fmt-check:
|
|
@out="$$(gofmt -s -l .)"; \
|
|
if [ -n "$$out" ]; then \
|
|
echo "gofmt needed on:"; echo "$$out"; exit 1; \
|
|
fi
|
|
|
|
# check must not modify any files in the repo
|
|
check: fmt-check lint test
|
|
|
|
docker:
|
|
docker build -t $(IMAGENAME) .
|
|
|
|
hooks:
|
|
@printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit
|
|
@printf 'go mod tidy\ngofmt -s -w .\n' >> .git/hooks/pre-commit
|
|
@printf 'git diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> .git/hooks/pre-commit
|
|
@printf 'make check\n' >> .git/hooks/pre-commit
|
|
@chmod +x .git/hooks/pre-commit
|
|
@echo "installed .git/hooks/pre-commit"
|
|
|
|
# --- image distribution --------------------------------------------------
|
|
|
|
docker-dist: docker
|
|
docker tag $(IMAGENAME) $(IMAGENAME):$(VERSION)
|
|
docker tag $(IMAGENAME) $(IMAGENAME):$(BUILDTIMETAG)
|
|
|
|
docker-push: docker-dist
|
|
docker push $(IMAGENAME):$(VERSION)
|
|
docker push $(IMAGENAME):$(BUILDTIMETAG)
|
|
docker push $(IMAGENAME):latest
|