This repository was archived by the owner on Oct 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
License check workflow #152
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5f0734a
Update README.md
SuitablyMysterious 5a77cb6
Merge pull request #150 from The-CS-Nerds/documentation-1
SuitablyMysterious 87b4ee0
create a workflow to check if a PR has correct License Text
SuitablyMysterious 4141b57
Potential fix for code scanning alert no. 3: Workflow does not contai…
SuitablyMysterious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| REQUIRED_LICENSE = [ | ||
| "#", | ||
| "# This program is free software: you can redistribute it and/or modify", | ||
| "# it under the terms of the GNU Affero General Public License as published", | ||
| "# by the Free Software Foundation, either version 3 of the License, or", | ||
| "# (at your option) any later version.", | ||
| "#", | ||
| "# 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 Affero General Public License for more details.", | ||
| "#", | ||
| "# You should have received a copy of the GNU Affero General Public License", | ||
| "# along with this program. If not, see <https://www.gnu.org/licenses/>." | ||
| ] | ||
|
|
||
| SOURCE_EXTS = {".py", ".js", ".ts", ".java", ".c", ".cpp", ".go", ".rs"} | ||
|
|
||
| IGNORE_DIRS = { | ||
| "docs", | ||
| ".github" | ||
| } | ||
| IGNORE_FILES = { | ||
| "LICENSE", | ||
| "mkdocs.yml", | ||
| ".readthedocs.yml", | ||
| ".gitignore" | ||
|
|
||
| } | ||
|
|
||
| def check_file(path): | ||
| try: | ||
| with open(path, "r", encoding="utf-8") as f: | ||
| lines = [line.rstrip("\n") for line in f.readlines()] | ||
| except UnicodeDecodeError: | ||
| return True | ||
| if len(lines) < len(REQUIRED_LICENSE) + 2: | ||
| return False | ||
|
|
||
| return lines[2:2+len(REQUIRED_LICENSE)] == REQUIRED_LICENSE | ||
|
|
||
| def main(): | ||
| failed_files = [] | ||
| for file_path in Path(".").rglob("*"): | ||
| if ( | ||
| file_path.is_file() | ||
| and file_path.suffix in SOURCE_EXTS | ||
| and not any(part in IGNORE_DIRS for part in file_path.parts) | ||
| and file_path.name not in IGNORE_FILES | ||
| ): | ||
| if not check_file(file_path): | ||
| failed_files.append(str(file_path)) | ||
|
|
||
| if failed_files: | ||
| print("License header check failed for these files:") | ||
| for f in failed_files: | ||
| print(f" - {f}") | ||
| sys.exit(1) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Check License | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ main, dev, testing ] | ||
|
|
||
| jobs: | ||
| license-check: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Run license check | ||
| run: python .github/scripts/check-license.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.