Skip to content

Commit

Permalink
chore: add license header checks to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Feb 20, 2022
1 parent bf8bd16 commit fbac694
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ jobs:
with:
command: fmt
args: --all -- --check
- name: license-check
run: scripts/license_check.sh

cargo-deny:
name: cargo-deny (advisories, licenses, bans, ...)
Expand Down
20 changes: 20 additions & 0 deletions scripts/license_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# shellcheck disable=SC2044
# This script checks each file starts with a license comment
set -e
set -o pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TOPLEVEL="${DIR}/../"

# Iterate over rust files not in the target directory
for i in $(find "$TOPLEVEL" -path "$TOPLEVEL/target" -prune -o -iname "*.rs" -print)
do
CNT=$(head -n3 "$i" | grep -oEe '// (Copyright \(c\) 2022, Mysten Labs, Inc.|SPDX-License-Identifier: Apache-2.0)' | wc -l)
# echo "$i $CNT"
if [ "$CNT" -lt 2 ]
then
echo "File $i has an incorrect license header"
exit 1
fi
done

0 comments on commit fbac694

Please sign in to comment.