Create REAL changelog validation workflow

- Validates actual PRs against v3-alpha branch
- Gets real PR diff from GitHub
- Runs actual validation script
- Commits fixes back to PR
- Comments on PR with results
- Automatically triggers on changelog changes to v3-alpha PRs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Lea Anthony 2025-07-13 11:26:13 +10:00
commit 9640e16c12

View file

@ -1,42 +1,132 @@
name: Changelog V3
name: Changelog Validation
on:
pull_request:
branches: [ v3-alpha ]
paths:
- 'docs/src/content/docs/changelog.mdx'
workflow_dispatch:
inputs:
pr_number:
description: 'PR number'
description: 'PR number to validate'
required: true
type: string
jobs:
validate:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || format('refs/pull/{0}/head', github.event.inputs.pr_number) }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Simulate PR #4392 validation
- name: Get PR information
id: pr_info
run: |
echo "Simulating validation for PR: ${{ github.event.inputs.pr_number }}"
# Simulate the problematic lines from PR #4392
cat > /tmp/pr_added_lines.txt << 'EOF'
- Add distribution-specific build dependencies for Linux by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/4345)
- Added bindings guide by @atterpac in [PR](https://github.com/wailsapp/wails/pull/4404)
EOF
echo "Simulated lines that would be added to changelog:"
cat /tmp/pr_added_lines.txt
# Fetch v3-alpha to get the actual changelog
git fetch origin v3-alpha
git checkout origin/v3-alpha -- docs/src/content/docs/changelog.mdx || echo "Changelog not found, creating test version"
# Run validation if script exists
if [ -f "v3/scripts/validate-changelog.go" ]; then
echo "Running changelog validation..."
cd v3/scripts
go run validate-changelog.go ../../docs/src/content/docs/changelog.mdx /tmp/pr_added_lines.txt
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
echo "base_ref=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
else
echo "Script not found"
fi
echo "pr_number=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT
echo "base_ref=v3-alpha" >> $GITHUB_OUTPUT
fi
- name: Check changelog modifications
id: changelog_check
run: |
echo "Checking PR #${{ steps.pr_info.outputs.pr_number }} for changelog changes"
git fetch origin ${{ steps.pr_info.outputs.base_ref }}
if git diff --name-only origin/${{ steps.pr_info.outputs.base_ref }}..HEAD | grep -q "docs/src/content/docs/changelog.mdx"; then
echo "changelog_modified=true" >> $GITHUB_OUTPUT
echo "✅ Changelog was modified in this PR"
else
echo "changelog_modified=false" >> $GITHUB_OUTPUT
echo " Changelog was not modified - skipping validation"
fi
- name: Get changelog diff
id: get_diff
if: steps.changelog_check.outputs.changelog_modified == 'true'
run: |
echo "Getting diff for changelog changes..."
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
echo "Lines added in this PR:"
cat /tmp/pr_added_lines.txt
echo "Total lines added: $(wc -l < /tmp/pr_added_lines.txt)"
- name: Validate changelog
id: validate
if: steps.changelog_check.outputs.changelog_modified == 'true'
run: |
echo "Running changelog validation..."
cd v3/scripts
OUTPUT=$(go run validate-changelog.go ../../docs/src/content/docs/changelog.mdx /tmp/pr_added_lines.txt 2>&1)
echo "$OUTPUT"
RESULT=$(echo "$OUTPUT" | grep "VALIDATION_RESULT=" | cut -d'=' -f2)
echo "result=$RESULT" >> $GITHUB_OUTPUT
- name: Commit fixes
id: commit_fixes
if: steps.validate.outputs.result == 'fixed'
run: |
echo "Committing automatic fixes..."
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if git diff --quiet docs/src/content/docs/changelog.mdx; then
echo "No changes to commit"
echo "committed=false" >> $GITHUB_OUTPUT
else
git add docs/src/content/docs/changelog.mdx
git commit -m "🤖 Fix changelog: move entries to Unreleased section"
git push origin HEAD
echo "committed=true" >> $GITHUB_OUTPUT
echo "✅ Changes committed and pushed"
fi
- name: Comment on PR
if: steps.validate.outputs.result && github.event.inputs.pr_number
uses: actions/github-script@v7
with:
script: |
const result = '${{ steps.validate.outputs.result }}';
const committed = '${{ steps.commit_fixes.outputs.committed }}';
let message;
if (result === 'success') {
message = '## ✅ Changelog Validation Passed\n\nNo misplaced changelog entries detected.';
} else if (result === 'fixed' && committed === 'true') {
message = '## 🔧 Changelog Updated\n\nMisplaced entries were automatically moved to the `[Unreleased]` section. The changes have been committed to this PR.';
} else if (result === 'cannot_fix' || result === 'error') {
message = '## ❌ Changelog Validation Failed\n\nPlease manually move changelog entries to the `[Unreleased]` section.';
}
if (message) {
await github.rest.issues.createComment({
issue_number: ${{ steps.pr_info.outputs.pr_number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
}
- name: Fail if validation failed
if: steps.validate.outputs.result == 'cannot_fix' || steps.validate.outputs.result == 'error'
run: |
echo "❌ Changelog validation failed"
exit 1