Skip to content

Modernize clang-format file #10

Modernize clang-format file

Modernize clang-format file #10

Workflow file for this run

name: clang-format check for ls1
on:
push:
# pushes to master
branches: [ master ]
pull_request:
# PRs to master
branches: [ master ]
# abort old runs if a new one is started
concurrency:
group: ${{ github.head_ref }}-format-test
cancel-in-progress: true
jobs:
clang-format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install clang-format
run: sudo apt-get install -y clang-format
- name: Run clang-format and check for differences
run: |
# Run clang-format and get changes
clang-format -i $(find src -name "*.h" -or -name "*.cpp")
git diff --name-only > diff_files.log
- name: Check changes
id: check_diff
run: |
if [ -s diff_files.log ]; then
echo "Formatting issues detected!"
echo "formatting_issues=true" >> "$GITHUB_ENV"
else
echo "No formatting issues found"
echo "formatting_issues=false" >> "$GITHUB_ENV"
fi
- name: Post comment if issues found
if: env.formatting_issues == 'true'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ':warning: The CI detected formatting issues in this pull request. '
+ 'Please run clang-format locally to resolve them.\n'
+ 'Details are shown in the [job log](https://github.com/'
+ context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId + ').'
})
- name: Exit with failure if clang-format found issues
if: env.formatting_issues == 'true'
run: |
echo "Formatting issues detected!"
echo "Format the following files properly:"
cat diff_files.log
exit 0