-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
[skip changelog] Automate license headers checks in CI #2177
[skip changelog] Automate license headers checks in CI #2177
Conversation
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## master #2177 +/- ##
=======================================
Coverage 62.83% 62.83%
=======================================
Files 220 220
Lines 19477 19477
=======================================
Hits 12239 12239
Misses 6150 6150
Partials 1088 1088
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
1b8105f
to
b7ce834
Compare
I tried to change the license in Can this be changed to detect also if a license is not the correct one? |
9720ca1
to
1401806
Compare
.github/workflows/check-go-task.yml
Outdated
); do | ||
# We read only the license header, removing all the comments symbols and changing the date to be 2000. This will | ||
# help us understand if the other part of the license are exactly the same as the template. | ||
HEADER=$(head -n$N_LINES $file | sed -r 's| [0-9]{4} | 2000 |' | sed 's|// ||; s|^//||' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must keep the year range 2020-2023
. I did some research and found that:
- the starting year must be kept to indicate when the copyright started (otherwise any previous work may not be considered under copyright)
- the ending year must be kept to indicate when the copyright expires (it happens after the last year + some decades actually...)
- we cannot use
2020-present
... - old headers should be updated every time a file is touched (for example if a file made in 2020 is modified in 2023 then the ending year in the header must be updated with
2020-2023
)
At this point, maybe the simplest solution is to just put the year range in the template file and update the template + all source files every year?
.github/workflows/check-go-task.yml
Outdated
if [ "$LICENSE" != "$HEADER" ]; then | ||
STATUS=1 | ||
echo "$file" | ||
fi | ||
done | ||
exit $STATUS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this check because it just tells you that a file is wrong but didn't tell you what's wrong, and we don't have any way to re-run it locally. Also running task go:add-license-headers
won't fix the wrong file.
Ideally, the action should just run task go:add-license-header
and check if there are changes with git diff
.
(more or less the same as the check for protoc files https://github.com/arduino/arduino-cli/blob/master/.github/workflows/check-protobuf-task.yml#L130).
In other words task go:add-license-header
should write the files as they should be before pushing the PR.
b65d97c
to
86ad5e5
Compare
Ideally, we'd like to have a tool that can recognize and fix unwanted changes in the license header without being only limited to checking the presence of a license header. We tried to implement something quick with bash, but it's more tricky than expected. For example, do we need to provide a date range for our license headers? Or it's okay to keep the year when the file was created? In case we have to opt for a year range, should we always put 2020-CURRENT_YEAR? We agreed that the most common mistake is to forget to add the license for a newly created file. Without overcomplicating this, the |
86ad5e5
to
cf53299
Compare
Please check if the PR fulfills these requirements
See how to contribute
before creating one)
our contributing guidelines
UPGRADING.md
has been updated with a migration guide (for breaking changes)configuration.schema.json
updated if new parameters are added.What kind of change does this PR introduce?
This adds a new CI check for new go files missing the license headers.
We have to put in the root of the folder a template called:
license_header.tpl
. This file will be used byaddlicense
to add any missing license header in the go file.What is the current behavior?
If we create a new go file and forget to add a license header we can spot it only by a manual CR which might be error-prone if the PR is large.
What is the new behavior?
Every time a new golang file is pushed with a missing license header the CI will fail and warn the user.
Does this PR introduce a breaking change, and is titled accordingly?
Other information
Any suggestion are welcomed