addlicense icon indicating copy to clipboard operation
addlicense copied to clipboard

Add possibility to update existing license header

Open oskarwojciski opened this issue 4 years ago • 4 comments

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

oskarwojciski avatar Feb 17 '21 15:02 oskarwojciski

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 avatar Aug 09 '21 21:08 willnorris

@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.

oskarwojciski avatar Aug 11 '21 05:08 oskarwojciski

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 }}'

oskarwojciski avatar Aug 11 '21 08:08 oskarwojciski

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.

Shabirmean avatar Aug 29 '21 01:08 Shabirmean