Add a pre-push git-hook to run tests on obitools commands before pushing on master

This commit is contained in:
Eric Coissac
2025-03-08 18:56:02 +01:00
parent 52d5f6fe11
commit 50d11ce374
3 changed files with 42 additions and 16 deletions

View File

@ -16,6 +16,12 @@ PACKAGES_SRC:= $(wildcard pkg/*/*.go pkg/*/*/*.go)
PACKAGE_DIRS:=$(sort $(patsubst %/,%,$(dir $(PACKAGES_SRC)))) PACKAGE_DIRS:=$(sort $(patsubst %/,%,$(dir $(PACKAGES_SRC))))
PACKAGES:=$(notdir $(PACKAGE_DIRS)) PACKAGES:=$(notdir $(PACKAGE_DIRS))
GITHOOK_SRC_DIR=git-hooks
GITHOOKS_SRC:=$(wildcard $(GITHOOK_SRC_DIR)/*)
GITHOOK_DIR=.git/hooks
GITHOOKS:=$(patsubst $(GITHOOK_SRC_DIR)/%,$(GITHOOK_DIR)/%,$(GITHOOKS_SRC))
OBITOOLS_SRC:= $(wildcard cmd/obitools/*/*.go) OBITOOLS_SRC:= $(wildcard cmd/obitools/*/*.go)
OBITOOLS_DIRS:=$(sort $(patsubst %/,%,$(dir $(OBITOOLS_SRC)))) OBITOOLS_DIRS:=$(sort $(patsubst %/,%,$(dir $(OBITOOLS_SRC))))
OBITOOLS:=$(notdir $(OBITOOLS_DIRS)) OBITOOLS:=$(notdir $(OBITOOLS_DIRS))
@ -53,15 +59,23 @@ endif
OUTPUT:=$(shell mktemp) OUTPUT:=$(shell mktemp)
all: obitools all: install-githook obitools
packages: $(patsubst %,pkg-%,$(PACKAGES))
obitools: $(patsubst %,$(OBITOOLS_PREFIX)%,$(OBITOOLS)) obitools: $(patsubst %,$(OBITOOLS_PREFIX)%,$(OBITOOLS))
install-githook: $(GITHOOKS)
$(GITHOOK_DIR)/%: $(GITHOOK_SRC_DIR)/%
@echo installing $$(basename $@)...
@mkdir -p $(GITHOOK_DIR)
@cp $< $@
@chmod +x $@
update-deps: update-deps:
go get -u ./... go get -u ./...
test: test: .FORCE
$(GOTEST) ./... $(GOTEST) ./...
obitests: obitests:
@ -71,17 +85,6 @@ obitests:
githubtests: obitools obitests githubtests: obitools obitests
man:
make -C doc man
obibook:
make -C doc obibook
doc: man obibook
macos-pkg:
@bash pkgs/macos/macos-installer-builder-master/macOS-x64/build-macos-x64.sh \
OBITools \
0.0.1
$(BUILD_DIR): $(BUILD_DIR):
mkdir -p $@ mkdir -p $@
@ -104,5 +107,5 @@ ifneq ($(strip $(COMMIT_ID)),)
@rm -f $(OUTPUT) @rm -f $(OUTPUT)
endif endif
.PHONY: all packages obitools man obibook doc update-deps obitests githubtests .FORCE .PHONY: all obitools update-deps obitests githubtests .FORCE
.FORCE: .FORCE:

23
git-hooks/pre-push Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
remote="$1"
#url="$2"
log() {
echo -e "[Pre-Push tests @ $(date)] $*" 1>&2
}
current_branch=$(git symbolic-ref --short head)
cmd="make githubtests"
if [[ $current_branch = "master" ]]; then
log "you are on $current_branch, running build test"
if ! eval "$cmd"; then
log "Pre-push tests failed $cmd"
exit 1
fi
fi
log "Tests are OK, ready to push on $remote"
exit 0

View File

@ -8,7 +8,7 @@ import (
// corresponds to the last commit, and not the one when the file will be // corresponds to the last commit, and not the one when the file will be
// commited // commited
var _Commit = "65bd29b" var _Commit = "52d5f6f"
var _Version = "Release 4.4.0" var _Version = "Release 4.4.0"
// Version returns the version of the obitools package. // Version returns the version of the obitools package.