Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions scripts/add-spdx-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ if [ "$YEAR" != "2024" ]; then
COPYRIGHT="Copyright (C) 2024-$YEAR Breakdown RS Contributors"
fi

# Find supported source files recursively. Covers the Rust backend and the
# frontend-flutter tree (Dart, Gherkin .feature, YAML).
# Find supported source files recursively. Covers the Rust backend, the
# frontend-flutter tree (Dart, Gherkin .feature, YAML) and Markdown docs
# (AGENTS.md, pi-rules instruction files, ADRs, issue notes).
find "${1:-.}" -type f \
\( -name "*.rs" -o -name "*.typ" -o -name "*.sh" \
-o -name "*.dart" -o -name "*.feature" \
-o -name "*.yaml" -o -name "*.yml" \) | while read -r file; do
-o -name "*.yaml" -o -name "*.yml" \
-o -name "*.md" \) | while read -r file; do
# Check if header already exists
if grep -q "SPDX-License-Identifier" "$file"; then
echo "⏭️ Skipping (already has header): $file"
Expand All @@ -45,6 +47,32 @@ find "${1:-.}" -type f \
echo "" >> "$temp_file"
cat "$file" >> "$temp_file"
;;
*.md)
# Markdown: HTML comments. Files may start with YAML frontmatter
# (e.g. pi-rules .github/instructions rule files); the header MUST
# go after the closing "---" delimiter, or downstream tools would
# parse the frontmatter as plain body text (a rule file would lose
# its glob frontmatter and stop matching entirely).
frontmatter_end=0
if [ "$(head -n 1 "$file")" = "---" ]; then
frontmatter_end=$(awk 'NR > 1 && $0 == "---" { print NR; exit }' "$file")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
frontmatter_end=${frontmatter_end:-0}
fi
if [ "$frontmatter_end" -gt 0 ]; then
head -n "$frontmatter_end" "$file" > "$temp_file"
echo "" >> "$temp_file"
else
: > "$temp_file"
fi
echo "<!-- SPDX-License-Identifier: $LICENSE -->" >> "$temp_file"
echo "<!-- $COPYRIGHT -->" >> "$temp_file"
echo "" >> "$temp_file"
if [ "$frontmatter_end" -gt 0 ]; then
tail -n +$((frontmatter_end + 1)) "$file" >> "$temp_file"
else
cat "$file" >> "$temp_file"
fi
;;
*)
echo "⚠️ Unsupported file type: $file"
continue
Expand Down