+# Makefile
-GITCMDS := fetch checkout pull add commit push
-DATE ?= $(shell (date '+%T %d.%m.%Y'))
-DTSTAMP ?= $(shell (date '+%Y%d%m%H%M%S'))
-VERSION ?= $(shell git symbolic-ref --short HEAD 2>/dev/null)/$(shell git rev-list --count HEAD 2>/dev/null)/$(shell git rev-parse --short=8 HEAD 2>/dev/null)
-OWNER ?= $(shell whoami)
-CHECK ?= $(shell cat "./gitVer.txt")
+BUILD_DIR = $(shell pwd)
+REPO_DIR ?= $(BUILD_DIR)
-#export DATE DTSTAMP VERSION
+ALL_RSC := $(wildcard html/*.rsc html/*/*.rsc)
+commitinfo.sh := $(wildcard bin/commitinfo.sh)
+GLOB_RSC := $(wildcard html/AM-GlobalFunc.rsc)
-all: $(GITCMDS)
+SHELL := /bin/bash
+include ../.config/config.mk
-.PHONY: $(GITCMDS)
+COMM_TAG := $(shell git rev-list --abbrev-commit --tags --max-count=1)
+# `2>/dev/null` suppress errors and `|| true` suppress the error codes.
+TAG := $(shell git describe --abbrev=0 --tags ${COMM_TAG} 2>/dev/null || true)
+# here we strip the version prefix
+TAG_VERS :=$(TAG:v%=%)
+# get the latest commit hash in the short form
+COMM_HASH := $(shell git rev-parse --short=8 HEAD 2>/dev/null) # Get short commit hash
+#COMMIT := $(shell git rev-parse --short HEAD)
+# get the latest commit date in the form of YYYYmmddHHMM ($(DTSTAMP_FMT))
+COMM_DATE := $(shell git log -1 --format=%cd --date=format:$(DTSTAMP_FMT))
+ifneq ($(COMM_HASH), $(COMM_TAG))
+ TAG_VERS :=$(TAG_VERS)-next-$(COMM_HASH)-$(COMM_DATE)
+endif
+ifeq ($(TAG_VERS), )
+ TAG_VERS :=$(COMM_HASH)-$(COMM_DATE)
+endif
+ifneq ($(shell git status --porcelain), )
+ TAG_VERS :=$(TAG_VERS)-dirty
+endif
-fetch: ORIGIN := main
-commit: ARGS := -m
-commit: SRING := "$(DATE) - Commit version: $(VERSION), owner $(OWNER)."
+.ONESHELL:
-#define edit-file =
-# cd $@ && \
-# wget -r -nH -X $(EXCLUDEDIRS) --restrict-file-names=nocontrol $(DOMAIN)
-#endef
+export BUILD_DIR REPO_DIR ALL_RSC GLOB_RSC
-$(GITCMDS):
-
-commitinfo: AM-global-functions.rsc
- contrib/commitinfo.sh $< > $<~
+.DEFAULT_GOAL := all
+
+.PHONY: all check commit notify test
+
+all:
+ @$(MAKE) check; rc=$$?; \
+ if [ $$rc -eq 0 ]; then \
+ echo "[add] check $$rc, go to commit..."; \
+ $(MAKE) commit; cm=$$?; \
+ if [ $$cm -eq 0 ]; then \
+ echo "[all] commit exit $$ci. Exit Ok."; \
+ else \
+ $(MAKE) notify MSG="[all] commit exit $$ci. Check it!"; \
+ fi \
+ else \
+ echo "[all] check exit $$rc, repo is clean exit Ok."; \
+ fi
+ @echo "[all] done"
+
+run:
+ @$(MAKE) check; rc=$$?; \
+ if [ $$rc -eq 0 ]; then \
+ echo "[run] check $$rc, go to commitinfo.sh..."; \
+ $(MAKE) $(commitinfo.sh); ci=$$?; \
+ if [ $$ci -eq 0 ]; then \
+ echo "[run] commitinfo.sh exit $$ci. Go to checksums.sh..."; \
+ $(MAKE) checksums; cs=$$?; \
+ if [ $$cs -eq 0 ]; then \
+ echo "[run] checksums.sh exit $$cs. Do git add commit and push..."; \
+ git add .; \
+ git commit -m '$(COMM_INFO)'; \
+ git push; \
+ else \
+ $(MAKE) notify MSG="[run] checksums.sh exit $$cs, check it!"; \
+ fi \
+ else \
+ $(MAKE) notify MSG="[run] commitinfo.sh exit $$ci, check it!"; \
+ fi \
+ else \
+ echo "[run] check exit $$rc, repo is clean exit Ok."; \
+ fi
+ @echo "[run] done"
+
+check:
+ @bash bin/check_repo.sh
+
+commit:
+ cd $(BUILD_DIR)
+ git add .
+ git commit -m '$(COMM_INFO)'
+ git push
+
+notify:
+ @bash bin/notify_telegram.sh "$(MSG)"
+
+checksums: checksums.json
+
+checksums.json: bin/checksums.sh $(ALL_RSC)
+ bin/checksums.sh > html/tmp/$@
+
+$(commitinfo.sh): $(GLOB_RSC)
+ $(commitinfo.sh) $< > $<~
mv $<~ $<
-clean:
- rm -f $(HTML) checksums.json
- make -C contrib/ clean
+test:
+ @bash -n bin/check_repo.sh
+ @bash -n bin/notify_telegram.sh
+ @bash -n bin/checksums.sh
+ @bash -n bin/commitinfo.sh
+ @echo "syntax ok"
+
+#clean:
+# git checkout HEAD -- .
--- /dev/null
+#!/usr/bin/env bash
+
+cd "${REPO_DIR:-.}"
+
+dirty="$(git ls-files -u || true)"
+lsfiles="$(git ls-files --others --exclude-standard || true)"
+
+# Conflict or unresolved state: stop and notify.
+if [[ -n "$dirty" ]]; then
+ echo "[check_repo] repo has conflicts, stop"
+ echo "[check_repo] unmerged files:"
+ printf "%s\n" "$dirty"
+ echo "[check_repo] resolve conflicts and run: git add <files> && git commit"
+ bash bin/notify_telegram.sh "STOP: repo conflicts in $(pwd)"
+ exit 1
+fi
+
+# Exit 0 only when repo is NOT clean to allow autocommit flow.
+if git diff --quiet && git diff --cached --quiet && [[ -z "$lsfiles" ]]; then
+ echo "[check_repo] repo clean. Exit 1 from check_repo.sh."
+ exit 1
+else
+ echo "[check_repo] repo not clean. Exit 0 from check_repo.sh."
+ exit 0
+fi