From fb2af07583009a1ec10cd3917b72952c2b4f260a Mon Sep 17 00:00:00 2001 From: Bikouo Aubin <79859644+abikouo@users.noreply.github.com> Date: Wed, 29 Mar 2023 07:55:53 +0200 Subject: [PATCH] PR AutoFixing via GHA (#600) auto commit changelog and black formatting fixes --- .github/workflows/test.yml | 76 ++++++++++++++++++++++++++++++++++++++ tox.ini | 9 ++++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..6be8440d18 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,76 @@ +name: CI +concurrency: + group: ${{ github.head_ref }} + cancel-in-progress: true + +on: + pull_request: + types: + - opened + - reopened + - labeled + - unlabeled + - synchronize + branches: + - main + - stable-* + tags: + - '*' + +jobs: + auto_changelog: + name: changelog / black formatting + runs-on: ubuntu-latest + steps: + - name: Checkout the collection repository + uses: actions/checkout@v3 + with: + fetch-depth: "0" + + - name: Set up Python '3.9' + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + # black should be defined as input parameter of the action + - name: Install python dependencies + run: | + pip install -U pyyaml pygithub tox + shell: bash + + - name: Download script + run: >- + curl -o /tmp/add_changelog.py + https://raw.githubusercontent.com/abikouo/gha_testing/main/tools/add_changelog.py + + - name: Validate or add pull request changelog + run: + python3 /tmp/add_changelog.py + env: + PR_REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + + - name: Run black check + id: black_check + continue-on-error: true + run: | + tox -e black -vv 2>/tmp/black_check.txt + shell: bash + + - name: Run black formatting + run: | + tox -e black_format -vv -- $(grep "would reformat" /tmp/black_check.txt | cut -d ' ' -f3 | tr '\n' ' ') + shell: bash + if: steps.black_check.outcome != 'success' + + - name: (debug only) list files in diff + run: | + git status + shell: bash + if: steps.black_check.outcome != 'success' + + - name: commit and push changes + id: commit + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "automated changes for changelog and/or black formatting" diff --git a/tox.ini b/tox.ini index 491046ec3a..ab7f890e0c 100644 --- a/tox.ini +++ b/tox.ini @@ -26,6 +26,13 @@ deps = commands = black -v --check --diff {toxinidir}/plugins {toxinidir}/tests +[testenv:black_format] +deps = + {[testenv:black]deps} + +commands = + black -v {posargs} + [testenv:linters] deps = yamllint @@ -33,6 +40,6 @@ deps = {[testenv:black]deps} commands = - black -v --check --diff {toxinidir}/plugins {toxinidir}/tests + {[testenv:black]commands} yamllint -s {toxinidir} flake8 {toxinidir}