addlicense
addlicense copied to clipboard
Add possibility to update existing license header
This change allows to update existing license headers, eg.
// Copyright 2018 Google LLC
to
// Copyright 2018-2021 Google LLC
To enable this mode flag -u
must be set, example of use:
addlicense -c "CompanyName" -f LICENSE.tmpl -v -u ~/path_to_files/
It can be set up as commit pre-hook to change only files which are going to be commited:
.git/hooks/pre-commit
:
git diff --staged --name-only -z | xargs -0 ./addlicense -c "CompanyName" -f LICENSE.tmpl -u
Hey, thanks for the contribution!
I worry a bit about adding complexity to support a practice that (in my opinion) should probably be avoided anyway. I fully recognize that engineers at companies need to follow the guidance of their own legal departments, but it's worth noting that Google explicitly states that including the current year is optional, and at Twitter we actively discourage it (including only the earliest year in Copyright lines). It adds maintenance work because it has to be updated every year, with arguably no meaningful difference.
I'll certainly leave this open for discussion if other folks want to weight in, but I'm certainly wary of adding it to addlicense.
@willnorris as you mentioned Google states that adding the current year is optional. This feature is also optional (if you want to update the year, you have to add the flag -u
when running the program.
I see the value of adding it to the codebase, so companies using the google/addlicense
may choose if they want to have the year updated or leave the earliest one.
In our organization, we have also prepared GitHub action for our needs, which checks if the changed files contains the proper license header and if not, then update the files.
Here is the action source: https://github.com/nordcloud/addlicense/blob/master/action.yml And example of the job is:
name: Action
on:
pull_request:
branches: [ master ]
jobs:
licenses:
name: Check licenses
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- id: changed-files
uses: jitterbit/get-changed-files@v1
- uses: nordcloud/addlicense@master
with:
directory-pattern: '${{ steps.changed-files.outputs.added_modified }}'
- name: Commit changes
uses: EndBug/[email protected]
with:
message: "Update license headers"
add: '${{ steps.changed-files.outputs.added_modified }}'
I agree with @willnorris. Unless the requirement is a clear need (for the purposes of the license to be valid), we should avoid overloading the tool. It is definitely a nice to have but these changes can complicate the simplicity of the tool which is generally available and used by many. I am siding to bank this change for now and consider it if this becomes a more general practice/need.