From 2a674093a8d24fe026d27e12367c0b736c8ca348 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 10:42:41 -0400 Subject: [PATCH 1/8] Add swift version files as exclusions to the license header checks --- .github/workflows/scripts/check-license-header.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index 845eb25..cdc1223 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -47,6 +47,8 @@ else exclude_list=":(exclude).license_header_template" fi +exclude_list="${exclude_list}:(exclude).swift-version" # Swift version files will never have license headers in them + file_paths=$(echo "$exclude_list" | xargs git ls-files) while IFS= read -r file_path; do From 4a5d4f9a6fb020ba29afff891f6e54d0ec79bf8b Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 12:30:32 -0400 Subject: [PATCH 2/8] Split out static, and dynamic exclude lists --- .../workflows/scripts/check-license-header.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index cdc1223..0ee65df 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -39,17 +39,20 @@ fi paths_with_missing_license=( ) +static_exclude_list=( ) +static_exclude_list+=( '":(exclude).license_header_template"' ) +static_exclude_list+=( '":(exclude).swift-version"' ) # Swift version files do not have comments nor licenses in them +dynamic_exclude_list=( ) + if [[ -f .licenseignore ]]; then - static_exclude_list='":(exclude).licenseignore" ":(exclude).license_header_template" ' - dynamic_exclude_list=$(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%" ') - exclude_list=$static_exclude_list$dynamic_exclude_list -else - exclude_list=":(exclude).license_header_template" + static_exclude_list+=( '":(exclude).licenseignore"' ) + IFS=$'\n' read -d '' -r -a dynamic_exclude_list <<< $(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore) fi -exclude_list="${exclude_list}:(exclude).swift-version" # Swift version files will never have license headers in them +exclude_list=( "${static_exclude_list[@]}" "${dynamic_exclude_list[@]}" ) +excludes=$(IFS=" " ; echo "${exclude_list[*]}") -file_paths=$(echo "$exclude_list" | xargs git ls-files) +file_paths=$(echo "$excludes" | xargs git ls-files) while IFS= read -r file_path; do file_basename=$(basename -- "${file_path}") From d0152225c94f272e6dbc3f70c5953161f653520d Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 12:32:50 -0400 Subject: [PATCH 3/8] Fix shellcheck error --- .github/workflows/scripts/check-license-header.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index 0ee65df..49f9e2f 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -46,7 +46,7 @@ dynamic_exclude_list=( ) if [[ -f .licenseignore ]]; then static_exclude_list+=( '":(exclude).licenseignore"' ) - IFS=$'\n' read -d '' -r -a dynamic_exclude_list <<< $(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore) + IFS=$'\n' read -d '' -r -a dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" fi exclude_list=( "${static_exclude_list[@]}" "${dynamic_exclude_list[@]}" ) From f2a0835ba6bff662fbac0c4c16165d1670747419 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 14:32:42 -0400 Subject: [PATCH 4/8] Fix read error --- .github/workflows/scripts/check-license-header.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index 49f9e2f..de9f55f 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -46,7 +46,7 @@ dynamic_exclude_list=( ) if [[ -f .licenseignore ]]; then static_exclude_list+=( '":(exclude).licenseignore"' ) - IFS=$'\n' read -d '' -r -a dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" + IFS=$'\n' read -r -a dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" fi exclude_list=( "${static_exclude_list[@]}" "${dynamic_exclude_list[@]}" ) From 0f91dd03868187634110fe22a523f2c53f5c3c2c Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 15:34:23 -0400 Subject: [PATCH 5/8] Use readarray for more reliable mechanism of reading output of sed into an array --- .github/workflows/scripts/check-license-header.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index de9f55f..31e3437 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -46,7 +46,7 @@ dynamic_exclude_list=( ) if [[ -f .licenseignore ]]; then static_exclude_list+=( '":(exclude).licenseignore"' ) - IFS=$'\n' read -r -a dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" + readarray -t dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" fi exclude_list=( "${static_exclude_list[@]}" "${dynamic_exclude_list[@]}" ) From a16a471fe29fe9211dfb71405d4f124518231f40 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 16:08:03 -0400 Subject: [PATCH 6/8] Add a test case for missing licenses --- .github/workflows/scripts/check-license-header.sh | 2 +- tests/no-license.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/no-license.yml diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index 31e3437..ecfd824 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -46,7 +46,7 @@ dynamic_exclude_list=( ) if [[ -f .licenseignore ]]; then static_exclude_list+=( '":(exclude).licenseignore"' ) - readarray -t dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" + #readarray -t dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" fi exclude_list=( "${static_exclude_list[@]}" "${dynamic_exclude_list[@]}" ) diff --git a/tests/no-license.yml b/tests/no-license.yml new file mode 100644 index 0000000..2fbf472 --- /dev/null +++ b/tests/no-license.yml @@ -0,0 +1,2 @@ +# Look, no license +{} From 2a500bf7094d54ed5f35718994b4c26a12434e31 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Wed, 14 May 2025 16:14:41 -0400 Subject: [PATCH 7/8] Revise the missing license test case --- .licenseignore | 1 + tests/no-license.java | 1 + tests/no-license.yml | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 tests/no-license.java delete mode 100644 tests/no-license.yml diff --git a/.licenseignore b/.licenseignore index a37bae2..2c73ea8 100644 --- a/.licenseignore +++ b/.licenseignore @@ -1,5 +1,6 @@ .github/workflows/configs/.flake8 **/*.yml +**/*.java CODEOWNERS LICENSE.txt README.md diff --git a/tests/no-license.java b/tests/no-license.java new file mode 100644 index 0000000..b33b285 --- /dev/null +++ b/tests/no-license.java @@ -0,0 +1 @@ +// Look, no license diff --git a/tests/no-license.yml b/tests/no-license.yml deleted file mode 100644 index 2fbf472..0000000 --- a/tests/no-license.yml +++ /dev/null @@ -1,2 +0,0 @@ -# Look, no license -{} From c3a4e26eb1ba63ad91e2af7daacdb35a0bf7b975 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Thu, 15 May 2025 11:48:37 -0400 Subject: [PATCH 8/8] Update to code so that the test now passes --- .github/workflows/scripts/check-license-header.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/check-license-header.sh b/.github/workflows/scripts/check-license-header.sh index ecfd824..31e3437 100755 --- a/.github/workflows/scripts/check-license-header.sh +++ b/.github/workflows/scripts/check-license-header.sh @@ -46,7 +46,7 @@ dynamic_exclude_list=( ) if [[ -f .licenseignore ]]; then static_exclude_list+=( '":(exclude).licenseignore"' ) - #readarray -t dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" + readarray -t dynamic_exclude_list <<< "$(sed -E 's/^(.*)$/":(exclude)\1"/' <.licenseignore)" fi exclude_list=( "${static_exclude_list[@]}" "${dynamic_exclude_list[@]}" )