Skip to content

create generic branch #3

create generic branch

create generic branch #3

# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0
# GitHub Action that uses
# isort, black, mypy and pylint to reformat the Python code in an incoming pull request.
# clang-format to reformat the C++ code in an incoming pull request.
# If all code in the pull request is compliant with Black and clang-format then this Action
# does nothing. Otherwise, it will print the files which need to be reformatted and raise an error.
name: Check Code Quality
on:
# run pipeline on push event of main branch
push:
branches:
- main
# run pipeline on pull request
pull_request:
# run pipeline on merge queue
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-code-quality:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Upgrade pip
run: pip install --upgrade pip
- name: Install and run isort
run: |
pip install isort
isort .
- name: Install and run black
run: |
pip install black[jupyter]
black .
- name: Install and run mypy
run: |
pip install mypy
mypy .
- name: Install and run pylint
run: |
pip install pylint .
pylint power_grid_model
git restore README.md
- name: Install and run clang-format
run: |
sudo apt-get update && sudo apt-get install -y clang-format-15
find . -regex '.*\.\(h\|c\|cpp\|hpp\|cc\|cxx\)' -exec clang-format-15 -style=file -i {} \;
- name: If needed raise error
run: |
if [[ `git status --porcelain --untracked-files=no` ]]; then
echo "Formatting not correct! See below the files which need to be reformatted!"
git status --porcelain --untracked-files=no
exit 1
fi
- name: Check generated code
if: success()
run: |
pip install -r code_generation/requirements.txt
python code_generation/code_gen.py
if [ -n "$(git status --porcelain)" ]; then
echo
echo "The following files are outdated or were manually updated:"
git status --porcelain
exit 1
else
echo
echo "All the generated files are up to date."
fi