diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cd595b31a..efeb70138 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,7 +3,7 @@ # separate terms of service, privacy policy, and support # documentation. -name: Build and test +name: Build, test, and report coverage of recent files on: push: @@ -55,6 +55,8 @@ jobs: # Step: Check out the code. - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 # Step: Define how to cache deps. Restores existing cache if present. - name: Cache deps @@ -91,7 +93,21 @@ jobs: # the cached version. - name: Install dependencies run: mix compile + + - name: create cover folder if not exists, to cache coverage reporting results + run: mkdir -p ./cover/ + + - name: emit hint on where to update minimum test coverage + run: echo "to update minimum test coverage requirements, edit coveralls.json" + + - name: Run tests, failing loudly on error, emitting coverage to file for use when reporting test coverage in later proposed step + run: set -eo pipefail; mix test --exclude needs_attention --cover | tee ./cover/test_coverage_by_file.txt + + - name: generate list of files changed in the last month + run: git --no-pager log --name-only --oneline --since='1 month ago' | tee ./cover/files_changed_in_last_month.txt + + - name: echo coverage header to the files_changed_in_last_month file to assist in reporting + run: echo "LINES RELEVANT MISSED" | tee -a ./cover/files_changed_in_last_month.txt - # Step: Execute the tests. - - name: Run tests - run: mix test --exclude needs_attention + - name: use grep to create test coverage report only on recently changed files, sorted by coverage percent + run: grep -F -f ./cover/files_changed_in_last_month.txt ./cover/test_coverage_by_file.txt | grep -A999 "LINES RELEVANT MISSED" | sort -g \ No newline at end of file diff --git a/coveralls.json b/coveralls.json index 30417ea34..f9a0ab8fa 100644 --- a/coveralls.json +++ b/coveralls.json @@ -21,7 +21,7 @@ "coverage_options": { "treat_no_relevant_lines_as_covered": true, "output_dir": "cover/", - "minimum_coverage": 80 + "minimum_coverage": 33 } } diff --git a/documents/guides/testing.md b/documents/guides/testing.md index 5b675d1da..94ef337bb 100644 --- a/documents/guides/testing.md +++ b/documents/guides/testing.md @@ -59,4 +59,9 @@ the full launch.json should look like that: } ``` -Then you can press the mix (Default task) button or F5 to start debugging. **It may take a while to start** \ No newline at end of file +Then you can press the mix (Default task) button or F5 to start debugging. **It may take a while to start** + +## Review test coverage of recently changed files +To get a quick list of recently changed files and their test coverage, run `scripts/show_test_coverage_for_files_changed_in_last_month.sh` + +To update minimum test coverage requirements, edit `coveralls.json` \ No newline at end of file diff --git a/scripts/show_test_coverage_for_files_changed_in_last_month.sh b/scripts/show_test_coverage_for_files_changed_in_last_month.sh new file mode 100755 index 000000000..87d957ae8 --- /dev/null +++ b/scripts/show_test_coverage_for_files_changed_in_last_month.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +##### +# Generates a rough report of files changed in the last month, and their test coverage +# +# This report could help people who like writing tests find recently changed regions of code that need tests. +# +# usage: From the root directory of the repository, run this script +# e.g: $ ./scripts/show_test_coverage_for_files_changed_in_last_month.sh +##### + +#make cover directory if it does not exist, so we can place output in a folder excluded by .gitignore +mkdir -p ./cover/ + +git diff HEAD '@{last month}' --name-only > ./cover/files_changed_in_last_month.txt + +# append an additional search string that aligns with the coverage header +# so the header is also emitted and highlighted +echo "LINES RELEVANT MISSED" >> ./cover/files_changed_in_last_month.txt + +mix test --exclude needs_attention --cover > ./cover/test_coverage_by_file.txt + +#grep matches the two files and emits only test coverage information about recently changed files, sorted by coverage percent +grep -F -f ./cover/files_changed_in_last_month.txt ./cover/test_coverage_by_file.txt | grep -A999 "LINES RELEVANT MISSED" | sort -g