forked from rukamori/ArchiveTune
-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (96 loc) · 3.7 KB
/
Copy pathheader.yml
File metadata and controls
123 lines (96 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Kotlin Header
on: workflow_dispatch
jobs:
kotlin-header:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: Install addlicense
run: go install github.com/google/addlicense@latest
- name: Write Kotlin header banner
run: |
YEAR=$(date +%Y)
cat > banner.txt <<EOF
ArchiveTune ($YEAR)
© Rukamori — github.com/rukamori
GPL-3.0 License | Contributors: see git history
Do not remove or alter this notice. - Per GPL-3.0 Section 4 & Section 5
EOF
- name: Find duplicate Kotlin headers
run: |
python3 <<'PY'
from pathlib import Path
marker = "GPL-3.0 License | Contributors: see git history"
duplicates = []
for path in Path(".").rglob("*.kt"):
if ".git" in path.parts or "build" in path.parts:
continue
count = path.read_text(encoding="utf-8").count(marker)
if count > 1:
duplicates.append((path, count))
if duplicates:
print("Duplicate Kotlin headers found:")
for path, count in duplicates:
print(f"{path}: {count}")
else:
print("No duplicate Kotlin headers found.")
PY
- name: Remove existing Kotlin headers
run: |
python3 <<'PY'
from pathlib import Path
archive_marker = "ArchiveTune ("
license_marker = "GPL-3.0 License | Contributors: see git history"
total_removed = 0
for path in Path(".").rglob("*.kt"):
if ".git" in path.parts or "build" in path.parts:
continue
text = path.read_text(encoding="utf-8")
removed = 0
while text.startswith("/*"):
end = text.find("*/")
if end == -1:
break
header = text[:end + 2]
if archive_marker not in header or license_marker not in header:
break
text = text[end + 2:].lstrip("\r\n")
removed += 1
if removed:
path.write_text(text, encoding="utf-8")
total_removed += removed
print(f"{path}: removed {removed} existing header(s)")
print(f"Removed {total_removed} existing Kotlin header(s).")
PY
- name: Add current Kotlin header
run: |
find . -path "./.git" -prune -o -path "*/build" -prune -o -type f -name "*.kt" -print0 | xargs -0 -r "$(go env GOPATH)/bin/addlicense" -v -f banner.txt
rm banner.txt
- name: Verify Kotlin headers are unique
run: |
python3 <<'PY'
from pathlib import Path
import sys
marker = "GPL-3.0 License | Contributors: see git history"
duplicates = []
for path in Path(".").rglob("*.kt"):
if ".git" in path.parts or "build" in path.parts:
continue
count = path.read_text(encoding="utf-8").count(marker)
if count > 1:
duplicates.append((path, count))
if duplicates:
print("Duplicate Kotlin headers remain:")
for path, count in duplicates:
print(f"{path}: {count}")
sys.exit(1)
print("Every Kotlin file has at most one ArchiveTune header.")
PY
- uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Kotlin Header