Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions .github/workflows/format-xaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ 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

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: |
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand All @@ -113,14 +118,18 @@ 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)

if ($LASTEXITCODE -eq 0)
{
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
Expand Down