From 50d11ce374e1c130ab68050068228084bb8de03e Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sat, 8 Mar 2025 18:56:02 +0100 Subject: [PATCH] Add a pre-push git-hook to run tests on obitools commands before pushing on master --- Makefile | 33 ++++++++++++++++++--------------- git-hooks/pre-push | 23 +++++++++++++++++++++++ pkg/obioptions/version.go | 2 +- 3 files changed, 42 insertions(+), 16 deletions(-) create mode 100755 git-hooks/pre-push diff --git a/Makefile b/Makefile index b16fa89..d3355f1 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,12 @@ PACKAGES_SRC:= $(wildcard pkg/*/*.go pkg/*/*/*.go) PACKAGE_DIRS:=$(sort $(patsubst %/,%,$(dir $(PACKAGES_SRC)))) 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_DIRS:=$(sort $(patsubst %/,%,$(dir $(OBITOOLS_SRC)))) OBITOOLS:=$(notdir $(OBITOOLS_DIRS)) @@ -53,15 +59,23 @@ endif OUTPUT:=$(shell mktemp) -all: obitools +all: install-githook obitools -packages: $(patsubst %,pkg-%,$(PACKAGES)) 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: go get -u ./... -test: +test: .FORCE $(GOTEST) ./... obitests: @@ -70,17 +84,6 @@ obitests: done 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): mkdir -p $@ @@ -104,5 +107,5 @@ ifneq ($(strip $(COMMIT_ID)),) @rm -f $(OUTPUT) endif -.PHONY: all packages obitools man obibook doc update-deps obitests githubtests .FORCE +.PHONY: all obitools update-deps obitests githubtests .FORCE .FORCE: \ No newline at end of file diff --git a/git-hooks/pre-push b/git-hooks/pre-push new file mode 100755 index 0000000..2d9a0fd --- /dev/null +++ b/git-hooks/pre-push @@ -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 \ No newline at end of file diff --git a/pkg/obioptions/version.go b/pkg/obioptions/version.go index f4861bc..4fab2a9 100644 --- a/pkg/obioptions/version.go +++ b/pkg/obioptions/version.go @@ -8,7 +8,7 @@ import ( // corresponds to the last commit, and not the one when the file will be // commited -var _Commit = "65bd29b" +var _Commit = "52d5f6f" var _Version = "Release 4.4.0" // Version returns the version of the obitools package.