From 19b7ec5082e1aac76c19adfaa49faec6eb9a00ed Mon Sep 17 00:00:00 2001 From: Raffaello Bonghi Date: Tue, 14 Jan 2025 20:01:46 +0000 Subject: [PATCH] Add auto style code CI --- .github/workflows/build-and-push.yml | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 06c5b7c4..74ae101a 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -11,9 +11,40 @@ env: # https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions jobs: + auto_style: + name: Auto style code + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install autopep8 + run: | + python -m pip install --upgrade pip + pip install flake8 autopep8 + - name: Auto style code with autopep8 + run: autopep8 --in-place --aggressive --aggressive --max-line-length 180 . + - name: Check for changes + run: | + if [[ `git status --porcelain` ]]; then + echo "There are changes after auto-styling the code." + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "Auto style code with autopep8" + exit 1 + else + echo "No changes detected." + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build: name: Test on python ${{ matrix.python-version }} runs-on: ubuntu-latest + needs: [auto_style] strategy: # max-parallel: 1 matrix: