-
Notifications
You must be signed in to change notification settings - Fork 3
58 lines (53 loc) · 1.92 KB
/
Copy pathlicense-headers.yml
File metadata and controls
58 lines (53 loc) · 1.92 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
name: License headers
on:
pull_request:
paths:
- "backend/**/*.py"
- "frontend/src/**/*.ts"
- "frontend/src/**/*.vue"
- "multiplayer/src/**/*.ts"
- "shared/**/*.ts"
- ".github/workflows/license-headers.yml"
permissions:
contents: read
jobs:
check-headers:
name: Apache-2.0 header on new source files
runs-on: ubuntu-latest
timeout-minutes: 3
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Find new / changed source files
id: changed
run: |
set -euo pipefail
# Source files only; skip generated/vendored trees.
mapfile -t files < <(git diff --name-only --diff-filter=AM "$BASE_SHA" "$HEAD_SHA" \
| grep -E '^(backend/.*\.py|frontend/src/.*\.(ts|vue)|multiplayer/src/.*\.ts|shared/.*\.ts)$' \
| grep -v -E '(__pycache__|node_modules|dist|build|alembic/versions)' \
|| true)
printf '%s\n' "${files[@]}" > changed_files.txt
echo "count=${#files[@]}" >> "$GITHUB_OUTPUT"
- name: Verify Apache 2.0 header
if: steps.changed.outputs.count != '0'
run: |
set -euo pipefail
missing=0
while IFS= read -r f; do
[ -z "$f" ] && continue
if ! head -n 15 "$f" | grep -q "Licensed under the Apache License, Version 2.0"; then
echo "::error file=$f::missing Apache 2.0 license header"
missing=$((missing + 1))
fi
done < changed_files.txt
if [ "$missing" -gt 0 ]; then
echo ""
echo "Files missing the Apache 2.0 header: $missing"
echo "Add the header from an existing file (e.g. backend/app/main.py) to the top of each new source file."
exit 1
fi