-
Notifications
You must be signed in to change notification settings - Fork 731
Add pre-commit hook to auto-insert Apache license headers in shell scripts (#1995) #2171
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
base: master
Are you sure you want to change the base?
Conversation
I am working on adding a pre-commit hook to insert Apache license headers in shell scripts but the insert-license hook keeps changing docker/install-sedona.sh docker/install-spark.sh and some Scala files with TODO license comments causing a commit loop. I removed TODO lines and old license parts ran the hook and fixed EOF but the problem continues with the same files failing. Please advise if there is a process I missed or if maintainer help is needed. |
You can exclude files from being checked. See the sedona/.pre-commit-config.yaml Line 82 in 3863962
|
Thanks for your suggestion about using the exclude key in .pre-commit-config.yaml I tried adding exclude patterns but insert-license hook still modifies the same files causing commit loops with TODO license comments .Is there anything else I should do to exclude these files properly and stop the repeated changes. |
Normally when you get a license TODO that means the licenses were not inserted properly for those files. |
719d4c8
to
3863962
Compare
Reopened the PR with all required updates. License headers are now correctly inserted in shell scripts without duplication. .gitignore and affected script files have been cleaned up. Thanks for the guidance John. |
88396a0
to
69c8bde
Compare
Co-authored-by: John Bampton <[email protected]>
The pre-commit workflow is failing for the insert-license hook for the shell scripts. I can see the problem and it is very subtle. Have a look at the next two example files: This first link is the correct license template and you will see in this that there are 7 lines at the top and 6 lines at the bottom and in between is the "apache url": https://github.com/apache/sedona/blob/master/.github/workflows/license-templates/LICENSE.txt So then look at: https://github.com/apache/sedona/blob/master/docker/install-sedona.sh this is one of the shell scripts that is failing with a "TODO" license. So you can see that in this file the license header has 6 lines at the top and 5 lines at the bottom between the "apache url". So the license headers are not the same. Which means to fix this issue you need to go to all the shell scripts that have failed with "TODO" licenses and remove all the TODO licenses and then try running pre-commit again and it should insert the correct license into the shell scripts. Otherwise you can manually insert the correct license template in to the shell files and then run pre-commit to make sure the new shell license hooks passes. |
Thank you for pointing out the subtle difference in the license headers. I will go through all the shell scripts showing TODO licenses and remove those headers so pre-commit can add the correct template as per LICENSE.txt. If any issues persist I will update the headers manually to match exactly. Appreciate your help! |
Yes I have read the Contributor Rules and Contributor Development Guide
Yes and the PR name follows the format [GH-1995] Add pre-commit hook to auto-insert Apache license headers in shell scripts. Closes #1995
This PR introduces a pre-commit hook configuration to automatically insert the Apache License header in all shell script files (*.sh). It includes:
Addition of the shell license insertion hook in .pre-commit-config.yaml utilizing the existing Lucas-C/pre-commit-hooks insert-license hook.
Removal of inconsistent license headers and TODO license comments from current shell scripts.
Adjustment to insert the license header immediately after the shebang line to maintain script correctness.
Verification that the license header does not duplicate on multiple runs.
Updates to various shell scripts to comply with the licensing standard.
Locally ran pre-commit run insert-license --all-files ensuring no duplicate headers and correct placement.
Manual verification of header insertion after shebang in affected shell script files.
Verified all other pre-commit hooks pass successfully.
Committed and pushed the changes to the feature branch allowing GitHub Actions to validate build and tests.
No this PR does not affect any public API so no need to change the documentation.