puter icon indicating copy to clipboard operation
puter copied to clipboard

CI check for copyright notices

Open AtkinsSJ opened this issue 1 year ago • 1 comments

Make sure that files we've created contain the copyright notice in a comment at the top. This often gets forgotten with new code.

Challenges:

  • Some files we didn't write, so we shouldn't check those. (How?)
  • JS and CSS use /* */ comments around the license, so it's not an exact match to the license_header.txt file.

AtkinsSJ avatar Apr 08 '24 10:04 AtkinsSJ

I would suggest something like that

name: Check Copyright Notices

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  check-copyright:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Check Copyright Notices
      run: |
        # Exclude files and directories that we shouldn't be checked
        exclude_patterns=(
          "<place_it_here>"
          "<place_it_here>"
        )

        # We Loop through all files in the repository except excluded patterns.
        for file in $(find . -type f | grep -vE "$(IFS='|'; echo "${exclude_patterns[*]}")"); do
          # Look for css and js files
          if [[ $file == *.js || $file == *.css ]]; then
            # Check if the file contains the copyright notice wrapped in /* */
            if ! grep -qE '/\*.*Copyright \(C\) 2024 Puter Technologies Inc\..*\*/' "$file"; then
              echo "Copyright notice missing in $file"
              exit 1
            fi
          else
            # Check if the file contains the exact copyright notice from license_header.txt (for non-js/non-css files)
            if ! grep -qF "$(cat puter/doc/license_header.txt)" "$file"; then
              echo "Copyright notice missing in $file"
              exit 1
            fi
          fi
        done

        echo "Copyright notices check passed!"

MohamedElashri avatar Apr 08 '24 15:04 MohamedElashri

Any solution to this should use our license header tool (tools/license-headers), which is more capable than any license checker/updater we've been able to find elsewhere but needs to be documented.

KernelDeimos avatar Nov 07 '24 05:11 KernelDeimos