Makefile: initial commit, add phony review target

This commit is contained in:
Ryan Heywood 2024-01-18 18:01:44 -05:00
parent 4c6c071539
commit 8e24555d09
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 24 additions and 0 deletions

24
Makefile Normal file
View File

@ -0,0 +1,24 @@
BASE_REF ?= main
HEAD_REF ?= $(shell git rev-parse HEAD)
.PHONY: review
review:
@echo "Ensuring Cargo.lock is in clean state, not modified"
test -z "$(shell git status --porcelain | grep -E 'M +Cargo.lock')"
@echo "Ensuring current HEAD_REF is not BASE_REF"
test "$(shell git rev-parse $(BASE_REF))" != "$(HEAD_REF)"
@echo "Verifying if any changes happened in Cargo.lock that require review"
test "$(shell git show $(BASE_REF):Cargo.lock | sha256sum)" != "$(shell git show $(HEAD_REF):Cargo.lock | sha256sum)"
$(eval TEMP_REPO := $(shell mktemp -d))
git -C $(TEMP_REPO) init
# Fetch files for BASE_REF
git show $(BASE_REF):Cargo.lock > $(TEMP_REPO)/Cargo.lock
CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch
git -C $(TEMP_REPO) add .
git -C $(TEMP_REPO) commit --no-gpg-sign -m "base ref: $(BASE_REF)"
# Fetch files for HEAD_REF
git show $(HEAD_REF):Cargo.lock > $(TEMP_REPO)/Cargo.lock
CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch
git -C $(TEMP_REPO) add -A .
git -C $(TEMP_REPO) difftool HEAD || true
rm -rf $(TEMP_REPO)