-
Notifications
You must be signed in to change notification settings - Fork 5
Copyright notice and whitespace check #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
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,36 @@ | ||
| name: check copyright | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '.github/workflows/check-copyright.yml' | ||
| - '.pre-commit-config.yaml' | ||
| - 'scripts/check_copyright_notice.py' | ||
| - '**/*.go' | ||
| - '!**/docs/**/*' | ||
| - '!**/*.md' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| copyright: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Checkout devtools | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
|
||
| - name: Check copyright notice | ||
| run: | | ||
| pip install \ | ||
| pre-commit \ | ||
| comment-parser>=1.2.3 | ||
| pre-commit run --all-files |
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 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 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 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 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,19 @@ | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v4.5.0 | ||
| hooks: | ||
| - id: end-of-file-fixer | ||
| name: Fix end of files | ||
| description: Ensures files end with a newline | ||
| - id: trailing-whitespace | ||
| name: Check for trailing whitespace | ||
| description: Fails and fix files with trailing whitespace | ||
|
|
||
| - repo: local | ||
| hooks: | ||
| - id: check-copyright-notice | ||
| name: Check for copyright notice | ||
| description: Ensures source files include a copyright notice | ||
| entry: python3 scripts/check_copyright_notice.py | ||
| language: system | ||
| types: [go] |
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 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 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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # Security | ||
| # Security | ||
|
|
||
| For reporting security issues, please follow the official guidelines outlined in [SECURITY.md](https://github.com/Open-CMSIS-Pack/cmsis-toolbox/blob/main/SECURITY.md). |
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 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,83 @@ | ||
| # ------------------------------------------------------- | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright Contributors to the vidx2pidx project. | ||
| # ------------------------------------------------------- | ||
|
|
||
| """ | ||
| Checks the presence of copyright notice in the files | ||
| """ | ||
|
|
||
| from typing import Optional, Sequence | ||
| import argparse | ||
| import os | ||
| import sys | ||
| import magic | ||
| from comment_parser import comment_parser | ||
|
|
||
| COPYRIGHT_TEXT = "Copyright Contributors to the vidx2pidx project." | ||
| LICENSE_TEXT = "SPDX-License-Identifier: Apache-2.0" | ||
|
|
||
| def check_file(filename: str) -> int: | ||
| """ | ||
| Checks a file for the presence of fixed copyright and license notices. | ||
| Args: | ||
| filename: The name of the file to check. | ||
| Returns: | ||
| 0 if both copyright and license are found, 1 otherwise. | ||
| """ | ||
| if os.path.getsize(filename) == 0: | ||
| return 0 | ||
|
|
||
| try: | ||
| mime_type = magic.from_file(filename, mime=True) | ||
| except Exception as e: | ||
| print(f"# Error reading MIME type of {filename}: {e}") | ||
| return 1 | ||
|
|
||
| if mime_type == "text/plain": | ||
| mime_type = "text/x-c++" | ||
|
|
||
| try: | ||
| comments = "\n".join(comment.text() for comment in comment_parser.extract_comments(filename, mime=mime_type)) | ||
| except Exception as e: | ||
| print(f"# Failed to parse comments in {filename}: {e}") | ||
| return 1 | ||
|
|
||
| copyright_found = COPYRIGHT_TEXT in comments | ||
| license_found = LICENSE_TEXT in comments | ||
|
|
||
| if copyright_found and license_found: | ||
| return 0 | ||
|
|
||
| print(f"# Copyright check error(s) in: {filename}") | ||
| if not copyright_found: | ||
| print(f"\t# Missing or invalid copyright. Expected: {COPYRIGHT_TEXT}") | ||
| if not license_found: | ||
| print(f"\t# Missing or invalid license. Expected: {LICENSE_TEXT}") | ||
| return 1 | ||
|
|
||
| def main(argv: Optional[Sequence[str]] = None) -> int: | ||
| """ | ||
| Entry point to check for copyright notices in the provided files. | ||
| Args: | ||
| argv: A list of filenames. | ||
| Returns: | ||
| Non-zero if any file is missing the required notice. | ||
| """ | ||
| parser = argparse.ArgumentParser(description="Check for fixed copyright and license headers.") | ||
| parser.add_argument('filenames', nargs='*', help='Files to check.') | ||
| args = parser.parse_args(argv) | ||
|
|
||
| print("Checking copyright headers...") | ||
| ret = 0 | ||
|
|
||
| for filename in args.filenames: | ||
| ret |= check_file(filename) | ||
|
|
||
| if ret != 0: | ||
| print(">> error: One or more files are missing a valid copyright or license header") | ||
|
|
||
| return ret | ||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(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
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
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.