Skip to content

Commit dcb630b

Browse files
committed
ci: auto-insert Apache license headers via Lucas-C/insert-license
Add Lucas-C/pre-commit-hooks insert-license to .pre-commit-config.yaml covering every file type that's actually present in the repo: .py .yml/.yaml .toml .sh .ezt Dockerfile/*.Dockerfile .md Hooks share a single license template (scripts/license-templates/LICENSE.txt) and the canonical wrapped '#'-comment style ('#|#|#') used by the majority of existing files. Markdown uses '<!--| |-->' to match the existing 2-space-indented HTML-comment style. Exclusions are scoped narrowly: * approved_patterns.yml — auto-generated from actions.yml. * stash/* (except stash/pyproject.toml) — uses the short-form 'Copyright (c) The stash contributors / Licensed under Apache 2.0' style which RAT accepts. * .github/workflows/stash-action-test.yml — same short-form. * AGENTS.md / CLAUDE.md — agentic-tooling docs that follow the short-license convention used in apache/airflow. Drive-by normalisation across files outside stash/: * 17 files had unwrapped headers ('# Licensed' on line 1, no surrounding '#' lines) — wrapped to the canonical style so the hook is a no-op on subsequent runs. * pelican/plugins/spu.py and pelican/plugin_paths.py had legacy near-identical license blocks (slightly different wrap, https vs http URL) — replaced with the canonical block; the duplicate that insert-license added on first run was removed manually. Motivation: PR #770 shipped a new file (lock_file_exemptions.yml) without an ASF license header, which the rat check correctly caught but only after the PR was opened and reviewed. Running this hook locally would have flagged it before push.
1 parent c3d4987 commit dcb630b

20 files changed

Lines changed: 157 additions & 15 deletions

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -15,6 +16,7 @@
1516
# specific language governing permissions and limitations
1617
# under the License.
1718
#
19+
#
1820
---
1921
name: "CodeQL"
2022

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -15,6 +16,7 @@
1516
# specific language governing permissions and limitations
1617
# under the License.
1718
#
19+
#
1820
---
1921
name: Pre-commit Checks
2022

.github/workflows/pytest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -15,6 +16,7 @@
1516
# specific language governing permissions and limitations
1617
# under the License.
1718
#
19+
#
1820
name: pytest
1921

2022
on:

.github/workflows/rat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -15,6 +16,7 @@
1516
# specific language governing permissions and limitations
1617
# under the License.
1718
#
19+
#
1820
name: rat
1921

2022
on:

.pre-commit-config.yaml

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -14,6 +15,7 @@
1415
# KIND, either express or implied. See the License for the
1516
# specific language governing permissions and limitations
1617
# under the License.
18+
#
1719
---
1820
default_stages: [pre-commit]
1921
default_language_version:
@@ -28,4 +30,93 @@ repos:
2830
language: python
2931
additional_dependencies: ['rich>=12.4.4', 'ruamel.yaml']
3032
require_serial: true
31-
files: ^actions\.yml$
33+
files: ^actions\.yml$
34+
- repo: https://github.com/Lucas-C/pre-commit-hooks
35+
rev: v1.5.6
36+
hooks:
37+
# Files in stash/ (except stash/pyproject.toml) carry the short-form
38+
# Apache 2.0 license ("Copyright (c) The stash contributors / Licensed
39+
# under the Apache License, Version 2.0") which RAT accepts. Adding the
40+
# full ASF contributor header on top would just duplicate, so they are
41+
# excluded across every ecosystem-specific hook below.
42+
- id: insert-license
43+
name: Add Apache license header to Python files
44+
files: \.py$
45+
exclude: ^stash/(?!pyproject\.toml).*$
46+
args:
47+
- --comment-style
48+
- "#|#|#"
49+
- --license-filepath
50+
- license-templates/LICENSE.txt
51+
- --fuzzy-match-generates-todo
52+
- id: insert-license
53+
name: Add Apache license header to YAML files
54+
files: \.ya?ml$
55+
# approved_patterns.yml is regenerated from actions.yml by gateway/.
56+
# stash-action-test.yml uses the short-form Apache 2.0 license to
57+
# match the rest of the stash sub-project.
58+
exclude: |
59+
(?x)
60+
^approved_patterns\.yml$|
61+
^stash/(?!pyproject\.toml).*$|
62+
^\.github/workflows/stash-action-test\.yml$
63+
args:
64+
- --comment-style
65+
- "#|#|#"
66+
- --license-filepath
67+
- license-templates/LICENSE.txt
68+
- --fuzzy-match-generates-todo
69+
- id: insert-license
70+
name: Add Apache license header to TOML files
71+
files: \.toml$
72+
args:
73+
- --comment-style
74+
- "#|#|#"
75+
- --license-filepath
76+
- license-templates/LICENSE.txt
77+
- --fuzzy-match-generates-todo
78+
- id: insert-license
79+
name: Add Apache license header to shell scripts
80+
files: \.(sh|bash)$
81+
args:
82+
- --comment-style
83+
- "#|#|#"
84+
- --license-filepath
85+
- license-templates/LICENSE.txt
86+
- --fuzzy-match-generates-todo
87+
- id: insert-license
88+
name: Add Apache license header to Dockerfiles
89+
files: (^|/)Dockerfile$|\.Dockerfile$
90+
args:
91+
- --comment-style
92+
- "#|#|#"
93+
- --license-filepath
94+
- license-templates/LICENSE.txt
95+
- --fuzzy-match-generates-todo
96+
- id: insert-license
97+
name: Add Apache license header to ezt templates
98+
files: \.ezt$
99+
args:
100+
- --comment-style
101+
- "#|#|#"
102+
- --license-filepath
103+
- license-templates/LICENSE.txt
104+
- --fuzzy-match-generates-todo
105+
- id: insert-license
106+
name: Add Apache license header to Markdown files
107+
files: \.md$
108+
# CLAUDE.md / AGENTS.md are agentic-tooling docs that follow the
109+
# short-license convention used in apache/airflow; keeping them
110+
# exempted here matches that convention until we add the short
111+
# template too. stash/README.md uses the short-form Apache license.
112+
exclude: |
113+
(?x)
114+
^(?:.*/)?AGENTS\.md$|
115+
^(?:.*/)?CLAUDE\.md$|
116+
^stash/.*\.md$
117+
args:
118+
- --comment-style
119+
- "<!--| |-->"
120+
- --license-filepath
121+
- license-templates/LICENSE.txt
122+
- --fuzzy-match-generates-todo

allowlist-check/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -14,6 +15,7 @@
1415
# KIND, either express or implied. See the License for the
1516
# specific language governing permissions and limitations
1617
# under the License.
18+
#
1719

1820
name: "ASF Allowlist Check"
1921
description: >

allowlist-check/check_asf_allowlist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -14,6 +15,7 @@
1415
# KIND, either express or implied. See the License for the
1516
# specific language governing permissions and limitations
1617
# under the License.
18+
#
1719

1820
"""Check that all GitHub Actions uses: refs are on the ASF allowlist.
1921

allowlist-check/insert_actions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
#
23
# Licensed to the Apache Software Foundation (ASF) under one
34
# or more contributor license agreements. See the NOTICE file
45
# distributed with this work for additional information
@@ -15,6 +16,7 @@
1516
# KIND, either express or implied. See the License for the
1617
# specific language governing permissions and limitations
1718
# under the License.
19+
#
1820
"""Insert action entries into actions.yml in alphabetical order.
1921
2022
Usage:

allowlist-check/test_check_asf_allowlist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -14,6 +15,7 @@
1415
# KIND, either express or implied. See the License for the
1516
# specific language governing permissions and limitations
1617
# under the License.
18+
#
1719

1820
import os
1921
import shutil

license-templates/LICENSE.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.

0 commit comments

Comments
 (0)