Skip to content

qoj/7993

qoj/7993 #162

Workflow file for this run

name: Code Formatting
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install clang-format and dos2unix
run: |
sudo apt-get update
sudo apt-get install -y clang-format dos2unix
- name: Get Current Date
id: date
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Run dos2unix on All Files
run: find . -type f -exec dos2unix {} \;
- name: Commit dos2unix Changes
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add .
if git diff --staged --quiet; then
echo "No changes after dos2unix, skipping commit."
else
git commit -m "Applied dos2unix automatically (${{ env.CURRENT_DATE }})"
git push
fi
- name: Run clang-format on CPP Files
run: |
find . -iname "*.cpp" -exec clang-format -i --style=file {} \;
- name: Commit clang-format Changes
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add .
if git diff --staged --quiet; then
echo "No changes after clang-format, skipping commit."
else
git commit -m "Applied clang-format automatically (${{ env.CURRENT_DATE }})"
git push
fi