Skip to content

chore: never modify the COPYRIGHT template and guard .github templates#1032

Closed
mc-nv wants to merge 16 commits into
mainfrom
mchornyi/TRI-1100/github-align-hooks-and-templates
Closed

chore: never modify the COPYRIGHT template and guard .github templates#1032
mc-nv wants to merge 16 commits into
mainfrom
mchornyi/TRI-1100/github-align-hooks-and-templates

Conversation

@mc-nv

@mc-nv mc-nv commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

What does the PR do?

Aligns this repository's self-contained copyright hook with NVIDIA's copyright/license header guidance. model_analyzer keeps its own SPDX implementation (Apache-2.0) and does not adopt the centralized developer_tools hooks:

  • tools/add_copyright.py computes the header's copyright year in memory instead of rewriting the tools/COPYRIGHT template file on every run — hooks never modify license/copyright source files.
  • The add-copyright hook excludes .github/ so GitHub issue/PR templates keep their YAML frontmatter first.
  • Pre-commit CI runs only on files modified by the PR (mirroring the other triton-inference-server repos) — a full --all-files run bumps every stale copyright year and fails any PR at year rollover.
  • Adopts the org-wide GitHub defaults: PR templates inherited from triton-inference-server/.github (local copies removed) and the conventional-pr caller stub (@v1.4.3) — title validation, multi-label from commit types, org-wide label colors, cherry-pick detection.
  • Workflow files use this repo's Apache SPDX header convention (the BSD long-form headers on conventional-pr.yml, codeql.yml, and python-package.yaml are converted), and the add-copyright exclude is narrowed to template paths so .github/workflows/ is under header enforcement.

Pros / Cons

Pros

  • Hook runs no longer produce surprise diffs on tools/COPYRIGHT at year rollover; newly-inserted headers always carry the current year.
  • .github/ templates are protected from header injection that would break their frontmatter.

Cons / risks

  • None identified — inserted header text is unchanged; only the side effect on the template file is removed.

Related Issues / PRs

  • Resolves: TRI-1100

Related PRs:

Test plan

  • pre-commit validate-config passes.
  • Running the hook on a new file inserts the standard two-line SPDX Apache-2.0 header with the current year while tools/COPYRIGHT stays byte-identical (verified via md5).

Caveats

  • None.

Align the self-contained copyright hook with NVIDIA Legal header
guidance: compute the header's copyright year in memory instead of
rewriting tools/COPYRIGHT on every run, and exclude .github/ so
GitHub issue/PR templates keep their YAML frontmatter first.

TRI-1100
@mc-nv mc-nv self-assigned this Jul 18, 2026
A full --all-files run bumps the copyright year of every file with a
stale year, failing CI for any PR at year rollover. Check only the
files the PR modifies, mirroring the other triton-inference-server
repositories.

TRI-1100
This was referenced Jul 18, 2026
@mc-nv
mc-nv marked this pull request as ready for review July 18, 2026 02:05
@mc-nv
mc-nv requested review from Vinya567, mudit-eng and nv-rinig July 18, 2026 02:20
mc-nv added 2 commits July 20, 2026 14:48
PR templates are inherited from triton-inference-server/.github instead
of local copies; add the caller stub for the org-wide conventional-pr
reusable workflow (PR title validation + type labeling).

TRI-1100
Org-wide label color scheme and cherry-pick detection.

TRI-1100
@github-actions github-actions Bot added the chore Maintenance work, no production code change (chore: PRs) label Jul 20, 2026
mc-nv added 3 commits July 20, 2026 15:30
Human-readable type labels with enforced descriptions and colors.

TRI-1100
@github-actions github-actions Bot added the CI/CD Continuous integration and workflow changes (ci: PRs) label Jul 20, 2026
mc-nv added 4 commits July 21, 2026 08:17
The add-license hook now fails when the LICENSE copyright year is
stale.

TRI-1100
Workflow files are license-processed again (only templates excluded);
refresh the stale copyright year this repo's pre-commit workflow
carried.

TRI-1100
…dd-copyright exclude

The conventional-pr stub carried a BSD long-form header - the wrong
license assertion in this Apache-2.0 repository - and codeql.yml /
python-package.yaml had the same pre-existing issue. Convert all three
to the repo's SPDX Apache two-line convention (start years preserved as
ranges). Narrow the add-copyright exclude to template paths only so
.github/workflows is under header enforcement.

TRI-1100
Grant issues:write to the labeling job (review feedback).

TRI-1100
@mc-nv
mc-nv requested a review from pskiran1 July 22, 2026 15:12
@Vinya567

Copy link
Copy Markdown

@greptileai

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors the copyright tooling and CI so that pre-commit hooks never produce surprise diffs on the tools/COPYRIGHT template file and GitHub issue/PR templates are shielded from header injection. It also consolidates the workflow license headers from BSD long-form to the two-line Apache SPDX convention used by the rest of the repo.

  • get_license() now computes the copyright header in memory (always with the current year) instead of first mutating tools/COPYRIGHT; the regex substitution is correct and behaviorally identical to the old single-year path.
  • The add-copyright hook gains an exclude for .github/ISSUE_TEMPLATE/ and .github/PULL_REQUEST_TEMPLATE paths, and pre-commit.yml switches to a git diff HEAD^1 HEAD approach (with fetch-depth: 2) that runs hooks only on PR-modified files.
  • conventional-pr.yml is a new thin-caller workflow that routes same-repo PRs through pull_request and fork PRs through pull_request_target with a mutually-exclusive if guard and appropriately scoped write permissions.

Confidence Score: 5/5

Safe to merge — the changes are confined to CI tooling, copyright header plumbing, and license-text normalization; no application logic is affected.

The core change — computing the copyright header in memory instead of rewriting the template file — is a clean, well-scoped refactor. The regex substitution in get_license() behaves identically to the old disallow_range=True path. The workflow changes (targeted pre-commit diff, caching, header normalization, new conventional-pr caller) are all standard patterns and the pull_request_target guard correctly prevents double-triggering and limits permissions to PR/issue writes.

No files require special attention. The new conventional-pr.yml delegates to an external reusable workflow (@v1.4.3); reviewers may want to confirm that tag is immutable in the org .github repo, consistent with the comment in the file.

Important Files Changed

Filename Overview
tools/add_copyright.py Replaces file-mutating update_and_get_license() with in-memory get_license(); COPYRIGHT template is no longer modified on each run. Logic for year substitution is correct — single current year is always used for new headers, and existing headers are updated via the existing update_copyright_year path.
.github/workflows/pre-commit.yml Replaces pre-commit/action with a manual pip install + git diff approach targeting only PR-modified files (HEAD^1..HEAD via fetch-depth: 2). Adds pre-commit cache and minimal contents: read permission. The approach is correct for GitHub Actions merge-commit checkout semantics.
.pre-commit-config.yaml Adds exclude pattern for .github/ template paths to the add-copyright hook, preventing header injection that would break YAML frontmatter. Copyright year bumped to 2026.
.github/workflows/conventional-pr.yml New thin-caller workflow using pull_request for same-repo PRs and pull_request_target for forks (with the mutually-exclusive if guard). Delegates to org-wide reusable workflow pinned at v1.4.3 with appropriately scoped permissions.
.github/workflows/codeql.yml License header converted from 27-line BSD long-form to 2-line Apache SPDX. No logic changes.
.github/workflows/python-package.yaml License header converted from BSD long-form to Apache SPDX. No logic changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[PR opened / pushed] --> B{pull_request event}
    B --> C[actions/checkout\nfetch-depth: 2]
    C --> D[actions/cache\n~/.cache/pre-commit]
    D --> E[pip install pre-commit]
    E --> F[git diff --name-only -z\n--diff-filter=d HEAD^1 HEAD]
    F --> G{Any modified\nnon-deleted files?}
    G -- No files --> H[xargs --no-run-if-empty\nskips — exit 0]
    G -- Files listed --> I[pre-commit run --files\non changed paths only]
    I --> J[add-copyright hook]
    J --> K{File in exclude\npattern?}
    K -- Yes --> L[Skip — no header injection]
    K -- No --> M[get_license in memory\ncurrent year only]
    M --> N{File has\ncopyright already?}
    N -- Yes --> O[update_copyright_year\nin file]
    N -- No --> P[Insert header\nwith current year]
    O --> Q[COPYRIGHT template\nunchanged]
    P --> Q
Loading

Reviews (3): Last reviewed commit: "ci: keep this repo's Apache SPDX header ..." | Re-trigger Greptile

Comment thread .github/workflows/pre-commit.yml Outdated
Comment thread .pre-commit-config.yaml Outdated
mc-nv added 2 commits July 22, 2026 11:31
- conventional-pr stub: dual pull_request/pull_request_target triggers
  so fork PRs from external contributors get labeled too (the reusable
  workflow never checks out PR code); explicit contents:read; pinned
  v1.4.3.
- pre-commit workflow: robust modified-files runner (null-delimited
  paths, deletion-only PRs handled, deleted paths filtered, no
  undocumented -r flag, cache keyed on config hash).
- flake8 args quoted correctly (the flow-scalar form split at commas
  and silently reduced the select list).
- hooks pinned to .github v1.4.3.

TRI-1100
The fleet stub refresh reintroduced the BSD long-form header; this
repository's convention is the two-line SPDX Apache header and its
add-copyright hook enforces it.

TRI-1100
@mc-nv

mc-nv commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing: the team is moving away from centralized org-level configuration in favor of per-repository self-contained setups (see triton-inference-server/server#8897 for the first decentralized implementation). Branch retained for reference. TRI-1100

@mc-nv mc-nv closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance work, no production code change (chore: PRs) CI/CD Continuous integration and workflow changes (ci: PRs)

Development

Successfully merging this pull request may close these issues.

2 participants