Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The folders to inspect, separated by a comma. Default `"."`.

## `ignores`

The files to ignore, separated by a comma. Default `""`.
The files to ignore, separated by a comma. Default `"__init__.py"`.

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inputs:
ignores:
description: 'Files to ignore'
required: false
default: ''
default: '__init__.py'

outputs:
issues: # id of output
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -l
set -eax

python validate_headers.py $1 $2 $3 --folders $4 --ignores $5
python /validate_headers.py $1 $2 $3 --folders $4 --ignores $5
2 changes: 1 addition & 1 deletion supported-licenses.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Apache License 2.0": "https://www.apache.org/licenses/LICENSE-2.0.txt", "Apache-2.0": {"name": "Apache License 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.txt"}, "MIT": {"name": "MIT License", "url": "https://opensource.org/licenses/MIT"}}
{"Apache License 2.0": "https://www.apache.org/licenses/LICENSE-2.0.txt", "Apache-2.0": {"name": "Apache License version 2", "url": "https://www.apache.org/licenses/LICENSE-2.0.txt"}, "MIT": {"name": "MIT License", "url": "https://opensource.org/licenses/MIT"}}
13 changes: 10 additions & 3 deletions validate_headers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Copyright (C) 2022, François-Guillaume Fernandez.

# This program is licensed under the Apache License version 2.
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.


import json
from datetime import datetime
from pathlib import Path
Expand All @@ -8,15 +14,15 @@

def main(args):

# Parse args
# Possible years
current_year = datetime.now().year
assert args.year <= current_year, f"Invalid first copyright year: {args.year}"

with open("supported-licenses.json", "rb") as f:
LICENSES = json.load(f)
license_info = LICENSES[args.license]

year_options = [f"{current_year}"] + [f"{year}-{current_year}" for year in range(args.starting_year, current_year)]
year_options = [f"{current_year}"] + [f"{year}-{current_year}" for year in range(args.year, current_year)]
copyright_notices = [[f"# Copyright (C) {year_str}, {args.owner}.\n"] for year_str in year_options]
license_notice = [
f"# This program is licensed under the {license_info['name']}.\n",
Expand Down Expand Up @@ -55,6 +61,7 @@ def main(args):

if len(invalid_files) > 0:
invalid_str = "\n- " + "\n- ".join(map(str, invalid_files))
invalid_str += "\n\nYour header should look like:\n\n" + "".join(HEADERS[-1])
raise AssertionError(f"Invalid header in the following files:{invalid_str}")


Expand All @@ -67,7 +74,7 @@ def parse_args():

parser.add_argument("license", type=str, help="identifier of the license being used")
parser.add_argument("owner", type=str, help="owner of the copyright")
parser.add_argument("starting-year", type=int, help="first copyright year of the project")
parser.add_argument("year", type=int, help="first copyright year of the project")
parser.add_argument("--folders", type=str, default=".", help="folders to inspect")
parser.add_argument("--ignores", type=str, default="", help="files to ignore")
args = parser.parse_args()
Expand Down