From a9d9e89d0c52fe812cde670b170ab35b20e85bd1 Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 30 Dec 2020 12:01:40 +0100 Subject: [PATCH 1/6] Use a common target to pick yadm to test in test/scripthost --- .gitignore | 1 + Makefile | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index aa13f8f..5324947 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ .jekyll-metadata .pytest_cache .sass-cache +.testyadm _site testenv diff --git a/Makefile b/Makefile index c098057..761f684 100644 --- a/Makefile +++ b/Makefile @@ -97,43 +97,42 @@ test: docker run --rm -it -v "$(CURDIR):/yadm:ro" $(IMAGE) make test testargs="$(testargs)"; \ fi -.PHONY: testhost -testhost: version ?= HEAD -testhost: require-docker - @rm -rf /tmp/testhost +.PHONY: .testyadm +.testyadm: version ?= HEAD +.testyadm: + @echo "Using yadm version=\"$(version)\"" @if [ "$(version)" = "local" ]; then \ - cp -f yadm /tmp/testhost; \ + cp -f yadm $@; \ else \ - git show $(version):yadm > /tmp/testhost; \ + git show $(version):yadm > $@; \ fi - @chmod a+x /tmp/testhost - @echo Starting testhost version=\"$(version)\" + @chmod a+x $@ + +.PHONY: testhost +testhost: require-docker .testyadm + @echo "Starting testhost" @docker run \ -w /root \ --hostname testhost \ --rm -it \ - -v "/tmp/testhost:/bin/yadm:ro" \ + -v "$(CURDIR)/.testyadm:/bin/yadm:ro" \ $(IMAGE) \ bash -l .PHONY: scripthost -scripthost: version ?= HEAD -scripthost: require-docker - @rm -rf /tmp/testhost - @git show $(version):yadm > /tmp/testhost - @chmod a+x /tmp/testhost - @echo Starting scripthost version=\"$(version)\" \(recording script\) +scripthost: require-docker .testyadm + @echo "Starting scripthost \(recording script\)" @printf '' > script.gz @docker run \ -w /root \ --hostname scripthost \ --rm -it \ - -v "$$PWD/script.gz:/script.gz:rw" \ - -v "/tmp/testhost:/bin/yadm:ro" \ + -v "$(CURDIR)/script.gz:/script.gz:rw" \ + -v "$(CURDIR)/.testyadm:/bin/yadm:ro" \ $(IMAGE) \ bash -c "script /tmp/script -q -c 'bash -l'; gzip < /tmp/script > /script.gz" @echo - @echo "Script saved to $$PWD/script.gz" + @echo "Script saved to $(CURDIR)/script.gz" .PHONY: testenv From 44de30374f18f7e005661b3c7359504a4da4f96a Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 30 Dec 2020 12:52:36 +0100 Subject: [PATCH 2/6] Only run docker in interactive mode when stdin is a terminal --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 761f684..c9f5e2e 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,11 @@ test: py.test -v $(testargs); \ else \ $(MAKE) -s require-docker && \ - docker run --rm -it -v "$(CURDIR):/yadm:ro" $(IMAGE) make test testargs="$(testargs)"; \ + docker run \ + --rm -t$(shell test -t 0 && echo i) \ + -v "$(CURDIR):/yadm:ro" \ + $(IMAGE) \ + make test testargs="$(testargs)"; \ fi .PHONY: .testyadm From d926fb3e8bf7da40865e6a487c93d3ad29494859 Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 30 Dec 2020 12:03:23 +0100 Subject: [PATCH 3/6] Run "make test" in github workflow This avoids having to specify the docker image in multiple places. --- .github/workflows/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc9b4da..1dae7cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Tests - run: >- - docker run -t --rm - -v "$PWD:/yadm:ro" - yadm/testbed:2020-12-29 + run: make test From 64da1a6bee1391bc0eb78c827e9b3af388979cdc Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 30 Dec 2020 12:22:14 +0100 Subject: [PATCH 4/6] Include released yadm versions also in testenv --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index c9f5e2e..483ee9f 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,10 @@ testenv: python3 -m venv --clear testenv testenv/bin/pip3 install --upgrade pip setuptools testenv/bin/pip3 install --upgrade -r test/requirements.txt; + @for v in $$(sed -rn -e 's:.*/yadm-([0-9.]+)$$:\1:p' test/Dockerfile); do \ + git show $$v:yadm > testenv/bin/yadm-$$v; \ + chmod +x testenv/bin/yadm-$$v; \ + done @echo @echo 'To activate this test environment type:' @echo ' source testenv/bin/activate' From 32cc51c3910cd0af86ac5dddb4bd72ac0e072b98 Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 30 Dec 2020 12:28:55 +0100 Subject: [PATCH 5/6] Document version=local in make usage text --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 483ee9f..cb354cf 100644 --- a/Makefile +++ b/Makefile @@ -26,14 +26,15 @@ usage: @echo ' HEAD revision of yadm will be used unless "version" is' @echo ' specified. "version" can be set to any commit, branch, tag, etc.' @echo ' The targeted "version" will be retrieved from the repo, and' - @echo ' linked into the container as a local volume.' + @echo ' linked into the container as a local volume. Setting version to' + @echo ' "local" uses yadm from the current working tree.' @echo @echo ' make scripthost [version=VERSION]' @echo ' - Create an ephemeral container for demonstrating a bug. After' @echo ' exiting the shell, a log of the commands used to illustrate the' @echo ' problem will be written to the file "script.txt". This file can' @echo ' be useful to developers to make a repeatable test for the' - @echo ' problem.' + @echo ' problem. The version parameter works as for "testhost" above.' @echo @echo 'LINTING' @echo From 8d15eb970e7698dabd4fd052b9244d9af613cdb6 Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Wed, 30 Dec 2020 12:50:35 +0100 Subject: [PATCH 6/6] Don't pass -k to py.test when doing make test/test_foo.py As py.test then complains about "Wrong expression passed to '-k'" --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cb354cf..d07684e 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ usage: # Make it possible to run make specifying a py.test test file .PHONY: $(PYTESTS) $(PYTESTS): - @$(MAKE) test testargs="-k $@ $(testargs)" + @$(MAKE) test testargs="$@ $(testargs)" %.py: @$(MAKE) test testargs="-k $@ $(testargs)"