Skip to content

Fix license header check ignoring well known files #38

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

Merged
merged 1 commit into from
Oct 17, 2024
Merged

Conversation

FranzBusch
Copy link
Member

The previous PR tried to ignore two well known files .licenseignore and .license_header_template. However, that PR wasn't fully working and broke this check.

This PR fixes it by using a slightly different approach for those well known files.

@FranzBusch FranzBusch requested a review from a team as a code owner October 17, 2024 18:06
@FranzBusch FranzBusch force-pushed the fb-fix-license branch 2 times, most recently from c727d5a to 598d8d3 Compare October 17, 2024 18:16
@FranzBusch
Copy link
Member Author

We can also enable the license check on this repo after this change to make sure it stays green

.licenseignore Outdated
**/*.yml
CODEOWNERS
LICENSE.txt
README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these files have trailing newlines?

# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need the license header template for? It wasn’t there before

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we didn't actually check our license headers here and it appears that the Swift project and our Swift on server packages have slightly different license headers

Comment on lines +43 to 47
if [[ -f .licenseignore ]]; then
file_paths=$(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files ":(exclude).licenseignore" ":(exclude).license_header_template" )
else
file_paths=$(git ls-files ":(exclude).license_header_template" )
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second xargs confused me a little bit until I realized that it only causes git ls-files to be called a single time. Maybe worth pulling out the computation of the exclude list to make it more readable? Something along the lines of the following.

Suggested change
if [[ -f .licenseignore ]]; then
file_paths=$(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files ":(exclude).licenseignore" ":(exclude).license_header_template" )
else
file_paths=$(git ls-files ":(exclude).license_header_template" )
fi
if [[ -f .licenseignore ]]; then
exclude_list="':(exclude).licenseignore' ':(exclude).license_header_template' $($(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%")"
else
exclude_list=":(exclude).license_header_template"
fi
file_paths=$(git ls-files $exclude_list)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree though I would prefer a follow up PR to unblock the CI on other repos

The previous PR tried to ignore two well known files `.licenseignore` and `.license_header_template`. However, that PR wasn't fully working and broke this check.

This PR fixes it by using a slightly different approach for those well known files.
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting to unblock CI and let’s address https://github.com/swiftlang/github-workflows/pull/38/files#r1805237145 in a follow-up PR.

@ahoppen ahoppen merged commit 61881f8 into main Oct 17, 2024
9 checks passed
@ahoppen ahoppen deleted the fb-fix-license branch October 17, 2024 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants