Skip to content

Script/action to update the year in license files

License

Notifications You must be signed in to change notification settings

p3lim/license-year-updater

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License year updater

This script will parse license file(s) passed to it and update the years.

Example 1 - updating the end year:

-Copyright (c) 1998-2019 John Doe <[email protected]>
+Copyright (c) 1998-2020 John Doe <[email protected]>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

Example 2 - adding the end year:

-Copyright (c) 2019 John Doe <[email protected]>
+Copyright (c) 2019-2020 John Doe <[email protected]>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

Example 3 - multiple copyright holders:

-Copyright (c) 2015-2018 John Doe <[email protected]>
-Copyright (c) 2017-2018 Philip J. Fry <[email protected]>
+Copyright (c) 2015-2020 John Doe <[email protected]>
+Copyright (c) 2017-2020 Philip J. Fry <[email protected]>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

Usage

$ python3 update.py --help
usage: update.py [OPTION]

Updates license file(s) to the current year.

options:
  -h,--help             show this help message and exit
  -f,--files FILES      multiline string of file paths
  -e,--exclude EXCLUDE  multiline string of words in author to exclude
  -r,--no-range         only keep last year instead of range of years

Files

To pass it multiple files use update.py -f 'file1.txt\nfile2.txt'.

Exclude option

The exclude option lets you select not to update the year for words matching certain authors.

Given this example:

Copyright (c) 2015-2018 John Doe <[email protected]>
Copyright (c) 2017-2018 Philip J. Fry <[email protected]>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

You want to update the year for all authors, except "John Doe".
Invoke the script excluding parts of the author: update.py -f license.txt -e '[email protected]'

The result would be:

Copyright (c) 2015-2018 John Doe <[email protected]>
-Copyright (c) 2017-2018 Philip J. Fry <[email protected]>
+Copyright (c) 2017-2023 Philip J. Fry <[email protected]>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

You can be as verbose as you want, targeting domains (-e 'example.com') or names (-e john).
To pass multiple filters separate them by newline: -e 'john\nalice'

GitHub Action

This is an example workflow that will do the following:

  • check out the project
  • use this script as an action, passing it a license file
  • create a pull request

This will occur on January 1st every year at 03:00.

name: Update copyright year in license file

on:
  schedule:
    - cron: '0 3 1 1 *'

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - name: Clone project
        uses: actions/checkout@v4

      - name: Update license year
        uses: p3lim/license-year-updater@v2
        with:
          files: |
            license1.txt
            license2.txt

      - name: Create pull request
        uses: peter-evans/create-pull-request@v6
        with:
          title: Update license
          commit-message: Update license
          branch: update-license
          delete-branch: true

If you don't want to wait for Jan 1st every year and would like to run this action immediately, you can manually trigger it with workflow_dispatch in your workflow:

on:
  workflow_dispatch:

With this you can trigger the workflow manually from the workflow page, see this blog post for more information.

See action.yml for more options.