-
Notifications
You must be signed in to change notification settings - Fork 815
108 lines (88 loc) · 3.41 KB
/
validate-changelog.yml
File metadata and controls
108 lines (88 loc) · 3.41 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
name: Validate Changelog
on:
pull_request:
branches:
- '*'
jobs:
validate-changelog:
name: Check changelog entry
# Skip validation for Renovate PRs (solrbot) - they get changelog entries automatically
if: github.event.pull_request.user.login != 'solrbot'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for no-changelog label
id: check-label
run: |
LABELS='${{ toJson(github.event.pull_request.labels) }}'
if echo "$LABELS" | grep -q '"no-changelog"'; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Check for changelog entry
if: steps.check-label.outputs.skip == 'false'
run: |
# Get the list of changed files
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
# Check if any files were added to changelog/unreleased/
if echo "$CHANGED_FILES" | grep -q "^changelog/unreleased/"; then
echo "✓ Changelog entry found"
exit 0
fi
# Check if only docs/tests/comments were changed (common exceptions)
HAS_NON_DOCS_CHANGES=false
while IFS= read -r file; do
# Skip changelog, docs, tests, and certain config files
if ! echo "$file" | grep -qE "(^changelog/|^solr/solr-ref-guide/|^dev-docs/|\.md$|\.adoc$|^solr/.*/test|\.gradle$|\.properties$|README|NOTICE|LICENSE)"; then
HAS_NON_DOCS_CHANGES=true
break
fi
done <<< "$CHANGED_FILES"
if [ "$HAS_NON_DOCS_CHANGES" = false ]; then
echo "✓ No code changes detected (docs/tests only)"
exit 0
fi
echo "::error::This PR appears to contain code changes but no changelog entry was added."
echo ""
echo "Please add a changelog entry by:"
echo "1. Running: ./gradlew writeChangelog"
echo "2. Editing the generated YAML file in changelog/unreleased/"
echo "3. Committing the YAML file"
echo ""
echo "For more information, see: dev-docs/changelog.adoc"
echo ""
echo "If this PR should not have a changelog entry (e.g., refactoring, internal cleanup),"
echo "add the 'no-changelog' label to this PR."
exit 1
- name: Validate changelog YAML structure
if: steps.check-label.outputs.skip == 'false'
run: |
# Get the list of changed files
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
# Find all YAML files added to changelog/unreleased/
YAML_FILES=$(echo "$CHANGED_FILES" | grep "^changelog/unreleased/.*\.ya\?ml$" || true)
if [ -z "$YAML_FILES" ]; then
exit 0
fi
echo "Validating changelog YAML files..."
VALIDATION_FAILED=false
while IFS= read -r file; do
if [ -z "$file" ] || [ ! -f "$file" ]; then
continue
fi
echo ""
echo "Validating: $file"
# Validate using a Python script
python3 .github/scripts/validate-changelog-yaml.py "$file"
if [ $? -ne 0 ]; then
VALIDATION_FAILED=true
fi
done <<< "$YAML_FILES"
if [ "$VALIDATION_FAILED" = true ]; then
echo "Please see dev-docs/changelog.adoc for more info."
exit 1
fi