HeyPuter / puter

🌐 The Internet OS! Free, Open-Source, and Self-Hostable.
https://puter.com
GNU Affero General Public License v3.0
26.52k stars 1.75k forks source link

CI check for copyright notices #248

Open AtkinsSJ opened 7 months ago

AtkinsSJ commented 7 months ago

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:

MohamedElashri commented 7 months ago

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!"
KernelDeimos commented 1 week ago

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.