From 8a4da490650cb26240245799a418050f0e72cf41 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Fri, 1 Mar 2024 19:36:10 +0200 Subject: [PATCH] Add copyright header check to CI. --- .github/copyright.sh | 23 +++++++++++++++++++++++ .github/workflows/ci.yml | 8 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 .github/copyright.sh diff --git a/.github/copyright.sh b/.github/copyright.sh new file mode 100644 index 000000000..822ad8b8b --- /dev/null +++ b/.github/copyright.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# If there are new files with headers that can't match the conditions here, +# then the files can be ignored by an additional glob argument via the -g flag. +# For example: +# -g "!src/special_file.rs" +# -g "!src/special_directory" + +# Check all the standard Rust source files +output=$(rg "^// Copyright (19|20)[\d]{2} (.+ and )?the Druid Authors( and .+)?$\n^// SPDX-License-Identifier: Apache-2\.0$\n\n" --files-without-match --multiline -g "*.rs" -g "!{druid-derive/tests/ui,docs/book_examples/src}" .) + +if [ -n "$output" ]; then + echo -e "The following files lack the correct copyright header:\n" + echo $output + echo -e "\n\nPlease add the following header:\n" + echo "// Copyright $(date +%Y) the Druid Authors" + echo "// SPDX-License-Identifier: Apache-2.0" + echo -e "\n... rest of the file ...\n" + exit 1 +fi + +echo "All files have correct copyright headers." +exit 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fab943292..273b8d4f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,14 @@ jobs: - name: cargo fmt run: cargo fmt --all --check + - name: install ripgrep + run: | + sudo apt update + sudo apt install ripgrep + + - name: check copyright headers + run: bash .github/copyright.sh + test-stable: runs-on: ${{ matrix.os }} strategy: