diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 898b4188..b44a770a 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -8,4 +8,5 @@ jobs: steps: - uses: actions/checkout@v1 - run: make lint - - run: make tests \ No newline at end of file + - run: make tests CODE_COVERAGE=1 + - run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/.gitignore b/.gitignore index 723ef36f..3c56ae0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +coverage.txt \ No newline at end of file diff --git a/Makefile b/Makefile index f09e7c3b..c6d9d631 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ DOCKER_USER= DOCKER_PASSWORD= DOCKER_REPOSITORY=thecodingmachine GOLANGCI_LINT_VERSION=1.17.1 +CODE_COVERAGE=0 MAXIMUM_WAIT_TIMEOUT=30.0 MAXIMUM_WAIT_DELAY=10.0 MAXIMUM_WEBHOOK_URL_TIMEOUT=30.0 @@ -37,8 +38,7 @@ lint: # run all tests. tests: make workspace - docker build -t $(DOCKER_REPOSITORY)/gotenberg:tests -f build/tests/Dockerfile . - docker run --rm $(DOCKER_REPOSITORY)/gotenberg:tests + ./scripts/tests.sh $(DOCKER_REPOSITORY) $(CODE_COVERAGE) # generate documentation. doc: diff --git a/build/tests/docker-entrypoint.sh b/build/tests/docker-entrypoint.sh index 6b8a3aed..ad81d21f 100755 --- a/build/tests/docker-entrypoint.sh +++ b/build/tests/docker-entrypoint.sh @@ -14,4 +14,8 @@ fi go run github.com/thecodingmachine/gotenberg/test/cmd/pm2 # Run our tests. -go test -race -cover ./... \ No newline at end of file +if [ "$CODE_COVERAGE" = "1" ]; then + go test -race -coverprofile=coverage.txt -covermode=atomic ./... +else + go test -race -cover ./... +fi \ No newline at end of file diff --git a/scripts/tests.sh b/scripts/tests.sh new file mode 100755 index 00000000..b3f0170e --- /dev/null +++ b/scripts/tests.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +DOCKER_REPOSITORY="$1" +CODE_COVERAGE="$2" + +touch "$PWD/coverage.txt" +docker build -t "$DOCKER_REPOSITORY/gotenberg:tests" -f build/tests/Dockerfile . + +if [ "$CODE_COVERAGE" = "1" ]; then + docker run --rm -e "CODE_COVERAGE=$CODE_COVERAGE" -v "$PWD/coverage.txt:/gotenberg/tests/coverage.txt" "$DOCKER_REPOSITORY/gotenberg:tests" +else + docker run --rm -e "CODE_COVERAGE=$CODE_COVERAGE" "$DOCKER_REPOSITORY/gotenberg:tests" +fi \ No newline at end of file