From 12d9ffe8846f5bc75a286276a71e17b0db363c4d Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Tue, 7 Jan 2025 15:37:08 +0100 Subject: [PATCH] Add github workflow for license header check. --- .github/workflows/linting.yml | 7 +++++++ check_license_header.sh | 0 check_license_headers.sh | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) mode change 100755 => 100644 check_license_header.sh create mode 100755 check_license_headers.sh diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index e882f604a..4e8675e98 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -41,3 +41,10 @@ jobs: - uses: actions/checkout@v4 - run: cargo install cargo-audit - run: cargo audit + License-Headers: + runs-on: ubuntu-latest + steps: + - name: Check out openvas-scanner + uses: actions/checkout@v4 + - name: Check license headers + run: bash ./check_license_headers.sh diff --git a/check_license_header.sh b/check_license_header.sh old mode 100755 new mode 100644 diff --git a/check_license_headers.sh b/check_license_headers.sh new file mode 100755 index 000000000..aa2c73297 --- /dev/null +++ b/check_license_headers.sh @@ -0,0 +1,18 @@ +any_missing_headers=0 + +for folder in src misc rust/src; do + echo "Checking $folder" + for f in $(find $folder -regex ".*\.\(rs\|c\|h\)"); do + header=$(head -n 3 "$f") + if ! [[ "$header" =~ SPDX ]]; then + echo "File does not contain license header: $f" + any_missing_headers=1 + + if [[ "$1" == add_header ]]; then + echo -e "// SPDX-FileCopyrightText: 2025 Greenbone AG\n //\n// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception\n\n$(cat $f)" > $f + fi + fi + done +done + +exit $any_missing_headers