Skip to content

Modernize clang-format file #14

Modernize clang-format file

Modernize clang-format file #14

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@v4
- 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@v7
# 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 "#### :warning: Formatting issues detected!" >> $GITHUB_STEP_SUMMARY
echo "Format the following files properly:" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat diff_files.log >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# exit 1