Skip to content

Commit

Permalink
feat(ci): Add publishing of test results
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbrueckri committed Sep 26, 2024
1 parent 784cd7a commit 57d5672
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make

- name: Run tests
run: make

- name: Debug
run: ls -la .test_results/

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
./test-results/*.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.test_results
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
# ref.: https://forums.docker.com/t/how-to-turn-off-the-whats-new-message/140860
export DOCKER_CLI_HINTS = false

# Docker image name
# Image name
IMAGE_NAME=dotfiles-test

# Container name
CONTAINER_NAME=dotfiles-test

# Path to the tests in the container
TEST_PATH=/home/testuser/.tests/
TESTRESULT_PATH=/home/testuser/.test_results/

################################################################################
# Targets
Expand All @@ -34,19 +38,22 @@ build:
.PHONY: test
test: build
@echo "Running tests..."
@docker run -i --rm $(IMAGE_NAME) bash -c "bats -x --print-output-on-failure $(TEST_PATH)"
@mkdir -p `pwd`/.test_results
@docker run --name $(CONTAINER_NAME) -i -v `pwd`/.test_results:$(TESTRESULT_PATH) --rm $(IMAGE_NAME) bash -c "bats --formatter junit $(TEST_PATH) | tee $(TESTRESULT_PATH)/unit-test-result.xml"

# Run all tests
# Run all tests and open shell in container for debugging
.PHONY: test
test-debug: build
@echo "Running tests..."
@docker run -it --rm $(IMAGE_NAME) bash -c "bats -x -p -T --print-output-on-failure $(TEST_PATH); bash"
@docker run --name $(CONTAINER_NAME) -it --rm $(IMAGE_NAME) bash -c "bats -x -p -T --print-output-on-failure $(TEST_PATH); bash"

# Remove the Docker image
.PHONY: clean
clean:
@echo "Cleaning up..."
@docker rmi $(IMAGE_NAME)
@rm -r `pwd`/.test_results
@docker rm -fv $(CONTAINER_NAME)
@docker rmi -f $(IMAGE_NAME)

# Open shell in the build image
.PHONY: shell
Expand Down

0 comments on commit 57d5672

Please sign in to comment.