Skip to content
Snippets Groups Projects
Commit 73f2a7ab authored by Johan Grönqvist's avatar Johan Grönqvist
Browse files

Add makefile rule to run tests on docker

parent 1900a251
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,8 @@ SANITIZED_TESTS = $(shell echo $(TESTS) | sed 's/[ .]/_/g') ...@@ -12,8 +12,8 @@ SANITIZED_TESTS = $(shell echo $(TESTS) | sed 's/[ .]/_/g')
# Define container name # Define container name
CONTAINER_NAME = $(CONTAINER_NAME_PREFIX)$(COMMIT)_$(SANITIZED_TESTS) CONTAINER_NAME = $(CONTAINER_NAME_PREFIX)$(COMMIT)_$(SANITIZED_TESTS)
.PHONY: run_tests .PHONY: run_tests_podman
run_tests: run_tests_podman:
@if [ -z "$(TESTS)" ]; then \ @if [ -z "$(TESTS)" ]; then \
echo "Error: TESTS must be specified."; \ echo "Error: TESTS must be specified."; \
exit 1; \ exit 1; \
...@@ -54,10 +54,46 @@ run_tests: ...@@ -54,10 +54,46 @@ run_tests:
podman stop $(CONTAINER_NAME); \ podman stop $(CONTAINER_NAME); \
podman rm $(CONTAINER_NAME) podman rm $(CONTAINER_NAME)
.PHONY: run_tests_docker
run_tests_docker:
@if [ -z "$(TESTS)" ]; then \
echo "Error: TESTS must be specified."; \
exit 1; \
fi
@if [ -z "$(COMMIT)" ]; then \
echo "Error: COMMIT must be specified."; \
exit 1; \
fi
@echo "Starting a new container for commit $(COMMIT)..."
docker run --user johan -d --name $(CONTAINER_NAME) \
$(IMAGE) /bin/sh -c "sleep infinity"
docker cp $(HOME)/.ssh/known_hosts $(CONTAINER_NAME):/home/johan/.ssh/known_hosts
docker exec --user johan $(CONTAINER_NAME) git clone $(REPO_URL) /home/johan/tmp/repo
docker exec --user johan $(CONTAINER_NAME) bash -c "cd /home/johan/tmp/repo/ && git checkout $(COMMIT)"
for test in $(TESTS); do \
echo "Running test $$test..."; \
docker exec --user johan $(CONTAINER_NAME) bash -c "cd /home/johan/tmp/repo/examples && nice -19 ionice -c 3 $(JULIA_BIN) $$test"; \
if [ $$? -ne 0 ]; then \
echo "Test $$test failed."; \
echo "Set git tag with commands"; \
echo "git tag -f test_failed_$$test $(COMMIT)"; \
docker stop $(CONTAINER_NAME); \
docker rm $(CONTAINER_NAME); \
exit 1; \
fi; \
done;
echo "All tests $(TESTS) passed for commit $(COMMIT)."; \
echo "Set git tags with commands"; \
for test in $(TESTS); do \
echo "git tag -f test_passed_$$test $(COMMIT)"; \
done; \
docker stop $(CONTAINER_NAME); \
docker rm $(CONTAINER_NAME)
# Clean target to remove old test containers if needed # Clean target to remove old test containers if needed
.PHONY: clean .PHONY: clean
clean: clean:
@podman ps -a --filter "name=$(CONTAINER_NAME_PREFIX)*" -q | xargs podman rm -f @podman ps -a --filter "name=$(CONTAINER_NAME_PREFIX)*" -q | xargs -r podman rm -f
@docker ps -a --filter "name=$(CONTAINER_NAME_PREFIX)*" -q | xargs -r docker rm -f
@echo "Cleaned up old test containers." @echo "Cleaned up old test containers."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment