Merge v3-alpha into master #24
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Changelog Validation (v3) | |
| on: | |
| pull_request: | |
| branches: [ master ] | |
| paths: | |
| - 'docs/src/content/docs/changelog.mdx' | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR number to validate' | |
| required: true | |
| type: string | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| actions: write | |
| steps: | |
| - 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 || github.token }} | |
| - name: Get REAL validation script from v3-alpha | |
| run: | | |
| echo "Fetching the REAL validation script from v3-alpha branch..." | |
| git fetch origin master | |
| git checkout origin/master -- v3/scripts/validate-changelog.go | |
| echo "Validation script fetched successfully:" | |
| ls -la v3/scripts/ | |
| - name: Setup Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.25' | |
| - name: Get PR information | |
| id: pr_info | |
| run: | | |
| 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 "pr_number=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT | |
| echo "base_ref=master" >> $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" | |
| # Check only the changelog file for changes | |
| if git diff --quiet docs/src/content/docs/changelog.mdx; then | |
| echo "No changes to commit" | |
| echo "committed=false" >> $GITHUB_OUTPUT | |
| else | |
| # Ensure validation script doesn't get committed | |
| echo "v3/scripts/validate-changelog.go" >> .git/info/exclude | |
| # Get the correct branch name to push to | |
| REPO_OWNER="wailsapp" # Always wailsapp for this repo | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| BRANCH_NAME="${{ github.event.pull_request.head.ref }}" | |
| else | |
| # For manual workflow dispatch, get PR info | |
| PR_INFO=$(gh pr view ${{ steps.pr_info.outputs.pr_number }} --json headRefName,headRepository) | |
| BRANCH_NAME=$(echo "$PR_INFO" | jq -r '.headRefName') | |
| HEAD_REPO=$(echo "$PR_INFO" | jq -r '.headRepository.name') | |
| echo "🔍 PR source branch: $BRANCH_NAME" | |
| echo "🔍 Head repository: $HEAD_REPO" | |
| # Don't push if this is from a fork or if branch is v3-alpha (main branch) | |
| if [ "$HEAD_REPO" != "wails" ] || [ "$BRANCH_NAME" = "master" ]; then | |
| echo "⚠️ Cannot push - either fork or direct v3-alpha branch. Manual fix required." | |
| echo "committed=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| fi | |
| echo "Pushing to branch: $BRANCH_NAME in repo: $REPO_OWNER" | |
| # Only commit the changelog changes, not the validation script | |
| git add docs/src/content/docs/changelog.mdx | |
| git commit -m "🤖 Fix changelog: move entries to Unreleased section" | |
| # Only push if running on the main wailsapp repository | |
| if [ "${{ github.repository }}" = "wailsapp/wails" ]; then | |
| # Pull latest changes and rebase our commit | |
| git fetch origin $BRANCH_NAME | |
| git rebase origin/$BRANCH_NAME | |
| git push origin HEAD:$BRANCH_NAME | |
| else | |
| echo "⚠️ Running on fork (${{ github.repository }}). Skipping push - manual fix required." | |
| echo "committed=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "committed=true" >> $GITHUB_OUTPUT | |
| echo "✅ Changes committed and pushed" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get PR author for tagging | |
| id: pr_author | |
| if: steps.validate.outputs.result && github.event.inputs.pr_number | |
| run: | | |
| PR_AUTHOR=$(gh pr view ${{ steps.pr_info.outputs.pr_number }} --json author --jq '.author.login') | |
| echo "author=$PR_AUTHOR" >> $GITHUB_OUTPUT | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - 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 }}'; | |
| const author = '${{ steps.pr_author.outputs.author }}'; | |
| 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 === 'fixed' || result === 'cannot_fix' || result === 'error') { | |
| // Read the fixed changelog content | |
| const fs = require('fs'); | |
| let fixedContent = ''; | |
| try { | |
| fixedContent = fs.readFileSync('docs/src/content/docs/changelog.mdx', 'utf8'); | |
| } catch (error) { | |
| fixedContent = 'Error reading fixed changelog content'; | |
| } | |
| message = '## ⚠️ Changelog Validation Issue\\n\\n' + | |
| '@' + author + ' Your PR contains changelog entries that were added to already-released versions. These need to be moved to the `[Unreleased]` section.\\n\\n' + | |
| (committed === 'true' ? | |
| '✅ **Auto-fix applied**: The changes have been automatically committed to this PR.' : | |
| '❌ **Manual fix required**: Please apply the changes shown below manually.') + '\\n\\n' + | |
| '<details>\\n' + | |
| '<summary>📝 Click to see the corrected changelog content</summary>\\n\\n' + | |
| '```mdx\\n' + | |
| fixedContent + | |
| '\\n```\\n\\n' + | |
| '</details>\\n\\n' + | |
| '**What happened?** \\n' + | |
| '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' + | |
| (committed !== 'true' ? '**Action needed:** Please copy the corrected content from above and replace your changelog file.' : ''); | |
| } | |
| 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 |