name: Add SPDX headers on: workflow_dispatch: permissions: contents: write pull-requests: write jobs: spdx-headers: runs-on: ubuntu-latest steps: - name: Check out repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Add missing SPDX headers env: PROJECT: "Cinny Project" CR_YEAR: "2021-present" CR_HOLDER: "Ajay Bura" SPDX_LICENSE: "AGPL-3.0-only" LINK: "https://cinny.in" TEXT: | Please see LICENSE file in root of repository for full details. run: | python3 <<'PY' import os import subprocess from pathlib import Path project = os.environ["PROJECT"] year = os.environ["CR_YEAR"] holder = os.environ["CR_HOLDER"] license_id = os.environ["SPDX_LICENSE"] link = os.environ["LINK"] license_text = os.environ["TEXT"] excluded_prefixes = ( ".github/", "node_modules/", "dist/", "build/", ) def make_header(): return ( "/*\n" f"{project}\n" f"Copyright {year} {holder}\n" f"SPDX-License-Identifier: {license_id}\n" f"{link}\n" "\n" f"{license_text}" "*/\n" "\n" ) files = subprocess.check_output( ["git", "ls-files"], text=True ).splitlines() for filename in files: path = Path(filename) if not path.is_file(): continue if filename.startswith(excluded_prefixes): continue if path.parent == Path("."): continue if path.suffix.lower() not in {".ts", ".tsx", ".css"}: continue text = path.read_text(encoding="utf-8") # Skip files that already have a header. first_lines = "\n".join(text.splitlines()[:20]) if "SPDX-License-Identifier:" in first_lines: continue if "Copyright" in first_lines: continue updated = make_header() + text path.write_text(updated, encoding="utf-8") print(f"Updated {filename}") PY - name: Create pull request uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 with: token: ${{ secrets.GITHUB_TOKEN }} commit-message: "chore: add SPDX headers" branch: automation/spdx-headers delete-branch: true title: "chore: add SPDX headers" body: | This automated pull request adds missing SPDX license headers. labels: github_actions