1- name : Changelog V3
1+ name : Changelog Validation
22
33on :
4+ pull_request :
5+ branches : [ v3-alpha ]
6+ paths :
7+ - ' docs/src/content/docs/changelog.mdx'
48 workflow_dispatch :
59 inputs :
610 pr_number :
7- description : ' PR number'
11+ description : ' PR number to validate '
812 required : true
13+ type : string
914
1015jobs :
1116 validate :
1217 runs-on : ubuntu-latest
18+ permissions :
19+ contents : write
20+ pull-requests : write
21+
1322 steps :
14- - uses : actions/checkout@v4
15- - uses : actions/setup-go@v4
23+ - name : Checkout PR code
24+ uses : actions/checkout@v4
25+ with :
26+ ref : ${{ github.event.pull_request.head.sha || format('refs/pull/{0}/head', github.event.inputs.pr_number) }}
27+ fetch-depth : 0
28+ token : ${{ secrets.GITHUB_TOKEN }}
29+
30+ - name : Setup Go
31+ uses : actions/setup-go@v4
1632 with :
1733 go-version : ' 1.23'
18- - name : Simulate PR # 4392 validation
34+
35+ - name : Get PR information
36+ id : pr_info
37+ run : |
38+ if [ "${{ github.event_name }}" = "pull_request" ]; then
39+ echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
40+ echo "base_ref=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
41+ else
42+ echo "pr_number=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT
43+ echo "base_ref=v3-alpha" >> $GITHUB_OUTPUT
44+ fi
45+
46+ - name : Check changelog modifications
47+ id : changelog_check
1948 run : |
20- echo "Simulating validation for PR: ${{ github.event.inputs.pr_number }}"
49+ echo "Checking PR #${{ steps.pr_info.outputs.pr_number }} for changelog changes"
50+ git fetch origin ${{ steps.pr_info.outputs.base_ref }}
51+
52+ if git diff --name-only origin/${{ steps.pr_info.outputs.base_ref }}..HEAD | grep -q "docs/src/content/docs/changelog.mdx"; then
53+ echo "changelog_modified=true" >> $GITHUB_OUTPUT
54+ echo "✅ Changelog was modified in this PR"
55+ else
56+ echo "changelog_modified=false" >> $GITHUB_OUTPUT
57+ echo "ℹ️ Changelog was not modified - skipping validation"
58+ fi
2159
22- # Simulate the problematic lines from PR #4392
23- cat > /tmp/pr_added_lines.txt << 'EOF'
24- - Add distribution-specific build dependencies for Linux by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/4345)
25- - Added bindings guide by @atterpac in [PR](https://github.com/wailsapp/wails/pull/4404)
26- EOF
60+ - name : Get changelog diff
61+ id : get_diff
62+ if : steps.changelog_check.outputs.changelog_modified == 'true'
63+ run : |
64+ echo "Getting diff for changelog changes..."
65+ git diff origin/${{ steps.pr_info.outputs.base_ref }}..HEAD docs/src/content/docs/changelog.mdx | grep "^+" | grep -v "^+++" | sed 's/^+//' > /tmp/pr_added_lines.txt
2766
28- echo "Simulated lines that would be added to changelog :"
67+ echo "Lines added in this PR :"
2968 cat /tmp/pr_added_lines.txt
69+ echo "Total lines added: $(wc -l < /tmp/pr_added_lines.txt)"
70+
71+ - name : Validate changelog
72+ id : validate
73+ if : steps.changelog_check.outputs.changelog_modified == 'true'
74+ run : |
75+ echo "Running changelog validation..."
76+ cd v3/scripts
77+ OUTPUT=$(go run validate-changelog.go ../../docs/src/content/docs/changelog.mdx /tmp/pr_added_lines.txt 2>&1)
78+ echo "$OUTPUT"
79+
80+ RESULT=$(echo "$OUTPUT" | grep "VALIDATION_RESULT=" | cut -d'=' -f2)
81+ echo "result=$RESULT" >> $GITHUB_OUTPUT
3082
31- # Fetch v3-alpha to get the actual changelog
32- git fetch origin v3-alpha
33- git checkout origin/v3-alpha -- docs/src/content/docs/changelog.mdx || echo "Changelog not found, creating test version"
83+ - name : Commit fixes
84+ id : commit_fixes
85+ if : steps.validate.outputs.result == 'fixed'
86+ run : |
87+ echo "Committing automatic fixes..."
88+ git config --local user.email "action@github.com"
89+ git config --local user.name "GitHub Action"
3490
35- # Run validation if script exists
36- if [ -f "v3/scripts/validate-changelog.go" ]; then
37- echo "Running changelog validation..."
38- cd v3/scripts
39- go run validate-changelog.go ../../docs/src/content/docs/changelog.mdx /tmp/pr_added_lines.txt
91+ if git diff --quiet docs/src/content/docs/changelog.mdx; then
92+ echo "No changes to commit"
93+ echo "committed=false" >> $GITHUB_OUTPUT
4094 else
41- echo "Script not found"
42- fi
95+ git add docs/src/content/docs/changelog.mdx
96+ git commit -m "🤖 Fix changelog: move entries to Unreleased section"
97+ git push origin HEAD
98+ echo "committed=true" >> $GITHUB_OUTPUT
99+ echo "✅ Changes committed and pushed"
100+ fi
101+
102+ - name : Comment on PR
103+ if : steps.validate.outputs.result && github.event.inputs.pr_number
104+ uses : actions/github-script@v7
105+ with :
106+ script : |
107+ const result = '${{ steps.validate.outputs.result }}';
108+ const committed = '${{ steps.commit_fixes.outputs.committed }}';
109+
110+ let message;
111+ if (result === 'success') {
112+ message = '## ✅ Changelog Validation Passed\n\nNo misplaced changelog entries detected.';
113+ } else if (result === 'fixed' && committed === 'true') {
114+ message = '## 🔧 Changelog Updated\n\nMisplaced entries were automatically moved to the `[Unreleased]` section. The changes have been committed to this PR.';
115+ } else if (result === 'cannot_fix' || result === 'error') {
116+ message = '## ❌ Changelog Validation Failed\n\nPlease manually move changelog entries to the `[Unreleased]` section.';
117+ }
118+
119+ if (message) {
120+ await github.rest.issues.createComment({
121+ issue_number: ${{ steps.pr_info.outputs.pr_number }},
122+ owner: context.repo.owner,
123+ repo: context.repo.repo,
124+ body: message
125+ });
126+ }
127+
128+ - name : Fail if validation failed
129+ if : steps.validate.outputs.result == 'cannot_fix' || steps.validate.outputs.result == 'error'
130+ run : |
131+ echo "❌ Changelog validation failed"
132+ exit 1
0 commit comments