Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script to show test coverage for files that changed in the last month #535

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
185466f
wrote a script to show test coverage for files that changed in the la…
NortySpock Dec 4, 2024
45cfd97
exclude needs_attention
NortySpock Dec 8, 2024
d5016fd
update GitHub test action to additionally emit coverage report of fil…
NortySpock Dec 10, 2024
d97016f
switch from direct file write to using tee for visibility
NortySpock Dec 10, 2024
68a5c92
set fetch depth in order to get commits we can use to calculate the l…
NortySpock Dec 10, 2024
6ddc83d
maybe we needed to specify the head commit to avoid being detached
NortySpock Dec 10, 2024
70b8d62
trying to get it to fail pipeline on test failure, trying with hardco…
NortySpock Dec 10, 2024
1d1cc5a
got the test to fail early, now for success with coverage report
NortySpock Dec 10, 2024
6713dae
break the collection of test coverage information out into a separate…
NortySpock Dec 11, 2024
b35d2d5
used GitHub action syntax to get the relevant commit sha
NortySpock Dec 11, 2024
b1b800e
set test coverage to something actually achievable, returned back to …
NortySpock Dec 11, 2024
87edc4b
a GH issue claimed a git fetch cleared the issue right up :/
NortySpock Dec 11, 2024
e0b4913
Emit suggestion on where to update test coverage goal
NortySpock Dec 17, 2024
223311b
Update name of tests step to be more clear as to current state
NortySpock Dec 17, 2024
cb13f66
Add readme about scripts/show_test_coverage_for_files_changed_in_last…
NortySpock Dec 17, 2024
ff3d36e
re-added the code to generate code coverage for recent files, comment…
NortySpock Dec 17, 2024
f993779
add a bit of documentation on where to update test coverage requirements
NortySpock Dec 17, 2024
44f37e6
found an alternate way of getting a list of changed files
NortySpock Dec 18, 2024
11ca95b
slightly more explanation in the GH action file, and trying to kick t…
NortySpock Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -91,7 +91,26 @@ 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"

# Step: Execute the tests.
- name: Run tests
run: mix test --exclude needs_attention
- 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

# run git fetch --shallow-since far enough back to be confident we'll see some merge commits to the master branch
# (running off the end of a shallow commit history causes git log to believe every file has changed, somehow)
- name: git fetch more than just the most recent commit
run: git fetch --shallow-since="6 months"

- 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

- 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
2 changes: 1 addition & 1 deletion coveralls.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"coverage_options": {
"treat_no_relevant_lines_as_covered": true,
"output_dir": "cover/",
"minimum_coverage": 80
"minimum_coverage": 33
}
}

7 changes: 6 additions & 1 deletion documents/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
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`
24 changes: 24 additions & 0 deletions scripts/show_test_coverage_for_files_changed_in_last_month.sh
Original file line number Diff line number Diff line change
@@ -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
Loading