From fbac6946ab9f8db6829b67fbc0d79182a785b80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 20 Feb 2022 11:48:27 -0500 Subject: [PATCH] chore: add license header checks to CI --- .github/workflows/rust.yml | 2 ++ scripts/license_check.sh | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 scripts/license_check.sh diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2ec97f00ee3dd..cbfe5ebea2e54 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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, ...) diff --git a/scripts/license_check.sh b/scripts/license_check.sh new file mode 100755 index 0000000000000..d70348aae8ffc --- /dev/null +++ b/scripts/license_check.sh @@ -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