Skip to content

Add workflow to verify copyright headers in changed code#26201

Closed
Copilot wants to merge 8 commits into
masterfrom
copilot/add-copyright-verification-workflow
Closed

Add workflow to verify copyright headers in changed code#26201
Copilot wants to merge 8 commits into
masterfrom
copilot/add-copyright-verification-workflow

Conversation

Copilot AI commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds an automated GitHub Actions workflow that verifies all changed source code files include the proper Microsoft copyright header. The workflow runs on Linux and uses PowerShell for verification.

Changes

New Copyright Verification Script (tools/verifyCopyright.ps1)

  • Checks changed files for the required Microsoft copyright header
  • Supports file types specified in CONTRIBUTING.md:
    • C-style comments (//) for C# files (.cs)
    • Hash comments (#) for PowerShell files (.ps1, .psm1, .psd1)
  • Automatically detects changed files using GitHub API with fallback to git diff
  • Excludes files that don't require copyright (Markdown, JSON, test data, etc.)
  • Provides clear, actionable error messages with examples of proper headers

New GitHub Actions Workflow (.github/workflows/verify-copyright.yml)

  • Triggers on pull requests to master, release, and feature branches
  • Runs on Linux (ubuntu-latest)
  • Uses .github/actions/infrastructure/path-filters action to detect changed files
  • Uses PowerShell script for verification
  • Only checks file types mentioned in CONTRIBUTING.md (.cs, .ps1, .psm1, .psd1)
  • Integrates with PR checks to prevent merging files without proper copyright

Documentation Updates (.github/CONTRIBUTING.md)

  • Added information about the automatic copyright verification check
  • Updated "Work in Progress" section to recommend using draft PRs with WIP prefix as an additional option

Testing

The verification script has been thoroughly tested with:

  • Files containing proper copyright headers ✅
  • Files missing copyright headers ✅
  • Mixed scenarios with both types ✅
  • Correct file types (C#, PowerShell) ✅
  • Unsupported file types are properly skipped ✅

Example Usage

When a PR is submitted with files missing copyright headers, the workflow will fail and display:

✗ src/NewFile.cs - Missing copyright header

The following files are missing copyright headers:
  - src/NewFile.cs

Please add the appropriate copyright header to the beginning of each file:

For C# files (.cs):
  // Copyright (c) Microsoft Corporation.
  // Licensed under the MIT License.

For PowerShell files (.ps1, .psm1, .psd1):
  # Copyright (c) Microsoft Corporation.
  # Licensed under the MIT License.

See .github/CONTRIBUTING.md for more details.

Contributors can also run the script locally:

./tools/verifyCopyright.ps1 -ChangedFiles @('src/test.cs', 'tools/test.ps1')

Fixes the requirement to verify copyright headers on all changed code in pull requests.

Original prompt

Add a workflow to verify that all changed code adds the copyright, running on linux, verified using powershell and/or githubscript


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 6 commits October 15, 2025 20:04
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
…idelines.md changes

Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Copilot AI changed the title [WIP] Add workflow to verify copyright in changed code Add workflow to verify copyright headers in changed code Oct 15, 2025
Copilot AI requested a review from TravisEz13 October 15, 2025 20:14
@xtqqczze

xtqqczze commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

https://github.com/dotnet/runtime doesn't use a copyright header for.yaml files, they are pure configuration or data with minimal creative input.

@TravisEz13

Copy link
Copy Markdown
Member

@copilot

  1. update the powershell script to only check the file types mentioned in the contributing guide
  2. only use the powershell script, don't check twice
  3. use something like .github\actions\infrastructure\path-filters\action.yml to only check the files that have changed

…psm1, .psd1; remove duplicate GitHub Script check; use path-filters action

Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>

Copilot AI commented Oct 15, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

  1. update the powershell script to only check the file types mentioned in the contributing guide
    ...

Done in commit 8c8f8f4. Changes made:

  1. Updated PowerShell script to only check .cs, .ps1, .psm1, and .psd1 files (the file types mentioned in CONTRIBUTING.md)
  2. Removed the duplicate GitHub Script verification step - now only using PowerShell
  3. Updated workflow to use .github/actions/infrastructure/path-filters action for detecting changed files

The workflow now triggers only on changes to the four supported file types and uses the path-filters action you referenced.

@xtqqczze

xtqqczze commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

The copyright header string is already defined in .editorconfig file_header_template. This could be used with the dotnet format cli tool with IDE0073: The file header is missing or not located at the top of the file analyzer rule.

@TravisEz13

Copy link
Copy Markdown
Member

The copyright header string is already defined in .editorconfig file_header_template. This could be used with the dotnet format cli tool with IDE0073: The file header is missing or not located at the top of the file analyzer rule.

@xtqqczze Do you want to submit a PR? I was mostly just trying to see if GitHub Copilot agent could handle this.

@xtqqczze

xtqqczze commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

I don't think the current approach will work, we have to account for files like:

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/

@xtqqczze

xtqqczze commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

@xtqqczze Do you want to submit a PR? I was mostly just trying to see if GitHub Copilot agent could handle this.

I think we might need to fix other dotnet format issues first, e.g. #25959.

@xtqqczze

Copy link
Copy Markdown
Contributor

@xtqqczze Do you want to submit a PR? I was mostly just trying to see if GitHub Copilot agent could handle this.

I think we might need to fix other dotnet format issues first, e.g. #25959.

Actually we can use something like: dotnet format analyzers --diagnostics IDE0073 --verify-no-changes

@xtqqczze

Copy link
Copy Markdown
Contributor

However, dotnet format does not format files that aren’t included in a project or solution. I know we have files that are not compiled.

@TravisEz13

Copy link
Copy Markdown
Member

I don't think the current approach will work, we have to account for files like:

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/

We don't have to mark this as a required workflow. We can mark it as informational, and the intent is for it to only run on changed filed.

@TravisEz13

Copy link
Copy Markdown
Member

I don't think the current approach will work, we have to account for files like:

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/

We don't have to mark this as a required workflow. We can mark it as informational and the intent is for it to only run on changed filed.

@xtqqczze Do you want to submit a PR? I was mostly just trying to see if GitHub Copilot agent could handle this.

I think we might need to fix other dotnet format issues first, e.g. #25959.

Actually we can use something like: dotnet format analyzers --diagnostics IDE0073 --verify-no-changes

That PR is too broad and unlikely to get merged. Look at the code owners file and split it into chunks that a single maintainer can approve. Feel free to start with my areas.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Oct 19, 2025
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment.

@jshigetomi jshigetomi deleted the copilot/add-copyright-verification-workflow branch April 21, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants