- 
                Notifications
    
You must be signed in to change notification settings  - Fork 152
 
Add CI job to verify all Rust files have license headers #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 10 commits
      Commits
    
    
            Show all changes
          
          
            19 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      03cc1e9
              
                Add script and CI job to check license headers in Rust files
              
              
                Copilot 6bc0bb7
              
                Add license headers to files that were missing them
              
              
                Copilot 6e6760a
              
                Add just target for checking license headers
              
              
                Copilot c80eb8c
              
                Fix Label Checker test and improve license header script
              
              
                Copilot e7e7ab3
              
                Add license headers to files in src/hyperlight_guest_capi/
              
              
                Copilot 78dfcbc
              
                Add license header to idtr.rs and fix imports
              
              
                Copilot 36260d1
              
                Update README with DCO sign-off information
              
              
                Copilot b8fb4af
              
                Add documentation for DCO compliance
              
              
                Copilot d51042f
              
                Update documentation on GPG signing and DCO requirements
              
              
                Copilot 33d19fc
              
                Fix markdown linting issues in CONTRIBUTING.md and add markdownlint c…
              
              
                Copilot 3ea4801
              
                Address review feedback: update copyright year to 2025, simplify docs…
              
              
                Copilot bea43ab
              
                Remove commit signing docs and simplify references per review feedback
              
              
                Copilot e9609f8
              
                Revert GH PR workflow to use ./dev/check-license-headers.sh
              
              
                simongdavies 2baf424
              
                Update copyright year to 2025 in all remaining Rust files
              
              
                Copilot c6b3669
              
                Fix PR review issues: restore original files and update workflow
              
              
                Copilot 32bfa78
              
                Update ValidatePullRequest.yml to use script directly instead of just…
              
              
                Copilot 998bece
              
                Revert copyright year changes for files with existing license headers
              
              
                Copilot bbaf29e
              
                Merge branch 'main' into copilot/fix-502
              
              
                jsturtevant 5b2389d
              
                Merge remote-tracking branch 'upstream/main' into copilot/fix-502
              
              
                jsturtevant File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -67,6 +67,14 @@ jobs: | |
| - name: Spell Check Repo | ||
| uses: crate-ci/[email protected] | ||
| 
     | 
||
| license-headers: | ||
| name: check license headers | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Check License Headers | ||
| run: ./dev/check-license-headers.sh | ||
| 
     | 
||
| # Gate PR merges on this specific "join-job" which requires all other | ||
| # jobs to run first. We need this job since we cannot gate on particular jobs | ||
| # in the workflow, since they can sometimes be skipped (e.g. if the PR only touches docs). | ||
| 
        
          
        
         | 
    @@ -77,6 +85,7 @@ jobs: | |
| - rust | ||
| - fuzzing | ||
| - spelling | ||
| - license-headers | ||
| if: always() | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| 
          
            
          
           | 
    ||
                              
      
                  jsturtevant marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
            
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "default": true, | ||
| "MD013": false | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/bin/bash | ||
| # This script checks for the presence of the required license header in Rust source files. | ||
| 
     | 
||
| # Get the repository root | ||
| REPO_ROOT="$(git rev-parse --show-toplevel)" | ||
| cd "$REPO_ROOT" || exit 1 | ||
| 
     | 
||
| # Define the license header pattern to look for | ||
| LICENSE_PATTERN="Copyright .* The Hyperlight Authors..*Licensed under the Apache License, Version 2.0" | ||
| 
     | 
||
| # Define the full license header for files that need it | ||
| LICENSE_HEADER='/* | ||
| Copyright 2024 The Hyperlight Authors. | ||
                
      
                  jsturtevant marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| ' | ||
| 
     | 
||
| # Initialize a variable to track missing headers | ||
| MISSING_HEADERS=0 | ||
| MISSING_FILES="" | ||
| 
     | 
||
| # Find all Rust files, excluding target directory | ||
| while IFS= read -r file; do | ||
| # Skip auto-generated files | ||
| if grep -q "@generated" "$file" || grep -q "Automatically generated" "$file"; then | ||
| continue | ||
| fi | ||
| 
     | 
||
| # Check if the file has the license header (allowing for multi-line matching) | ||
| if ! grep -q -z "$LICENSE_PATTERN" "$file"; then | ||
| echo "Missing or invalid license header in $file" | ||
| MISSING_FILES="$MISSING_FILES\n $file" | ||
| MISSING_HEADERS=$((MISSING_HEADERS + 1)) | ||
| fi | ||
| done < <(find src -name "*.rs" -type f) | ||
| 
     | 
||
| if [ $MISSING_HEADERS -gt 0 ]; then | ||
| echo "Found $MISSING_HEADERS files with missing or invalid license headers:" | ||
| echo -e "$MISSING_FILES" | ||
| echo "" | ||
| echo "Please add the following license header to these files:" | ||
| echo "$LICENSE_HEADER" | ||
| echo "You can also run: just check-license-headers to verify your changes." | ||
| exit 1 | ||
| else | ||
| echo "All Rust files have the required license header" | ||
| exit 0 | ||
| fi | ||
                              
      
                  jsturtevant marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
                
      
                  jsturtevant marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
            
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # Commit Signing Requirements | ||
| 
     | 
||
| This document explains how to ensure your commits comply with both the Developer Certificate of Origin (DCO) requirements and GPG signing requirements for this project. | ||
| 
     | 
||
| ## What is the DCO? | ||
| 
     | 
||
| The Developer Certificate of Origin (DCO) is a lightweight way for contributors to certify that they wrote or otherwise have the right to submit the code they are contributing to the project. See the full text in the [CONTRIBUTING.md](../CONTRIBUTING.md#developer-certificate-of-origin-signing-your-work) file. | ||
| 
     | 
||
| ## Two Required Signature Types | ||
| 
     | 
||
| All commits to this repository must have two types of signatures: | ||
| 
     | 
||
| 1. **DCO Sign-off**: A `Signed-off-by` line in the commit message | ||
| 2. **GPG Signature**: A cryptographic signature verifying the committer's identity | ||
| 
     | 
||
| ## Adding DCO Sign-offs to Commits | ||
| 
     | 
||
| All commits must include a `Signed-off-by` line in the commit message. This line certifies that you have the right to submit your contribution under the project's license. | ||
| 
     | 
||
| ### Using the -s Flag | ||
| 
     | 
||
| The simplest way to add a sign-off to your commits is to use the `-s` flag with the `git commit` command: | ||
| 
     | 
||
| ```sh | ||
| git commit -s -m "Your commit message" | ||
| ``` | ||
| 
     | 
||
| This will automatically add a `Signed-off-by` line with your name and email to the commit message. | ||
| 
     | 
||
| ### Configuring Git for Automatic Sign-offs | ||
| 
     | 
||
| You can configure Git to automatically add sign-offs to all your commits: | ||
| 
     | 
||
| ```sh | ||
| git config --global commit.signoff true | ||
| ``` | ||
| 
     | 
||
| Alternatively, you can create a Git alias for creating signed-off commits: | ||
| 
     | 
||
| ```sh | ||
| git config --global alias.cs 'commit -s' | ||
| ``` | ||
| 
     | 
||
| Then use `git cs` instead of `git commit` to create commits with sign-offs. | ||
| 
     | 
||
| ## GPG Signing Your Commits | ||
| 
     | 
||
| In addition to DCO sign-offs, all commits must be GPG signed to verify your identity. | ||
| 
     | 
||
| ### Setting Up GPG | ||
| 
     | 
||
| 1. If you don't have a GPG key, generate one: | ||
| 
     | 
||
| ```sh | ||
| gpg --full-generate-key | ||
| ``` | ||
| 
     | 
||
| Choose RSA and RSA, 4096 bits, and an expiration date of your preference. | ||
| 
     | 
||
| 2. List your keys to get the ID: | ||
| 
     | 
||
| ```sh | ||
| gpg --list-secret-keys --keyid-format=long | ||
| ``` | ||
| 
     | 
||
| Look for the line starting with "sec" and note the key ID after the "/". | ||
| 
     | 
||
| 3. Configure Git to use your GPG key: | ||
| 
     | 
||
| ```sh | ||
| git config --global user.signingkey YOUR_KEY_ID | ||
| ``` | ||
| 
     | 
||
| Replace YOUR_KEY_ID with your actual GPG key ID. | ||
| 
     | 
||
| 4. Configure Git to sign commits automatically: | ||
| 
     | 
||
| ```sh | ||
| git config --global commit.gpgsign true | ||
| ``` | ||
| 
     | 
||
| ### Creating GPG Signed Commits | ||
| 
     | 
||
| With automatic signing enabled, normal commit commands will create signed commits. You can also explicitly sign with: | ||
| 
     | 
||
| ```sh | ||
| git commit -S -m "Your commit message" | ||
| ``` | ||
| 
     | 
||
| To create a commit with both GPG signature and DCO sign-off: | ||
| 
     | 
||
| ```sh | ||
| git commit -S -s -m "Your commit message" | ||
| ``` | ||
| 
     | 
||
| ### Adding Your GPG Key to GitHub | ||
| 
     | 
||
| 1. Export your public key: | ||
| 
     | 
||
| ```sh | ||
| gpg --armor --export YOUR_KEY_ID | ||
| ``` | ||
| 
     | 
||
| 2. Copy the output and add it to your GitHub account under Settings > SSH and GPG keys. | ||
| 
     | 
||
| ## Adding Both Signatures to Existing Commits | ||
| 
     | 
||
| If you forgot to sign your commits, you can fix them: | ||
| 
     | 
||
| ### For the Last Commit | ||
| 
     | 
||
| ```sh | ||
| git commit --amend --no-edit -S -s | ||
| ``` | ||
| 
     | 
||
| ### For Multiple Commits | ||
| 
     | 
||
| For adding both DCO sign-offs and GPG signatures to a range of commits, use interactive rebase: | ||
| 
     | 
||
| 1. Start the rebase: | ||
| 
     | 
||
| ```sh | ||
| git rebase -i HEAD~n | ||
| ``` | ||
| 
     | 
||
| Replace `n` with the number of commits you want to sign. | ||
| 
     | 
||
| 2. In the editor, change `pick` to `edit` for each commit. | ||
| 
     | 
||
| 3. For each commit that opens during the rebase: | ||
| 
     | 
||
| ```sh | ||
| git commit --amend --no-edit -S -s | ||
| git rebase --continue | ||
| ``` | ||
| 
     | 
||
| Alternatively, for adding just DCO sign-offs to multiple commits: | ||
| 
     | 
||
| ```sh | ||
| git rebase --signoff HEAD~n | ||
| ``` | ||
| 
     | 
||
| ## Verification | ||
| 
     | 
||
| The project uses automated checks to verify that all commits include both the required DCO sign-off and GPG signature. If you receive a signature verification failure notification, please follow the instructions above to add the required signatures. | ||
| 
     | 
||
| ## Troubleshooting | ||
| 
     | 
||
| ### GPG Signing Issues | ||
| 
     | 
||
| If you encounter issues with GPG signing: | ||
| 
     | 
||
| - Ensure your GPG key is properly generated and configured with Git | ||
| - Set the `GPG_TTY` environment variable: `export GPG_TTY=$(tty)` | ||
| - For Git GUI tools, you may need to configure GPG agent | ||
| - On Windows, you might need to specify the full path to gpg.exe | ||
| 
     | 
||
| ### DCO Sign-off Issues | ||
| 
     | 
||
| If you encounter issues with DCO sign-offs: | ||
| 
     | 
||
| - Ensure your Git user name and email are correctly configured | ||
| - Check that the commit author email matches your configured email | ||
| - For commits created through GitHub's web interface, you'll need to add the sign-off manually in the commit message | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.