diff --git a/.github/workflows/release-goreleaser.yml b/.github/workflows/release-goreleaser.yml new file mode 100644 index 00000000..59645ce4 --- /dev/null +++ b/.github/workflows/release-goreleaser.yml @@ -0,0 +1,55 @@ +name: Release (GoReleaser) + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25.4' + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '24.11.1' + + - name: Build Frontend + working-directory: frontend + run: | + npm ci + npm run build + + - name: Install Cross-Compilation Tools + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.CPMP_TOKEN }} + # Cross-compile env vars + CC_linux_amd64: gcc + CXX_linux_amd64: g++ + CC_linux_arm64: aarch64-linux-gnu-gcc + CXX_linux_arm64: aarch64-linux-gnu-g++ + CGO_ENABLED: 1 diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..cefd23cd --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,67 @@ +version: 2 + +project_name: cpmp + +builds: + - id: cpmp + dir: backend + main: ./cmd/api + binary: cpmp + env: + - CGO_ENABLED=1 + goos: + - linux + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/version.Version={{.Version}} + - -X github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/version.GitCommit={{.Commit}} + - -X github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/version.BuildTime={{.Date}} + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- .Os }}_ + {{- .Arch }} + files: + - LICENSE + - README.md + +nfpms: + - id: packages + package_name: cpmp + vendor: CaddyProxyManagerPlus + homepage: https://github.com/Wikid82/CaddyProxyManagerPlus + maintainer: Wikid82 + description: "Caddy Proxy Manager Plus - A powerful reverse proxy manager" + license: MIT + formats: + - deb + - rpm + contents: + - src: ./backend/data/ + dst: /var/lib/cpmp/data/ + type: dir + - src: ./frontend/dist/ + dst: /usr/share/cpmp/frontend/ + type: dir + dependencies: + - libc6 + - ca-certificates + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b71d0c00..24292309 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,6 +39,24 @@ repos: language: system files: '\.go$' pass_filenames: false + - id: go-test-race + name: Go Test Race + entry: bash -c 'cd backend && go test -race ./...' + language: system + files: '\.go$' + pass_filenames: false + - id: golangci-lint + name: GolangCI-Lint + entry: bash -c 'cd backend && docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run -v' + language: system + files: '\.go$' + pass_filenames: false + - id: hadolint + name: Hadolint Dockerfile Check + entry: bash -c 'docker run --rm -i hadolint/hadolint < Dockerfile' + language: system + files: 'Dockerfile' + pass_filenames: false - id: frontend-type-check name: Frontend TypeScript Check entry: bash -c 'cd frontend && npm run type-check' diff --git a/Makefile b/Makefile index dbdfc14a..f531e6db 100644 --- a/Makefile +++ b/Makefile @@ -123,3 +123,24 @@ security-scan-deps: cd backend && go list -m -json all | docker run --rm -i aquasec/trivy:latest sbom --format json - 2>/dev/null || true @echo "Checking for Go module updates..." cd backend && go list -m -u all | grep -E '\[.*\]' || echo "All modules up to date" + +# Quality Assurance targets +lint-backend: + @echo "Running golangci-lint..." + cd backend && docker run --rm -v $(PWD)/backend:/app -w /app golangci/golangci-lint:latest golangci-lint run -v + +lint-docker: + @echo "Running Hadolint..." + docker run --rm -i hadolint/hadolint < Dockerfile + +test-race: + @echo "Running Go tests with race detection..." + cd backend && go test -race -v ./... + +benchmark: + @echo "Running Go benchmarks..." + cd backend && go test -bench=. -benchmem ./... + +integration-test: + @echo "Running integration tests..." + @./scripts/integration-test.sh