Skip to content

Create pr-format-check.yml action #11

Create pr-format-check.yml action

Create pr-format-check.yml action #11

Workflow file for this run

on:
pull_request:
branches:
- main
jobs:
clang_format_check:
name: Check Clang Format
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up clang-format
run: sudo apt-get install clang-format
- name: Fetch main branch
run: git fetch origin main:main
- name: Get commit ID of main branch
run: |
MAIN_COMMIT=$(git rev-parse origin/main)
echo "Commit ID of main branch: $MAIN_COMMIT"
- name: Check code formatting
run: |
git clang-format --style=firmware/.clang-format --diff $MAIN_COMMIT..HEAD '*.cpp' '*.h'
- name: Check for changes
id: check_changes
run: |
git diff --exit-code || (echo "Code is not formatted properly. Please run clang-format and commit the changes." && exit 1)
- name: Complete
if: steps.check_changes.outcome == 'success'
run: echo "Code is properly formatted."