From 6542bb38db27375e0da85462c4ca250d2394bea1 Mon Sep 17 00:00:00 2001 From: Teemu Kuusisto Date: Tue, 8 Sep 2026 10:14:58 +0000 Subject: [PATCH] chore(license): enforce licence headers on PowerShell files install.ps1 shipped without the MIT/copyright header that every other source file in the repo carries, because the header check never looked at PowerShell files at all: `licenserc.toml` did not include them. The same was true of PSScriptAnalyzerSettings.psd1 and of the WSL helper script under .github/scripts, which also had no header. Adding the globs alone is not enough. hawkeye has no built-in comment style for the `ps1`, `psm1` or `psd1` extensions, so a file matched by `includes` but with no matching rule is classified `unsupported` and silently skipped while the command still exits 0 -- the check would look green without inspecting the file. The explicit `[[rules]]` block mapping those extensions to the `script` comment style is what makes the files actually get checked. Only `hawkeye check --fail-on-unknown` exposes the gap, and neither the CI job nor the hook passes it. PowerShell files get an ASCII `Copyright (c)` header, rendered from a conditional in the header template, instead of the copyright sign the other file types use. A file with any non-ASCII byte needs a byte order mark to satisfy PSScriptAnalyzer, and install.ps1 cannot have one: the documented install path is `irm ... | iex`, which hands the parser a string, so the mark survives into it and the param() block stops being the script's first statement, silently dropping every installer parameter. Keeping the headers ASCII leaves install.ps1 as ASCII-only as its existing comment says and needs no analyzer suppression. The other PowerShell files follow for consistency, and LICENSE.TXT already uses the `(c)` form. Headers for every other file type render byte-for-byte as before. The license-headers hook already runs on every commit (it has no file-type filter), so no hook change is needed: a PowerShell-only edit reaches it. PSScriptAnalyzerSettings.psd1's comments named scripts that do not exist; they now describe what the lint covers (every tracked .ps1) and note that .psm1 and .psd1 are licence-checked but not linted. Signed-off-by: Teemu Kuusisto --- .github/scripts/Invoke-WslBash.ps1 | 4 ++++ PSScriptAnalyzerSettings.psd1 | 20 +++++++++++++++----- install.ps1 | 4 ++++ licenserc.toml | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/scripts/Invoke-WslBash.ps1 b/.github/scripts/Invoke-WslBash.ps1 index 8770126675..fa07f64cc3 100644 --- a/.github/scripts/Invoke-WslBash.ps1 +++ b/.github/scripts/Invoke-WslBash.ps1 @@ -1,3 +1,7 @@ +# Copyright (c) Advanced Micro Devices, Inc., or its affiliates. +# +# SPDX-License-Identifier: MIT + # Runs a bash script inside the pinned WSL guest. # # Piping script text to `wsl.exe` from Windows PowerShell 5.1 is unreliable: diff --git a/PSScriptAnalyzerSettings.psd1 b/PSScriptAnalyzerSettings.psd1 index cf70d8e8b4..d4f6cda1aa 100644 --- a/PSScriptAnalyzerSettings.psd1 +++ b/PSScriptAnalyzerSettings.psd1 @@ -1,11 +1,21 @@ -# PSScriptAnalyzer configuration for the repo's PowerShell scripts -# (install.ps1, scripts/*.ps1). Used by the prek hook and CI. +# Copyright (c) Advanced Micro Devices, Inc., or its affiliates. +# +# SPDX-License-Identifier: MIT + +# PSScriptAnalyzer configuration for the repo's PowerShell scripts: every tracked +# .ps1 file, as listed by `git ls-files '*.ps1'` in xtask/src/powershell.rs +# (today install.ps1 and .github/scripts/Invoke-WslBash.ps1). Used by the prek +# hook and CI. +# +# Only .ps1 files are linted. The licence-header check (licenserc.toml) also +# covers .psm1 and .psd1, so a module or data file added later gets a header but +# no analyzer pass until the xtask and the hook's `files:` pattern are extended. @{ # Enforce the full default rule set at Warning and Error severity. Severity = @('Error', 'Warning') - # install.ps1 and the acceptance/packaging scripts are user-facing console - # programs where `Write-Host` is the intended way to print progress to the - # terminal, so the "avoid Write-Host" rule does not apply here. + # install.ps1 is a user-facing console program where `Write-Host` is the + # intended way to print progress to the terminal, so the "avoid Write-Host" + # rule does not apply here. ExcludeRules = @('PSAvoidUsingWriteHost') } diff --git a/install.ps1 b/install.ps1 index 33c391f91f..c1c9da0c91 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,3 +1,7 @@ +# Copyright (c) Advanced Micro Devices, Inc., or its affiliates. +# +# SPDX-License-Identifier: MIT + param( [Parameter(Position = 0)] [string] $Channel = $env:ROCM_CLI_CHANNEL, diff --git a/licenserc.toml b/licenserc.toml index 93d2bbd258..76b94d760c 100644 --- a/licenserc.toml +++ b/licenserc.toml @@ -8,9 +8,17 @@ ## folder is vendored verbatim into the amd/skills catalog, whose skills carry ## no headers. The licence is stated in the skill's own skill-card.md instead. +## The header text is a template rendered per file. PowerShell files get an ASCII +## `(c)` instead of the copyright sign: a file with any non-ASCII byte needs a +## BOM, and install.ps1 cannot have one because a BOM breaks `irm ... | iex`. The +## other PowerShell files follow so the whole family reads the same. [header] text = """ +{% if attrs.filename is endingwith(".ps1") or attrs.filename is endingwith(".psm1") or attrs.filename is endingwith(".psd1") -%} +Copyright (c) Advanced Micro Devices, Inc., or its affiliates. +{%- else -%} Copyright © Advanced Micro Devices, Inc., or its affiliates. +{%- endif %} SPDX-License-Identifier: MIT """ @@ -21,6 +29,9 @@ includes = [ "**/*.py", "**/*.sh", "**/*.md", + "**/*.ps1", + "**/*.psm1", + "**/*.psd1", ] excludes = [ @@ -35,3 +46,12 @@ excludes = [ [[rules]] extensions = ["md"] style_out = "xml" + +## hawkeye has no built-in comment syntax for PowerShell: without this rule a +## .ps1/.psm1/.psd1 file is reported `unsupported` and silently skipped (exit 0), +## so `includes` alone would not enforce anything. Only `hawkeye check +## --fail-on-unknown` turns that into a failure, and neither the CI job nor the +## prek hook passes the flag. +[[rules]] +extensions = ["ps1", "psm1", "psd1"] +style_out = "script"