Skip to content

Commit a3e05cf

Browse files
authored
CI: add Apache RAT audit workflow for license checks
This commit introduces a new GitHub workflow that: - Runs Apache Rat to verify license compliance on all files - Executes automatically on PR submissions and merges to main branch - Uploads check results as artifacts for debugging purposes - Provides a clear job summary with appropriate status indicators This workflow can help us ensure all files comply with ASF requirements, catching potential licensing issues before they're merged into the codebase.
1 parent fed0458 commit a3e05cf

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

.asf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ github:
8585
# Actions workflows. They do not include the workflow name as a
8686
# prefix
8787
contexts:
88+
- rat-check
8889
- check-skip
8990
- Build Apache Cloudberry RPM
9091
- RPM Install Test Apache Cloudberry
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# --------------------------------------------------------------------
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed
5+
# with this work for additional information regarding copyright
6+
# ownership. The ASF licenses this file to You under the Apache
7+
# License, Version 2.0 (the "License"); you may not use this file
8+
# except in compliance with the License. You may obtain a copy of the
9+
# License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
# implied. See the License for the specific language governing
17+
# permissions and limitations under the License.
18+
#
19+
# --------------------------------------------------------------------
20+
# Apache Rat Audit Workflow
21+
# Checks if all files comply with Apache licensing requirements
22+
# This workflow is based on the Apache Rat tool, you can run it locally
23+
# using the command: `mvn clean verify -Drat.consoleOutput=true`
24+
# --------------------------------------------------------------------
25+
26+
name: Apache Rat Audit
27+
28+
on:
29+
push:
30+
branches: [main]
31+
pull_request:
32+
branches: [main]
33+
types: [opened, synchronize, reopened, edited]
34+
workflow_dispatch:
35+
36+
permissions:
37+
contents: read
38+
39+
concurrency:
40+
group: ${{ github.workflow }}-${{ github.ref }}
41+
cancel-in-progress: true
42+
43+
jobs:
44+
rat-check:
45+
name: Apache Rat License Check
46+
runs-on: ubuntu-latest
47+
timeout-minutes: 10
48+
49+
steps:
50+
- name: Check out repository
51+
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 1
54+
55+
- name: Set up Java and Maven
56+
uses: actions/setup-java@v3
57+
with:
58+
distribution: 'temurin'
59+
java-version: '11'
60+
cache: maven
61+
62+
- name: Run Apache Rat check
63+
id: rat-check
64+
run: |
65+
echo "Running Apache Rat license check..."
66+
mvn clean verify -Drat.consoleOutput=true | tee rat-output.log
67+
68+
# Check for build failure
69+
if grep -q "\[INFO\] BUILD FAILURE" rat-output.log; then
70+
echo "rat_failed=true" >> $GITHUB_OUTPUT
71+
echo "::error::Apache Rat check failed - build failure detected"
72+
exit 1
73+
fi
74+
75+
# If we got here, the check passed
76+
echo "rat_failed=false" >> $GITHUB_OUTPUT
77+
echo "Apache Rat check passed successfully"
78+
79+
- name: Upload Rat check results
80+
if: always()
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: rat-check-results
84+
path: rat-output.log
85+
retention-days: 7
86+
87+
- name: Generate Job Summary
88+
if: always()
89+
run: |
90+
{
91+
echo "## Apache Rat Audit Results"
92+
echo "- Run Time: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
93+
echo ""
94+
95+
if [[ -f rat-output.log ]]; then
96+
# First extract and display summary statistics (only once)
97+
if grep -q "Rat check: Summary over all files" rat-output.log; then
98+
echo "#### 📊 License Summary"
99+
summary_line=$(grep "Rat check: Summary over all files" rat-output.log)
100+
echo "\`\`\`"
101+
echo "$summary_line"
102+
echo "\`\`\`"
103+
echo ""
104+
fi
105+
106+
# Then determine the result status
107+
if grep -q "\[INFO\] BUILD FAILURE" rat-output.log; then
108+
echo "### ❌ Check Failed - License Compliance Issues Detected"
109+
echo ""
110+
111+
# Extract and display files with unapproved licenses
112+
if grep -q "Files with unapproved licenses:" rat-output.log; then
113+
echo "#### 🚫 Files with Unapproved Licenses"
114+
echo "\`\`\`"
115+
# Get the line with "Files with unapproved licenses:" and all following lines until the dashed line
116+
sed -n '/Files with unapproved licenses:/,/\[INFO\] ------------------------------------------------------------------------/p' rat-output.log | \
117+
grep -v "\[INFO\] ------------------------------------------------------------------------" | \
118+
grep -v "^$" | \
119+
head -20
120+
echo "\`\`\`"
121+
echo ""
122+
fi
123+
124+
echo "💡 **How to fix:**"
125+
echo ""
126+
echo "**For new original files you created:**"
127+
echo "- Add the standard Apache License header to each file"
128+
echo ""
129+
echo "**For third-party files with different licenses:**"
130+
echo "- Add the file to exclusion list in \`pom.xml\` under the rat-maven-plugin configuration"
131+
echo "- Ensure the license is compatible with Apache License 2.0"
132+
echo "- Avoid introducing components with incompatible licenses"
133+
echo ""
134+
echo "**Need help?**"
135+
echo "- Run \`mvn clean verify -Drat.consoleOutput=true\` locally for the full report"
136+
echo "- Email [email protected] if you have questions about license compatibility"
137+
138+
elif grep -q "\[INFO\] BUILD SUCCESS" rat-output.log; then
139+
echo "### ✅ Check Passed - All Files Comply with Apache License Requirements"
140+
141+
else
142+
echo "### ⚠️ Indeterminate Result"
143+
echo "Check the uploaded log file for details."
144+
fi
145+
else
146+
echo "### ⚠️ No Output Log Found"
147+
echo "The rat-output.log file was not generated."
148+
fi
149+
} >> "$GITHUB_STEP_SUMMARY"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<img alt="SonarQube Cloud" src="https://sonarcloud.io/images/project_badges/sonarcloud-highlight.svg" width="100px">
4747
</a>
4848
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/apache/cloudberry)
49+
[![Apache Rat Audit](https://github.com/apache/cloudberry/actions/workflows/apache-rat-audit.yml/badge.svg)](https://github.com/apache/cloudberry/actions/workflows/apache-rat-audit.yml)
4950
---------
5051

5152
## Introduction

0 commit comments

Comments
 (0)