Skip to content

Query about no throw registry iterators #102

Query about no throw registry iterators

Query about no throw registry iterators #102

Workflow file for this run

name: Run clang-format on PR comment
on:
issue_comment:
types: [ created ]
permissions:
pull-requests: write
jobs:
# Job 1: Run formatting in sandbox with no write permissions
format-code:
if: >
github.event.issue.pull_request &&
contains(github.event.comment.body, '!run-clang-format') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER'
)
runs-on: windows-latest
permissions:
pull-requests: read
contents: read
outputs:
pr-ref: ${{ steps.pr.outputs.ref }}
pr-sha: ${{ steps.pr.outputs.sha }}
pr-repo: ${{ steps.pr.outputs.repo }}
has-changes: ${{ steps.format.outputs.has-changes }}
steps:
- name: Get PR info
id: pr
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput('ref', pr.data.head.ref);
core.setOutput('sha', pr.data.head.sha);
core.setOutput('repo', pr.data.head.repo.full_name);
return pr.data.head.ref;
- name: Checkout base repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch PR branch
shell: cmd
run: |
git fetch origin pull/${{ github.event.issue.number }}/head:pr-head
git checkout pr-head
- name: Run clang-format
id: format
shell: pwsh
run: |
# 'run-clang-format' script needs 'VCINSTALLDIR' env (among maybe others) to be set
& cmd /c "call ./scripts/call-vcvars.cmd x64 && call ./scripts/format-changes.cmd origin/master"
if ($LASTEXITCODE -eq 0) {
"has-changes=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -NoNewline
} else {
"has-changes=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -NoNewline
}
# Don't let the exit code of 'git clang-format' cause this step to fail
exit 0
- name: Create patch
if: steps.format.outputs.has-changes == 'true'
shell: cmd
run: |
git diff > format-changes.patch
- name: Upload patch
if: steps.format.outputs.has-changes == 'true'
uses: actions/upload-artifact@v4
with:
name: format-patch
path: format-changes.patch
retention-days: 1
# Job 2: Apply changes with write permissions (runs trusted code only)
apply-changes:
needs: format-code
if: needs.format-code.outputs.has-changes == 'true'
runs-on: windows-latest
permissions:
contents: write
steps:
- name: Checkout base repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch PR branch
env:
PR_NUMBER: ${{ github.event.issue.number }}
shell: cmd
run: |
git fetch origin pull/%PR_NUMBER%/head:pr-head
git checkout pr-head
- name: Download patch
uses: actions/download-artifact@v4
with:
name: format-patch
- name: Apply patch
shell: cmd
run: |
git apply format-changes.patch
del format-changes.patch
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_REPO: ${{ needs.format-code.outputs.pr-repo }}
PR_REF: ${{ needs.format-code.outputs.pr-ref }}
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Run clang-format on PR changes"
# Try to push to fork repo (works if maintainer edits allowed)
git push https://x-access-token:$env:GITHUB_TOKEN@github.com/$env:PR_REPO HEAD:$env:PR_REF
# Job 3: Run CI workflow
run-ci:

Check failure on line 137 in .github/workflows/format.yml

View workflow run for this annotation

GitHub Actions / Run clang-format on PR comment

Invalid workflow file

The workflow is not valid. .github/workflows/format.yml (Line: 137, Col: 3): Error calling workflow 'microsoft/wil/.github/workflows/ci.yml@4ea066a7bd8a3f41400e7c0bf63175316678bdd6'. The workflow is requesting 'contents: read', but is only allowed 'contents: none'.
needs: apply-changes
uses: ./.github/workflows/ci.yml
with:
pr_number: ${{ github.event.issue.number }}
# Job 4: Comment on PR with results
comment-result:
needs: [format-code, apply-changes]
if: always() && needs.format-code.result != 'cancelled'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Comment success
if: needs.format-code.result == 'success' && (needs.apply-changes.result == 'success' || needs.format-code.outputs.has-changes == 'false')
uses: actions/github-script@v7
with:
script: |
const hasChanges = '${{ needs.format-code.outputs.has-changes }}' === 'true';
const message = hasChanges
? '✅ clang-format completed successfully! Code formatting has been applied and committed to this PR.'
: '✅ clang-format completed successfully! No formatting changes were needed.';
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
});
- name: Comment failure
if: needs.format-code.result == 'failure' || needs.apply-changes.result == 'failure'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '❌ clang-format failed. Please check the [action logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.'
});