refactor: moved more logic components into core #569
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run clang-format | |
| on: | |
| pull_request_target: | |
| branches: | |
| - '*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| - uses: DoozyX/clang-format-lint-action@v0.18.1 | |
| with: | |
| extensions: 'c,cpp,h,hpp' | |
| clangFormatVersion: 18 | |
| inplace: True | |
| - name: Detect formatting changes | |
| id: changes | |
| run: | | |
| if git diff --quiet --exit-code; then | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | |
| { | |
| echo 'changed_files<<EOF' | |
| git diff --name-only | |
| echo 'EOF' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Classify pull request source | |
| id: pr_source | |
| run: | | |
| if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then | |
| echo "is_same_repo=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_same_repo=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Annotate formatting changes | |
| if: ${{ steps.changes.outputs.has_changes == 'true' }} | |
| run: | | |
| files='${{ steps.changes.outputs.changed_files }}' | |
| files="${files//$'\n'/%0A}" | |
| echo "::warning::clang-format updated these files:%0A$files" | |
| - name: Commit and push formatting fixes | |
| if: ${{ steps.changes.outputs.has_changes == 'true' && steps.pr_source.outputs.is_same_repo == 'true' }} | |
| run: | | |
| git config user.name "openastrotech-bot" | |
| git config user.email "openastrotech-bot@users.noreply.github.com" | |
| git add -A | |
| git commit -m "style: apply clang-format fixes" | |
| git push origin "HEAD:${{ github.event.pull_request.head.ref }}" | |
| - name: Fail for forked pull requests with formatting changes | |
| if: ${{ steps.changes.outputs.has_changes == 'true' && steps.pr_source.outputs.is_same_repo != 'true' }} | |
| run: | | |
| echo "Automatic formatting commits are only supported for branches in this repository." >&2 | |
| exit 1 |