APP := pgtidy CMD := ./cmd/pgtidy DIST := dist ARCH_PKGBUILDS := linux/arch/pgtidy-bin/PKGBUILD linux/arch/pgtidy-src/PKGBUILD RPM_SPEC := linux/centos/pgtidy.spec VSCODE_PKG := editors/vscode/package.json DATAGRIP_PROPS := editors/datagrip/gradle.properties PKG_FILES := $(ARCH_PKGBUILDS) $(RPM_SPEC) $(VSCODE_PKG) $(DATAGRIP_PROPS) .PHONY: installer-windows build test lint vet fmt clean release release-version snapshot vscode-compile vscode-package ## build: compile binary for the current platform build: go build -trimpath -ldflags "-s -w -X main.version=$$(git describe --tags --abbrev=0 2>/dev/null || echo dev)" -o $(DIST)/$(APP) $(CMD) ## test: run tests (incl. corpus safety harness) test: go test ./... ## vet: static analysis vet: go vet ./... ## fmt: format Go code fmt: go fmt ./... ## lint: vet + format check + golangci-lint lint: vet test -z "$$(gofmt -l .)" || (echo "gofmt needed:"; gofmt -l .; exit 1) golangci-lint run ./... ## installer-windows: build the Windows binary and NSIS installer (requires makensis) installer-windows: GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$$(git describe --tags --abbrev=0 2>/dev/null || echo dev)" -o $(DIST)/pgtidy-windows-amd64.exe $(CMD) makensis -DVERSION=$$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$$' || echo 0.0.0) -DEXE=$(CURDIR)/$(DIST)/pgtidy-windows-amd64.exe -DOUT=$(CURDIR)/$(DIST)/pgtidy-setup-windows-amd64.exe windows/installer.nsi ## clean: remove build artifacts clean: rm -rf $(DIST) ## snapshot: build multi-platform binaries without publishing (requires goreleaser) snapshot: goreleaser release --snapshot --clean ## release: auto-increment patch version, update package files, tag, and push release: @CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \ MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \ PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \ echo "Current: $$CURRENT"; \ $(MAKE) --no-print-directory release-version VERSION="$$MAJOR.$$MINOR.$$((PATCH + 1))" ## release-version: release VERSION=X.Y.Z — set and verify version in all package files, commit, tag, push release-version: @set -e; PKGVER="$(VERSION)"; PKGVER="$${PKGVER#v}"; NEXT="v$$PKGVER"; \ if ! echo "$$PKGVER" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \ echo "VERSION must be X.Y.Z (got '$(VERSION)')"; exit 1; fi; \ if git rev-parse -q --verify "refs/tags/$$NEXT" >/dev/null; then \ echo "Tag $$NEXT already exists"; exit 1; fi; \ echo "Releasing $$NEXT"; \ sed -i "s/^pkgver=.*/pkgver=$$PKGVER/" $(ARCH_PKGBUILDS); \ sed -i "s/^Version:.*/Version: $$PKGVER/" $(RPM_SPEC); \ sed -i "s/^ \"version\": \".*\",$$/ \"version\": \"$$PKGVER\",/" $(VSCODE_PKG); \ sed -i "s/^pluginVersion=.*/pluginVersion=$$PKGVER/" $(DATAGRIP_PROPS); \ fail=0; \ for f in $(ARCH_PKGBUILDS); do grep -qx "pkgver=$$PKGVER" $$f || { echo "pkgver not set in $$f"; fail=1; }; done; \ grep -qx "Version: $$PKGVER" $(RPM_SPEC) || { echo "Version not set in $(RPM_SPEC)"; fail=1; }; \ grep -qx " \"version\": \"$$PKGVER\"," $(VSCODE_PKG) || { echo "version not set in $(VSCODE_PKG)"; fail=1; }; \ grep -qx "pluginVersion=$$PKGVER" $(DATAGRIP_PROPS) || { echo "pluginVersion not set in $(DATAGRIP_PROPS)"; fail=1; }; \ if [ $$fail -ne 0 ]; then git checkout -- $(PKG_FILES); echo "Aborted — package files restored"; exit 1; fi; \ git add $(PKG_FILES); \ git commit -m "chore(release): bump version to $$PKGVER"; \ git tag -a "$$NEXT" -m "Release $$NEXT"; \ git push origin HEAD "$$NEXT"; \ echo "Pushed $$NEXT — release workflow triggered" ## vscode-compile: compile the VSCode extension TypeScript vscode-compile: cp -r assets editors/vscode/assets cd editors/vscode && pnpm install && pnpm run build ## vscode-package: build the .vsix package vscode-package: vscode-compile cd editors/vscode && pnpm run package