Closed sloth-ontabasco closed 8 months ago
I can't make it to setup on the markdown, yaml or shell scripts comments too, especially when the bash scripts starts with the shebang i.e. #!/usr/bin/env bash
so the license header suppose to be from the second or third line, not from the very top.
Hi @sloth-ontabasco @doniz ,
Apologies for the late reply, I missed the notification.
Quoting the README:
DISCLAIMER
The tool looks for the keywords license or copyright inside the first block comment of the file to determine whether the file contains a valid license.
By default, it is configured for the / ... / format but a custom regular expression can be provided for other types using the -e option.
Go build tags (or anything that is not a block comment that could be before the license) are respected when replacing the license.
To know if a file contains a license, the tool either checks for a match to the exact content of the provided target license or looks for the license/copyright keywords in the first block comment. Things like go build tags or #!/usr/bin/env bash
are respected when replacing a license but not when adding one. When adding, it inserts at the top of the file.
For Python, there's an example in the header tests line 64 using a block comment.
Here's the regular expression:
pyRegex := regexp.MustCompile(`"""(.|[\r\n])*"""`)
And here's the example file:
"""
This file is part of the XXX distribution (https://github.com/xxxx or http://xxx.github.io).
Copyright (c) 2020 The Author.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
print('Hello, World!')
Hope this helps. It's only meant as an example and test case, but I'm not a Python developer myself and have not used it in real projects.
For C, Go, Rust, etc., the same constraints apply. The license header should be in /* */
format instead of //
for each line.
Hi @sloth-ontabasco @doniz ,
Apologies for the late reply, I missed the notification.
Quoting the README:
DISCLAIMER
The tool looks for the keywords license or copyright inside the first block comment of the file to determine whether the file contains a valid license.
By default, it is configured for the / ... / format but a custom regular expression can be provided for other types using the -e option.
Go build tags (or anything that is not a block comment that could be before the license) are respected when replacing the license.
To know if a file contains a license, the tool either checks for a match to the exact content of the provided target license or looks for the license/copyright keywords in the first block comment. Things like go build tags or
#!/usr/bin/env bash
are respected when replacing a license but not when adding one. When adding, it inserts at the top of the file.For Python, there's an example in the header tests line 64 using a block comment.
Here's the regular expression:
pyRegex := regexp.MustCompile(`"""(.|[\r\n])*"""`)
And here's the example file:
""" This file is part of the XXX distribution (https://github.com/xxxx or http://xxx.github.io). Copyright (c) 2020 The Author. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ print('Hello, World!')
Hope this helps. It's only meant as an example and test case, but I'm not a Python developer myself and have not used it in real projects.
For C, Go, Rust, etc., the same constraints apply. The license header should be in
/* */
format instead of//
for each line.
Hey! Thanks for the clarification, I didn't notice that the action only supports block comments 😅 I tried it with python docstrings like you mentioned in the example and it works perfectly fine.
Cheers!
Hey! I was wondering how one could match headers that are python comments, for example:
I have tried using the following arguments but it does not seem to work:
-e "# (.|\r\n)*"
-e "# (.|\\r\\n)*"
-e "(?m)# .*"
Is there are an issue with the regex im providing? additionally in cases where im trying to match custom regexes would the license header need to be a simple txt file with no additional formatting?