diff --git a/Makefile b/Makefile index 4ba7f6a64..d631e68a9 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ VERSION=$(shell make -s version) PYTHON?=python3 TESTS?= BINPATH?=$(GOPATH)/bin -RUN_LONG_TESTS?=yes GOLANGCI_LINT_VERSION=v1.54.1 # version supporting go 1.19 COVERAGE_DIR?=$(shell mktemp -d) GOOS=$(shell go env GOHOSTOS) @@ -18,55 +17,62 @@ help: ## Print this help @grep -E '^[a-zA-Z][a-zA-Z0-9_-]*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' prepare: ## Install go module dependencies + # Prepare go modules go mod verify go mod tidy -v - # create VERSION file + # Create VERSION file go generate +releasetype: # Print release type: ci (on any branch/commit), release (on a tag) + @reltype=ci ; \ + gitbranch=`git rev-parse --abbrev-ref HEAD` ; \ + if [ "$$gitbranch" = "HEAD" ] && [ "$$FORCE_CI" != "true" ]; then \ + gittag=`git describe --tags --exact-match` ;\ + if echo "$$gittag" | grep -q '^v[0-9]'; then \ + reltype=release ; \ + fi ; \ + fi ; \ + echo $$reltype + +version: ## Print aptly version + @ci="" ; \ + if [ "`make -s releasetype`" = "ci" ]; then \ + ci=`TZ=UTC git show -s --format='+%cd.%h' --date=format-local:'%Y%m%d%H%M%S'`; \ + fi ; \ + if which dpkg-parsechangelog > /dev/null 2>&1; then \ + echo `dpkg-parsechangelog -S Version`$$ci; \ + else \ + echo `grep ^aptly -m1 debian/changelog | sed 's/.*(\([^)]\+\)).*/\1/'`$$ci ; \ + fi + swagger-install: - # set docs version + # Install swag + @test -f $(BINPATH)/swag || go install github.com/swaggo/swag/cmd/swag@latest + # Create docs/swagger.conf @cp docs/swagger.conf.tpl docs/swagger.conf @echo "// @version $(VERSION)" >> docs/swagger.conf - @test -f $(BINPATH)/swag || go install github.com/swaggo/swag/cmd/swag@latest swagger: swagger-install - PATH=$(BINPATH)/:$(PATH) swag init -q --markdownFiles docs --generalInfo docs/swagger.conf + # Generating swagger docs + @PATH=$(BINPATH)/:$(PATH) swag init -q --markdownFiles docs --generalInfo docs/swagger.conf # GOOS=linux GOARCH=amd64 go install github.com/swaggo/swag/cmd/swag@latest +build: prepare swagger ## Build aptly + go build -o build/aptly + install: @echo "\e[33m\e[1mBuilding aptly ...\e[0m" go generate @out=`mktemp`; if ! go install -v > $$out 2>&1; then cat $$out; rm -f $$out; echo "\nBuild failed\n"; exit 1; else rm -f $$out; fi -system-test: install ## Run system tests in github CI -ifeq ($(RUN_LONG_TESTS), yes) - go generate +etcd-install: # install etcd test -d /srv/etcd || system/t13_etcd/install-etcd.sh - system/t13_etcd/start-etcd.sh & - # build coverage binary - go test -v -coverpkg="./..." -c -tags testruncli - kill `cat /tmp/etcd.pid` - if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi - if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi - cd /home/runner; curl -O http://repo.aptly.info/system-tests/etcd.db.xz; xz -d etcd.db.xz - PATH=$(BINPATH)/:$(PATH) && APTLY_VERSION=$(VERSION) FORCE_COLOR=1 $(PYTHON) system/run.py --long $(TESTS) --coverage-dir $(COVERAGE_DIR) $(CAPTURE) -endif +flake8: ## run flake8 on system test python files + flake8 system/ -docker-test: prepare swagger ## Run system tests - @echo "\e[33m\e[1mBuilding aptly.test ...\e[0m" - @rm -f aptly.test - # build coverage binary - go test -v -coverpkg="./..." -c -tags testruncli - @echo "\e[33m\e[1mRunning python tests ...\e[0m" - @test -e aws.creds && . ./aws.creds; \ - export PATH=$(BINPATH)/:$(PATH); \ - export APTLY_VERSION=$(VERSION); \ - $(PYTHON) system/run.py --long $(TESTS) --coverage-dir $(COVERAGE_DIR) $(CAPTURE) $(TEST) - -test: prepare swagger ## Run unit tests - @test -d /srv/etcd || system/t13_etcd/install-etcd.sh +test: prepare swagger etcd-install ## Run unit tests @echo "\e[33m\e[1mStarting etcd ...\e[0m" @mkdir -p /tmp/etcd-data; system/t13_etcd/start-etcd.sh > /tmp/etcd-data/etcd.log 2>&1 & @echo "\e[33m\e[1mRunning go test ...\e[0m" @@ -76,46 +82,24 @@ test: prepare swagger ## Run unit tests @rm -f /tmp/etcd-data/etcd.log @ret=`cat .unit-test.ret`; if [ "$$ret" = "0" ]; then echo "\n\e[32m\e[1mUnit Tests SUCCESSFUL\e[0m"; else echo "\n\e[31m\e[1mUnit Tests FAILED\e[0m"; fi; rm -f .unit-test.ret; exit $$ret +system-test: prepare swagger etcd-install ## Run system tests + # build coverage binary + go test -v -coverpkg="./..." -c -tags testruncli + # Download fixture-db, fixture-pool, etcd.db + if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi + if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi + test -f ~/etcd.db || (curl -O http://repo.aptly.info/system-tests/etcd.db.xz && xz -d etcd.db.xz) + # Run system tests + PATH=$(BINPATH)/:$(PATH) && FORCE_COLOR=1 $(PYTHON) system/run.py --long $(TESTS) --coverage-dir $(COVERAGE_DIR) $(CAPTURE) $(TEST) + bench: @echo "\e[33m\e[1mRunning benchmark ...\e[0m" go test -v ./deb -run=nothing -bench=. -benchmem -mem.png: mem.dat mem.gp - gnuplot mem.gp - open mem.png - -man: ## Create man pages - make -C man - -version: ## Print aptly version - @ci="" ; \ - if [ "`make -s releasetype`" = "ci" ]; then \ - ci=`TZ=UTC git show -s --format='+%cd.%h' --date=format-local:'%Y%m%d%H%M%S'`; \ - fi ; \ - if which dpkg-parsechangelog > /dev/null 2>&1; then \ - echo `dpkg-parsechangelog -S Version`$$ci; \ - else \ - echo `grep ^aptly -m1 debian/changelog | sed 's/.*(\([^)]\+\)).*/\1/'`$$ci ; \ - fi - -releasetype: # Print release type (ci/release) - @reltype=ci ; \ - gitbranch=`git rev-parse --abbrev-ref HEAD` ; \ - if [ "$$gitbranch" = "HEAD" ] && [ "$$FORCE_CI" != "true" ]; then \ - gittag=`git describe --tags --exact-match` ;\ - if echo "$$gittag" | grep -q '^v[0-9]'; then \ - reltype=release ; \ - fi ; \ - fi ; \ - echo $$reltype - -build: prepare swagger ## Build aptly - go build -o build/aptly - server: prepare swagger-install ## Run devevelopment server go install github.com/air-verse/air@v1.52.3 - cp debian/aptly.conf /var/lib/aptly/.aptly.conf - sed -i /enableSwaggerEndpoint/s/false/true/ /var/lib/aptly/.aptly.conf + cp debian/aptly.conf ~/.aptly.conf + sed -i /enableSwaggerEndpoint/s/false/true/ ~/.aptly.conf PATH=$(BINPATH):$$PATH air -build.pre_cmd 'swag init -q --markdownFiles docs --generalInfo docs/swagger.conf' -build.exclude_dir system,debian,docs,pgp/keyrings,pgp/test-bins,completion.d,man,deb/testdata -- api serve -listen 0.0.0.0:3142 dpkg: prepare swagger ## Build debian packages @@ -173,7 +157,7 @@ docker-unit-tests: ## Run unit tests in docker container @docker run -it --rm -v ${PWD}:/app aptly-dev /app/system/run-unit-tests docker-system-tests: ## Run system tests in docker container (add TEST=t04_mirror or TEST=UpdateMirror26Test to run only specific tests) - @docker run -it --rm -v ${PWD}:/app aptly-dev /app/system/run-system-tests $(TEST) + @docker run -it --rm -v ${PWD}:/work/src aptly-dev /work/src/system/docker-wrapper system-test $(TEST) docker-server: ## Run development server (auto recompiling) on http://localhost:3142 @docker run -it --rm -p 3142:3142 -v ${PWD}:/work/src aptly-dev /work/src/system/docker-wrapper server @@ -184,13 +168,18 @@ docker-lint: ## Run golangci-lint in docker container docker-binaries: ## Build binary releases (FreeBSD, MacOS, Linux tar) in docker container @docker run -it --rm -v ${PWD}:/app aptly-dev /app/system/build-binaries -flake8: ## run flake8 on system tests - flake8 system +mem.png: mem.dat mem.gp + gnuplot mem.gp + open mem.png + +man: ## Create man pages + make -C man clean: ## remove local build and module cache + # Clean all generated and build files test -d .go/ && chmod u+w -R .go/ && rm -rf .go/ || true rm -rf build/ obj-*-linux-gnu* tmp/ rm -f unit.out aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf - find system/ -type d -name __pycache__ -exec rm -rf {} \; 2>/dev/null + find system/ -type d -name __pycache__ -exec rm -rf {} \; 2>/dev/null || true .PHONY: help man prepare swagger version binaries docker-release docker-system-tests docker-unit-tests docker-lint docker-build docker-image build docker-shell clean releasetype dpkg server docker-server flake8 diff --git a/system/Dockerfile b/system/Dockerfile index 13bb22f38..b57ce88b1 100644 --- a/system/Dockerfile +++ b/system/Dockerfile @@ -11,7 +11,7 @@ RUN useradd -m --shell /bin/sh --home-dir /var/lib/aptly aptly RUN sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/' /var/lib/aptly/.bashrc RUN mkdir /work -WORKDIR /work +WORKDIR /work/src RUN chown aptly /work RUN cd /var/lib/aptly; git clone https://github.com/aptly-dev/aptly-fixture-db.git @@ -21,5 +21,3 @@ RUN echo "aptly ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/aptly ADD system/t13_etcd/install-etcd.sh /src/ RUN /src/install-etcd.sh RUN rm -rf /src - -CMD /app/system/run-system-tests diff --git a/system/run.py b/system/run.py index f4a2ef4fa..599afe5f3 100755 --- a/system/run.py +++ b/system/run.py @@ -184,12 +184,10 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non if __name__ == "__main__": - if 'APTLY_VERSION' not in os.environ: - try: - os.environ['APTLY_VERSION'] = os.popen( - "make version").read().strip() - except BaseException as e: - print("Failed to capture current version: ", e) + try: + os.environ['APTLY_VERSION'] = os.popen("make -s version").read().strip() + except BaseException as e: + print("Failed to capture current version: ", e) if sys.version_info < PYTHON_MINIMUM_VERSION: raise RuntimeError(f'Tests require Python {PYTHON_MINIMUM_VERSION} or higher.')