|
| 1 | +name: XAML Styler |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: |
| 6 | + - "created" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + xaml-styler: |
| 13 | + name: Apply XAML Styling |
| 14 | + runs-on: windows-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + if: >- |
| 19 | + github.event.issue.pull_request && |
| 20 | + contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) && |
| 21 | + trim(github.event.comment.body) == '/xamlstyler' |
| 22 | + concurrency: |
| 23 | + group: xaml-styler-${{ github.event.issue.number }} |
| 24 | + cancel-in-progress: true |
| 25 | + steps: |
| 26 | + - name: Add eyes reaction |
| 27 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + await github.rest.reactions.createForIssueComment({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + comment_id: context.payload.comment.id, |
| 34 | + content: 'eyes' |
| 35 | + }); |
| 36 | +
|
| 37 | + - name: Get PR details |
| 38 | + id: pr |
| 39 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 40 | + with: |
| 41 | + script: | |
| 42 | + const pr = await github.rest.pulls.get({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + pull_number: context.issue.number |
| 46 | + }); |
| 47 | + core.setOutput('head_ref', pr.data.head.ref); |
| 48 | + core.setOutput('head_repo', pr.data.head.repo.full_name); |
| 49 | +
|
| 50 | + - name: Checkout PR branch |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + repository: ${{ steps.pr.outputs.head_repo }} |
| 54 | + ref: ${{ steps.pr.outputs.head_ref }} |
| 55 | + fetch-depth: 0 |
| 56 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Setup .NET |
| 59 | + uses: actions/setup-dotnet@v4 |
| 60 | + with: |
| 61 | + dotnet-version: '9.0.x' |
| 62 | + |
| 63 | + - name: Restore dotnet tools |
| 64 | + run: dotnet tool restore |
| 65 | + |
| 66 | + - name: Run XAML Styler |
| 67 | + run: | |
| 68 | + & '.pipelines/applyXamlStyling.ps1' -Main |
| 69 | + shell: pwsh |
| 70 | + |
| 71 | + - name: Commit and push changes |
| 72 | + id: commit |
| 73 | + run: | |
| 74 | + git config user.name "github-actions[bot]" |
| 75 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 76 | + git add -A |
| 77 | + if (git diff --cached --quiet) { |
| 78 | + echo "has_changes=false" >> $env:GITHUB_OUTPUT |
| 79 | + } else { |
| 80 | + git commit -m "Apply XAML styling" |
| 81 | + git push |
| 82 | + echo "has_changes=true" >> $env:GITHUB_OUTPUT |
| 83 | + } |
| 84 | + shell: pwsh |
| 85 | + |
| 86 | + - name: Add success reaction |
| 87 | + if: always() && steps.commit.outcome == 'success' |
| 88 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 89 | + with: |
| 90 | + script: | |
| 91 | + const hasChanges = '${{ steps.commit.outputs.has_changes }}' === 'true'; |
| 92 | + await github.rest.reactions.createForIssueComment({ |
| 93 | + owner: context.repo.owner, |
| 94 | + repo: context.repo.repo, |
| 95 | + comment_id: context.payload.comment.id, |
| 96 | + content: hasChanges ? 'rocket' : '+1' |
| 97 | + }); |
| 98 | + if (!hasChanges) { |
| 99 | + await github.rest.issues.createComment({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + issue_number: context.issue.number, |
| 103 | + body: '✅ No XAML styling changes needed — all files are already formatted correctly.' |
| 104 | + }); |
| 105 | + } |
| 106 | +
|
| 107 | + - name: Add failure reaction |
| 108 | + if: failure() |
| 109 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 110 | + with: |
| 111 | + script: | |
| 112 | + await github.rest.reactions.createForIssueComment({ |
| 113 | + owner: context.repo.owner, |
| 114 | + repo: context.repo.repo, |
| 115 | + comment_id: context.payload.comment.id, |
| 116 | + content: 'confused' |
| 117 | + }); |
0 commit comments