@@ -16,26 +16,32 @@ jobs:
1616 validate :
1717 runs-on : ubuntu-latest
1818 if : github.repository == 'wailsapp/wails'
19+ outputs :
20+ pr_number : ${{ steps.pr_info.outputs.pr_number }}
21+ result : ${{ steps.validate.outputs.result }}
1922 env :
2023 GOWORK : " off"
2124 permissions :
22- contents : write
23- pull-requests : write
24- actions : write
25+ contents : read
2526
2627 steps :
2728 - name : Checkout PR code
2829 uses : actions/checkout@v4
2930 with :
3031 ref : ${{ github.event.pull_request.head.sha || format('refs/pull/{0}/head', github.event.inputs.pr_number) }}
3132 fetch-depth : 0
32- token : ${{ secrets.GITHUB_TOKEN || github.token }}
33+ persist-credentials : false
3334
34- - name : Get validation script from master
35+ - name : Select validation script
3536 run : |
3637 echo "Fetching the validation script from master branch..."
3738 git fetch origin master
38- git checkout origin/master -- v3/scripts/validate-changelog.go
39+
40+ if git diff --quiet origin/master...HEAD -- v3/scripts/validate-changelog.go v3/scripts/validate-changelog_test.go; then
41+ git checkout origin/master -- v3/scripts/validate-changelog.go
42+ else
43+ echo "The PR updates the validator; retaining that version for focused tests."
44+ fi
3945
4046 echo "Validation script fetched successfully:"
4147 ls -la v3/scripts/
4450 uses : actions/setup-go@v4
4551 with :
4652 go-version : ' 1.25'
53+
54+ - name : Test validation script changes
55+ run : |
56+ if ! git diff --quiet origin/master...HEAD -- v3/scripts/validate-changelog.go v3/scripts/validate-changelog_test.go; then
57+ go test v3/scripts/validate-changelog.go v3/scripts/validate-changelog_test.go
58+ fi
4759
4860 - name : Get PR information
4961 id : pr_info
@@ -75,145 +87,74 @@ jobs:
7587 if : steps.changelog_check.outputs.changelog_modified == 'true'
7688 run : |
7789 echo "Getting diff for changelog changes..."
78- 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
90+ git diff origin/${{ steps.pr_info.outputs.base_ref }}..HEAD docs/src/content/docs/changelog.mdx > /tmp/pr_changelog.diff
91+ awk '/^\+\+\+/ { next } /^\+/ { sub(/^\+/, ""); print }' /tmp/pr_changelog.diff > /tmp/pr_added_lines.txt
92+ awk '/^---/ { next } /^-/ { sub(/^-/, ""); print }' /tmp/pr_changelog.diff > /tmp/pr_deleted_lines.txt
93+ git show origin/${{ steps.pr_info.outputs.base_ref }}:docs/src/content/docs/changelog.mdx > /tmp/base_changelog.mdx
7994
8095 echo "Lines added in this PR:"
8196 cat /tmp/pr_added_lines.txt
8297 echo "Total lines added: $(wc -l < /tmp/pr_added_lines.txt)"
98+
99+ echo "Lines deleted in this PR:"
100+ cat /tmp/pr_deleted_lines.txt
101+ echo "Total lines deleted: $(wc -l < /tmp/pr_deleted_lines.txt)"
83102
84103 - name : Validate changelog
85104 id : validate
86105 if : steps.changelog_check.outputs.changelog_modified == 'true'
87106 run : |
88107 echo "Running changelog validation..."
89108 cd v3/scripts
90- OUTPUT=$(go run validate-changelog.go ../../docs/src/content/docs/changelog.mdx /tmp/pr_added_lines.txt 2>&1)
109+ if ! OUTPUT=$(go run validate-changelog.go ../../docs/src/content/docs/changelog.mdx /tmp/pr_added_lines.txt /tmp/pr_deleted_lines.txt /tmp/base_changelog.mdx 2>&1); then
110+ echo "$OUTPUT"
111+ exit 1
112+ fi
91113 echo "$OUTPUT"
92114
93115 RESULT=$(echo "$OUTPUT" | grep "VALIDATION_RESULT=" | cut -d'=' -f2)
94116 echo "result=$RESULT" >> $GITHUB_OUTPUT
95117
96- - name : Commit fixes
97- id : commit_fixes
98- if : steps.validate.outputs.result == 'fixed'
99- run : |
100- echo "Committing automatic fixes..."
101- git config --local user.email "action@github.com"
102- git config --local user.name "GitHub Action"
103-
104- # Check only the changelog file for changes
105- if git diff --quiet docs/src/content/docs/changelog.mdx; then
106- echo "No changes to commit"
107- echo "committed=false" >> $GITHUB_OUTPUT
108- else
109- # Ensure validation script doesn't get committed
110- echo "v3/scripts/validate-changelog.go" >> .git/info/exclude
111- # Get the correct branch name to push to
112- REPO_OWNER="wailsapp" # Always wailsapp for this repo
113-
114- if [ "${{ github.event_name }}" = "pull_request" ]; then
115- BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
116- else
117- # For manual workflow dispatch, get PR info
118- PR_INFO=$(gh pr view ${{ steps.pr_info.outputs.pr_number }} --json headRefName,headRepository)
119- BRANCH_NAME=$(echo "$PR_INFO" | jq -r '.headRefName')
120- HEAD_REPO=$(echo "$PR_INFO" | jq -r '.headRepository.name')
121-
122- echo "🔍 PR source branch: $BRANCH_NAME"
123- echo "🔍 Head repository: $HEAD_REPO"
124-
125- # Don't push if this is from a fork or if branch is master (main branch)
126- if [ "$HEAD_REPO" != "wails" ] || [ "$BRANCH_NAME" = "master" ]; then
127- echo "⚠️ Cannot push - either fork or master branch. Manual fix required."
128- echo "committed=false" >> $GITHUB_OUTPUT
129- exit 0
130- fi
131- fi
132-
133- echo "Pushing to branch: $BRANCH_NAME in repo: $REPO_OWNER"
134-
135- # Only commit the changelog changes, not the validation script
136- git add docs/src/content/docs/changelog.mdx
137- git commit -m "🤖 Fix changelog: move entries to Unreleased section"
138-
139- # Only push if running on the main wailsapp repository
140- if [ "${{ github.repository }}" = "wailsapp/wails" ]; then
141- # Pull latest changes and rebase our commit
142- git fetch origin $BRANCH_NAME
143- git rebase origin/$BRANCH_NAME
144- git push origin HEAD:$BRANCH_NAME
145- else
146- echo "⚠️ Running on fork (${{ github.repository }}). Skipping push - manual fix required."
147- echo "committed=false" >> $GITHUB_OUTPUT
148- exit 0
149- fi
150-
151- echo "committed=true" >> $GITHUB_OUTPUT
152- echo "✅ Changes committed and pushed"
153- fi
154- env :
155- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
156-
157- - name : Get PR author for tagging
158- id : pr_author
159- if : steps.validate.outputs.result && github.event.inputs.pr_number
118+ - name : Fail if validation failed
119+ if : steps.validate.outputs.result && steps.validate.outputs.result != 'success'
160120 run : |
161- PR_AUTHOR=$(gh pr view ${{ steps.pr_info.outputs.pr_number }} --json author --jq '.author.login')
162- echo "author=$PR_AUTHOR" >> $GITHUB_OUTPUT
163- env :
164- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
121+ echo "❌ Changelog validation failed"
122+ exit 1
165123
124+ report :
125+ needs : validate
126+ if : always() && github.event.inputs.pr_number && needs.validate.outputs.result
127+ runs-on : ubuntu-latest
128+ permissions :
129+ contents : read
130+ issues : write
131+ pull-requests : read
132+
133+ steps :
166134 - name : Comment on PR
167- if : steps.validate.outputs.result && github.event.inputs.pr_number
168135 uses : actions/github-script@v7
136+ env :
137+ PR_NUMBER : ${{ needs.validate.outputs.pr_number }}
138+ VALIDATION_RESULT : ${{ needs.validate.outputs.result }}
169139 with :
170140 script : |
171- const result = '${{ steps.validate.outputs.result }}';
172- const committed = '${{ steps.commit_fixes.outputs.committed }}';
173- const author = '${{ steps.pr_author.outputs.author }}';
174-
175- let message;
176- if (result === 'success') {
177- message = '## ✅ Changelog Validation Passed\n\nNo misplaced changelog entries detected.';
178- } else if (result === 'fixed' && committed === 'true') {
179- message = '## 🔧 Changelog Updated\n\nMisplaced entries were automatically moved to the `[Unreleased]` section. The changes have been committed to this PR.';
180- } else if (result === 'fixed' || result === 'cannot_fix' || result === 'error') {
181- // Read the fixed changelog content
182- const fs = require('fs');
183- let fixedContent = '';
184- try {
185- fixedContent = fs.readFileSync('docs/src/content/docs/changelog.mdx', 'utf8');
186- } catch (error) {
187- fixedContent = 'Error reading fixed changelog content';
188- }
189-
190- message = '## ⚠️ Changelog Validation Issue\\n\\n' +
191- '@' + author + ' Your PR contains changelog entries that were added to already-released versions. These need to be moved to the `[Unreleased]` section.\\n\\n' +
192- (committed === 'true' ?
193- '✅ **Auto-fix applied**: The changes have been automatically committed to this PR.' :
194- '❌ **Manual fix required**: Please apply the changes shown below manually.') + '\\n\\n' +
195- '<details>\\n' +
196- '<summary>📝 Click to see the corrected changelog content</summary>\\n\\n' +
197- '```mdx\\n' +
198- fixedContent +
199- '\\n```\\n\\n' +
200- '</details>\\n\\n' +
201- '**What happened?** \\n' +
202- 'The validation script detected that you added changelog entries to a version section that has already been released (like `v3.0.0-alpha.10`). All new entries should go in the `[Unreleased]` section under the appropriate category (`### Added`, `### Fixed`, etc.).\\n\\n' +
203- (committed !== 'true' ? '**Action needed:** Please copy the corrected content from above and replace your changelog file.' : '');
204- }
205-
206- if (message) {
207- await github.rest.issues.createComment({
208- issue_number: ${{ steps.pr_info.outputs.pr_number }},
209- owner: context.repo.owner,
210- repo: context.repo.repo,
211- body: message
212- });
213- }
214-
215- - name : Fail if validation failed
216- if : steps.validate.outputs.result == 'cannot_fix' || steps.validate.outputs.result == 'error'
217- run : |
218- echo "❌ Changelog validation failed"
219- exit 1
141+ const prNumber = Number(process.env.PR_NUMBER);
142+ const result = process.env.VALIDATION_RESULT;
143+ const { data: pr } = await github.rest.pulls.get({
144+ owner: context.repo.owner,
145+ repo: context.repo.repo,
146+ pull_number: prNumber,
147+ });
148+
149+ const message = result === 'success'
150+ ? '## ✅ Changelog Validation Passed\n\nNo misplaced changelog entries detected.'
151+ : '## ⚠️ Changelog Validation Issue\n\n@' + pr.user.login +
152+ ' your PR contains changelog entries outside `[Unreleased]`. ' +
153+ 'The validation job is read-only; apply the correction manually and rerun it.';
154+
155+ await github.rest.issues.createComment({
156+ issue_number: prNumber,
157+ owner: context.repo.owner,
158+ repo: context.repo.repo,
159+ body: message,
160+ });
0 commit comments