Skip to content

Commit f392feb

Browse files
committed
Added Powershell script to run the Release Audit Tool
1 parent 28d626d commit f392feb

3 files changed

Lines changed: 151 additions & 0 deletions

File tree

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,24 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
400+
###########################################
401+
# Custom
402+
###########################################
403+
404+
# BeyondCompare .orig files (when doing conflict resolution)
405+
*.orig
406+
407+
# Build artifacts
408+
_artifacts/
409+
410+
# Rider / ReSharper
399411
.idea/
412+
*.sln.iml
413+
414+
# Rider - allow shared inspection + code style profiles
415+
!.idea/.idea.SPDX.CodeAnalysis/.idea/inspectionProfiles/
416+
!.idea/.idea.SPDX.CodeAnalysis/.idea/codeStyles/
417+
418+
# Custom Tools
419+
.tools/*

.rat-excludes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Note: these patterns are applied to single files or directories, not full paths
2+
# coverage/* will ignore any coverage dir, but airflow/www/static/coverage/* will match nothing
3+
4+
.git/*
5+
.rat-excludes
6+
.gitignore
7+
.gitattributes
8+
9+
# Exclude build assets
10+
lib/*
11+
obj/*
12+
bin/*
13+
_artifacts/*
14+
_site/*
15+
16+
# Exclude auto-generated designers
17+
.*\.Designer\.cs

rat.ps1

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<#
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
#>
17+
18+
<#
19+
.SYNOPSIS
20+
Helper script to download and run the Apache Release Audit Tool (RAT).
21+
22+
.DESCRIPTION
23+
This script automates use of the Apache RAT tool during release preparation.
24+
It ensures that the RAT JAR is available locally (downloading it if needed)
25+
and then runs it against the source tree to check for missing license headers
26+
and other compliance issues.
27+
28+
By default, the tool is downloaded into a `.tools/rat` directory located next
29+
to this script. The script always runs RAT with the repository root (same
30+
directory as this script) as the target directory.
31+
32+
.PARAMETER Version
33+
The version of Apache RAT to use (default: 0.16).
34+
35+
.PARAMETER ExcludeFileName
36+
Name of an exclude file containing path patterns that RAT should ignore.
37+
This file should be located next to the script. Default: rat-exclude.txt
38+
39+
.REQUIREMENTS
40+
- Java 8+ must be installed and available on the PATH.
41+
- Internet connection (for first run, to download RAT).
42+
43+
.EXAMPLE
44+
pwsh ./rat.ps1
45+
46+
Runs Apache RAT (default version 0.16) with exclusions from `rat-exclude.txt`.
47+
48+
.EXAMPLE
49+
pwsh ./rat.ps1 -Version 0.16 -ExcludeFileName custom-exclude.txt
50+
51+
Runs Apache RAT version 0.16 using the specified exclude file.
52+
53+
.NOTES
54+
This script is intended for use by release managers when preparing official
55+
ASF releases. It is not normally required for day-to-day development.
56+
#>
57+
param(
58+
[string]$Version = "0.16",
59+
[string]$ExcludeFileName = ".rat-excludes"
60+
)
61+
62+
# Script directory (works in PowerShell Core and Windows PowerShell)
63+
$scriptDir = $PSScriptRoot
64+
65+
# Tool paths (kept under the script dir)
66+
$ratDir = Join-Path $scriptDir ".tools\rat"
67+
$ratJar = Join-Path $ratDir "apache-rat-$Version.jar"
68+
$ratUrl = "https://repo1.maven.org/maven2/org/apache/rat/apache-rat/$Version/apache-rat-$Version.jar"
69+
70+
# Exclude file path (resolved relative to script dir)
71+
$ratExcludeFile = Join-Path $scriptDir $ExcludeFileName
72+
73+
# Ensure tool folder exists and jar is present (download if missing)
74+
if (-not (Test-Path $ratDir)) {
75+
New-Item -ItemType Directory -Path $ratDir | Out-Null
76+
}
77+
78+
if (-not (Test-Path $ratJar)) {
79+
Write-Host "Downloading Apache RAT $Version to $ratJar ..."
80+
Invoke-WebRequest -Uri $ratUrl -OutFile $ratJar
81+
}
82+
83+
# If exclude file is optional, optionally warn if missing:
84+
if (-not (Test-Path $ratExcludeFile)) {
85+
Write-Host "Warning: exclude file '$ratExcludeFile' not found. Continuing without --exclude-file."
86+
$useExclude = $false
87+
} else {
88+
$useExclude = $true
89+
}
90+
91+
# Run from the script directory so '.' means the repository root next to this script
92+
Push-Location $scriptDir
93+
try {
94+
$argsList = @(
95+
"-jar", $ratJar,
96+
"--dir", ".",
97+
"--addLicense",
98+
"--force"
99+
)
100+
101+
if ($useExclude) {
102+
$argsList += @("--exclude-file", $ratExcludeFile)
103+
}
104+
105+
# Call java with argument list. Use & to invoke program.
106+
& java @argsList
107+
108+
if ($LASTEXITCODE -ne 0) {
109+
throw "RAT exited with code $LASTEXITCODE"
110+
}
111+
}
112+
finally {
113+
Pop-Location
114+
}

0 commit comments

Comments
 (0)