build: clean @if command -v nix >/dev/null 2>&1; then \ echo "Building with nix..."; \ nix build; \ else \ echo "Building with go..."; \ mkdir -p result/bin; \ go build -o result/bin/pgit ./cmd/pgit; \ go build -o result/bin/pgit-index ./cmd/pgit-index; \ fi .PHONY: build clean: @# Remove result directory/symlink @rm -rf result @rm -rf bin/ .PHONY: clean fmt: go fmt ./... .PHONY: fmt lint: golangci-lint run .PHONY: lint test: go test ./... .PHONY: test local: go build -o ~/bin/pgit ./cmd/pgit go build -o ~/bin/pgit-index ./cmd/pgit-index .PHONY: local # Update flake.nix vendorHash when go.mod/go.sum changes # This target depends on go.mod and go.sum, so it will only run when they change update-vendor-hash: flake.nix go.mod go.sum @echo "Checking if vendorHash needs update..." @nix build 2>&1 | tee /tmp/nix-build.log; \ if grep -q "hash mismatch" /tmp/nix-build.log; then \ NEW_HASH=$$(grep "got:" /tmp/nix-build.log | sed 's/.*got: *//' | tail -1); \ echo "Updating vendorHash to $$NEW_HASH"; \ sed -i "s|vendorHash = \"sha256-[^\"]*\";|vendorHash = \"$$NEW_HASH\";|" flake.nix; \ sed -i "s|vendorHash = pkgs.lib.fakeHash;|vendorHash = \"$$NEW_HASH\";|" flake.nix; \ elif grep -q "error:.*fakeHash" /tmp/nix-build.log; then \ NEW_HASH=$$(grep "got:" /tmp/nix-build.log | sed 's/.*got: *//' | tail -1); \ echo "Updating vendorHash to $$NEW_HASH"; \ sed -i "s|vendorHash = pkgs.lib.fakeHash;|vendorHash = \"$$NEW_HASH\";|" flake.nix; \ else \ echo "vendorHash is up to date"; \ fi @rm -f /tmp/nix-build.log @touch update-vendor-hash .PHONY: update-vendor-hash # Update flake.lock when flake.nix inputs change update-flake-lock: flake.nix nix flake lock touch update-flake-lock .PHONY: update-flake-lock # Update both vendor hash and flake lock update-flake: update-vendor-hash update-flake-lock @echo "Flake updated successfully" .PHONY: update-flake test-site: mkdir -p testdata.site rm -rf testdata.site/* go run ./cmd/pgit \ -q \ --repo ./testdata \ --out testdata.site \ --clone-url "https://test.com/test/test2" \ --home-url "https://test.com/test" \ --label testdata \ --desc "pgit testing site - [link](https://yourmom.com)" \ --theme "github-dark" \ --revs "main,branch-c" \ --issues .PHONY: test-site static: build clean ./pgit \ --out ./public \ --label pgit \ --desc "static site generator for git" \ --clone-url "https://github.com/picosh/pgit.git" \ --home-url "https://git.erock.io" \ --theme "dracula" \ --revs main .PHONY: dev: static rsync -rv --delete ./public/ pgs.sh:/git-pgit-local/ .PHONY: dev