Skip to content

Commit

Permalink
Check unused modules for changed files only
Browse files Browse the repository at this point in the history
We always run this check for all modules in the repo, which takes around
5 minutes. However, we can just check files which are changed in the
  repo.
For that we have 3 cases:
1. Module is added or renamed
2. Last usage is removed from main.pm
3. Last usage is removed from any schedule file

With this change, we get modules from each of the group and verify if
they are used anywhere else and fail CI check in case it's not.

See [poo#64688](https://progress.opensuse.org/issues/64688).
  • Loading branch information
Rodion Iafarov committed May 25, 2020
1 parent 3ff689e commit 65786fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ perlcritic: tools/lib/

.PHONY: test-unused-modules
test-unused-modules:
tools/detect_unused_modules
tools/detect_unused_modules `git diff --name-only --diff-filter=d $$(git merge-base master HEAD) | grep '^tests/*'`
tools/detect_unused_modules `git diff --unified=0 $$(git merge-base master HEAD) products/* | grep -oP "^-.*loadtest.*[\"']\K[^\"'].+(?=[\"'])"`
tools/detect_unused_modules `git diff --unified=0 $$(git merge-base master HEAD) schedule/* | grep -oP "^-\s+- [\"']?\K.*(?=[\"']?)" | grep -v '{{'`

.PHONY: test-deleted-renamed-referenced-files
test-deleted-renamed-referenced-files:
Expand Down
6 changes: 4 additions & 2 deletions tools/detect_unused_modules
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/sh -e

for test in $(git ls-files "*tests/*.pm") ; do
MODULES="${@}"

for test in $MODULES ; do
t=$(echo $test | sed -e 's@tests/.*/@@' -e 's@\.pm$@@')
t_dir=$(echo $test | sed -e 's@tests/\(.*\)/.*$@\1@')
git grep -E "(- $t_dir/$t|loadtest.*$t|load_testdir.*$t_dir|^use (base )?\"?$t\"?)" | grep -qv ".(pm|yaml):\s*#" || echo $test
git grep -E "(- $t_dir/$t|loadtest.*$t|load_testdir.*$t_dir|^use (base )?\"?$t\"?)" | grep -qv ".(pm|yaml):\s*#" || echo "$test module is not used in any schedule"
done | \
# Whitelist

Expand Down

0 comments on commit 65786fa

Please sign in to comment.