Skip to content

WIP: Implement vulkan RHI #759

WIP: Implement vulkan RHI

WIP: Implement vulkan RHI #759

Workflow file for this run

name: clang-format
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- dev
workflow_dispatch:
inputs:
lint_mode:
description: 'Select lint mode: check_only, auto_commit, or create_pr'
required: true
default: 'check_only'
type: choice
options:
- check_only
- create_pr
- auto_commit
issue_comment:
types: [created] # Listen for new comments on issues/PRs
jobs:
clang-format-lint:
runs-on: ubuntu-latest
# Run if:
# - PR event
# - workflow_dispatch
# - issue_comment on a PR with /clang-format AND commenter is halx99
if: |
(github.event_name == 'pull_request') ||
(github.event_name == 'workflow_dispatch') ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
startsWith(github.event.comment.body, '/clang-format') &&
contains(fromJSON('["halx99"]'), github.event.comment.user.login))
steps:
# Reply start message when triggered by comment
- name: Reply start message
if: github.event_name == 'issue_comment'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.AX_BOT_TOKEN || github.token }}
issue-number: ${{ github.event.issue.number }}
body: |
👋 @${{ github.event.comment.user.login }} Command **/clang-format** received. Running code formatting, please wait...
# Get PR info when triggered by a comment
- name: Get PR info (for comment trigger)
if: github.event_name == 'issue_comment'
id: pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.AX_BOT_TOKEN || github.token }}
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue.number
});
core.setOutput('head_ref', pr.head.ref);
core.setOutput('head_repo', pr.head.repo.full_name);
# Determine lint_mode to auto_commit if triggered by /clang-format comment and store head commit sha
- name: Prepare clang-format lint
id: pp
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'issue_comment') {
$head_repo = "${{ steps.pr.outputs.head_repo }}"
$head_ref = "${{ steps.pr.outputs.head_ref }}"
}
elseif ($env:GITHUB_EVENT_NAME -eq 'pull_request') {
$head_repo = "${{ github.event.pull_request.head.repo.full_name }}"
$head_ref = "${{ github.event.pull_request.head.ref }}"
}
else {
$head_repo = "${{ github.repository }}"
$head_ref = "${{ github.head_ref || github.ref_name }}"
}
if (!$head_repo -or !$head_ref) {
Write-Error "❌ head_repo or head_ref is empty"
exit 1
}
if ($env:GITHUB_EVENT_NAME -eq 'issue_comment') {
echo "Set lint_mode=auto_commit for ${{ github.event.comment.user.login }} Command **/clang-format**"
$lint_mode = 'auto_commit'
}
else {
$lint_mode = "${{ inputs.lint_mode || 'check_only' }}"
}
echo "head_repo=$head_repo" >> ${env:GITHUB_OUTPUT}
echo "head_ref=$head_ref" >> ${env:GITHUB_OUTPUT}
echo "lint_mode=$lint_mode" >> ${env:GITHUB_OUTPUT}
Write-Host "head_repo=$head_repo, head_ref=$head_ref, lint_mode=$lint_mode"
# Checkout correct branch
- uses: actions/checkout@v5
with:
repository: ${{ steps.pp.outputs.head_repo }}
ref: ${{ steps.pp.outputs.head_ref }}
token: ${{ secrets.AX_BOT_TOKEN || github.token }}
- name: Run clang-format lint
uses: DoozyX/clang-format-lint-action@v0.20
with:
source: './axmol ./extensions ./tests ./templates'
exclude: './3rdparty ./extensions/ImGui/**/im* ./extensions/fairygui ./extensions/Live2D ./extensions/Effekseer ./extensions/scripting/lua-bindings/auto ./extensions/spine ./tests/cpp-tests/Source/Box2DTestBed/samples ./tests/fairygui-tests ./tests/live2d-tests ./extensions/**/*_generated.h'
extensions: 'h,cpp,c,mm'
clangFormatVersion: 20
inplace: True
# check_only mode
- name: Check for uncommitted changes
if: ${{ steps.pp.outputs.lint_mode == 'check_only' }}
shell: pwsh
run: |
git diff --quiet
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ clang-format check failed: Uncommitted formatting changes detected."
Write-Host "=== The following differences require formatting ==="
git --no-pager diff
Write-Host "===================================================="
exit 1
}
else {
Write-Host "✅ clang-format check passed: No formatting changes needed."
}
- name: Prepare for create pull request
if: ${{ steps.pp.outputs.lint_mode == 'create_pr' }}
id: ppr
shell: pwsh
run: |
$head_commit_sha = $(git rev-parse --short HEAD)
echo "head_commit_sha=$head_commit_sha" >> ${env:GITHUB_OUTPUT}
Write-Host "ppr: head_commit_sha=$head_commit_sha"
# create_pr mode
- name: Create pull request
if: ${{ steps.pp.outputs.lint_mode == 'create_pr' }}
id: cpr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.AX_BOT_TOKEN || github.token }}
push-to-fork: axmol-bot/axmol
commit-message: Committing clang-format changes
signoff: false
branch: clang_format_for_${{ steps.ppr.outputs.head_commit_sha }}
delete-branch: true
title: 'Committing clang-format changes ${{ steps.ppr.outputs.head_commit_sha }}'
body: |
RT
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
labels: |
clang-format
automated pr
pinned
assignees: axmol-bot
reviewers: halx99
draft: false
- name: Check pull request outputs
if: ${{ steps.pp.outputs.lint_mode == 'create_pr' && steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
# auto_commit mode (including comment trigger)
- name: Commit clang-format changes to PR source branch
if: ${{ steps.pp.outputs.lint_mode == 'auto_commit' }}
uses: EndBug/add-and-commit@v9
with:
author_name: axmol-bot
author_email: 116471739+axmol-bot@users.noreply.github.com
committer_name: GitHub Actions
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
message: 'Committing clang-format changes'
new_branch: ${{ steps.pp.outputs.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.AX_BOT_TOKEN || github.token }}
# Reply finish message after auto_commit success
- name: Reply finish message
if: ${{ success() && steps.pp.outputs.lint_mode == 'auto_commit' && github.event_name == 'issue_comment' }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.AX_BOT_TOKEN || github.token }}
issue-number: ${{ github.event.issue.number }}
body: |
✅ Formatting completed and changes have been committed to the PR branch: `${{ steps.pp.outputs.head_ref }}`.
@${{ github.event.comment.user.login }} please refresh to see the latest code.
# Reply failure message if job fails
- name: Reply failure message
if: ${{ failure() && github.event_name == 'issue_comment' }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.AX_BOT_TOKEN || github.token }}
issue-number: ${{ github.event.issue.number }}
body: |
❌ Formatting failed. Please check the GitHub Actions logs for details.