Skip to content

Commit a5eac1f

Browse files
Copilotsimongdavies
andcommitted
Add script and CI job to check license headers in Rust files
Co-authored-by: simongdavies <[email protected]>
1 parent 386a843 commit a5eac1f

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

.github/workflows/ValidatePullRequest.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ jobs:
6767
- name: Spell Check Repo
6868
uses: crate-ci/[email protected]
6969

70+
license-headers:
71+
name: check license headers
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v4
75+
- name: Check License Headers
76+
run: ./dev/check-license-headers.sh
77+
7078
# Gate PR merges on this specific "join-job" which requires all other
7179
# jobs to run first. We need this job since we cannot gate on particular jobs
7280
# in the workflow, since they can sometimes be skipped (e.g. if the PR only touches docs).
@@ -77,6 +85,7 @@ jobs:
7785
- rust
7886
- fuzzing
7987
- spelling
88+
- license-headers
8089
if: always()
8190
runs-on: ubuntu-latest
8291
steps:

dev/check-license-headers.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# This script checks for the presence of the required license header in Rust source files.
3+
4+
# Get the repository root
5+
REPO_ROOT="$(git rev-parse --show-toplevel)"
6+
cd "$REPO_ROOT" || exit 1
7+
8+
# Define the license header pattern to look for
9+
LICENSE_PATTERN="Copyright .* The Hyperlight Authors..*Licensed under the Apache License, Version 2.0"
10+
11+
# Initialize a variable to track missing headers
12+
MISSING_HEADERS=0
13+
MISSING_FILES=""
14+
15+
# Find all Rust files, excluding target directory
16+
while IFS= read -r file; do
17+
# Skip auto-generated files
18+
if grep -q "@generated" "$file" || grep -q "Automatically generated" "$file"; then
19+
continue
20+
fi
21+
22+
# Check if the file has the license header (allowing for multi-line matching)
23+
if ! grep -q -z "$LICENSE_PATTERN" "$file"; then
24+
echo "Missing or invalid license header in $file"
25+
MISSING_FILES="$MISSING_FILES\n $file"
26+
MISSING_HEADERS=$((MISSING_HEADERS + 1))
27+
fi
28+
done < <(find src -name "*.rs" -type f)
29+
30+
if [ $MISSING_HEADERS -gt 0 ]; then
31+
echo "Found $MISSING_HEADERS files with missing or invalid license headers:"
32+
echo -e "$MISSING_FILES"
33+
exit 1
34+
else
35+
echo "All Rust files have the required license header"
36+
exit 0
37+
fi

src/hyperlight_host/src/func/utils.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
/// An utility macro to execute a macro for each tuple of parameters
218
/// up to 32 parameters. This is useful to implement traits on functions
319
/// for may parameter tuples.

src/hyperlight_host/src/hypervisor/crashdump.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
use std::io::Write;
218

319
use tempfile::NamedTempFile;

0 commit comments

Comments
 (0)