Detect unused dependency license metadata files #219
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
The "Check Go Dependencies" GitHub Actions workflow checks for dependencies with incompatible or unapproved license types.
The dependency license metadata consumed by the "Licensed" tool is cached in the project repository, in a dedicated file for each dependency.
The
check-cache
job of the workflow checks whether that cache is in sync with the project's current dependencies. It does this by using the "Licensed" tool to update the cache and then agit diff
command to check whether that resulted in any changes (which would indicate it is out of sync).Out of sync states could result from any of three distinct conditions:
Problem
🐛 An incorrectly configured
git diff
command previously caused the last of these to be missed.My first take at this system was simply using
git diff --exit-code
alone. That detects the last two, but misses the first. I added a precedinggit add --intent-to-add .
command to detect added files, but didn't realize that it also caused the last condition to be missed.Superfluous files in the dependency license metadata cache won't interfere with its intended functionality, but it is still important to avoid an accumulation of unused files.
Solution
The new commands will catch all three of the possible out of sync conditions by staging all changes that result from the metadata cache update to the repository and then comparing those against the
HEAD
commit.Additional Context
I considered an alternative approach which works just as well as the chosen one (explanation of the two approaches here):
However, I feel that the
git diff
command with the--cached
flag is more self-explanatory.