diff --git a/.github/workflows/format-xaml.yml b/.github/workflows/format-xaml.yml index 9e72b8288deb..ebe9a94530a9 100644 --- a/.github/workflows/format-xaml.yml +++ b/.github/workflows/format-xaml.yml @@ -7,7 +7,6 @@ jobs: format-xaml: if: github.event.issue.pull_request && github.event.comment.body == '/format' runs-on: ubuntu-latest - environment: Pull Requests defaults: run: shell: pwsh @@ -15,12 +14,10 @@ jobs: steps: - name: Generate GitHub Apps token id: generate - uses: tibdex/github-app-token@v1 + uses: actions/create-github-app-token@v1 with: - app_id: ${{ secrets.BOT_APP_ID }} - - private_key: ${{ secrets.BOT_PRIVATE_KEY }} - + app-id: ${{ secrets.BOT_APP_ID }} + private-key: ${{ secrets.BOT_PRIVATE_KEY }} - name: Create run condition variable run: | @@ -43,6 +40,9 @@ jobs: # all steps after this one must have the env.CAN_RUN == 1 condition + - uses: actions/checkout@v4 + if: env.CAN_RUN == 1 + - name: Set git identity if: env.CAN_RUN == 1 run: | @@ -56,10 +56,6 @@ jobs: git config --global user.name "$($data.login)" git config --global user.email "$($data.databaseId)+$($data.login)@users.noreply.github.com" - - - uses: actions/checkout@v4 - if: env.CAN_RUN == 1 - - name: Checkout PR if: env.CAN_RUN == 1 run: gh pr checkout ${{ github.event.issue.number }} -b pr @@ -86,8 +82,17 @@ jobs: - name: Commit formatted files if: env.CAN_RUN == 1 run: | - git add . - git commit -m "Formatted XAML files" + git add --renormalize *.xaml + git status --porcelain + if ((git status --porcelain) -eq $null) + { + gh pr comment ${{ github.event.issue.number }} -b "No XAML files changed." + "CAN_RUN=0" | Out-File -FilePath $env:GITHUB_ENV -Append + } + else + { + git commit -m "Formatted XAML files" + } - name: Push to PR if: env.CAN_RUN == 1 @@ -113,7 +118,7 @@ jobs: }' -F owner=$owner -F name=$name -F number=$number --jq '{Branch: .data.repository.pullRequest.headRef.name, Url: .data.repository.pullRequest.headRepository.url}' | ConvertFrom-Json $url = [UriBuilder]($data.Url) - $url.UserName = 'Personal Access Token' + $url.UserName = 'x-access-token' $url.Password = '${{ steps.generate.outputs.token }}' git push $url.Uri.AbsoluteUri pr:$($data.Branch) @@ -121,6 +126,10 @@ jobs: { gh pr comment ${{ github.event.issue.number }} -b "Successfully formatted XAML files." } + else + { + "CAN_RUN=0" | Out-File -FilePath $env:GITHUB_ENV -Append + } continue-on-error: true - name: Comment if failed