From fc0a0d0a8b8bbe383096455aa942cee508aa4386 Mon Sep 17 00:00:00 2001 From: Sumanth Lingappa Date: Fri, 23 Feb 2024 10:39:26 +0530 Subject: [PATCH 1/3] run fmtcheck for every pullrequest Signed-off-by: Sumanth Lingappa --- .github/workflows/fmtcheck.yml | 70 ++++++++++++++++++++++++++++++++++ Makefile | 18 +++++++++ pyproject.toml | 1 + requirements.txt | 5 ++- 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/fmtcheck.yml diff --git a/.github/workflows/fmtcheck.yml b/.github/workflows/fmtcheck.yml new file mode 100644 index 000000000..131d46a56 --- /dev/null +++ b/.github/workflows/fmtcheck.yml @@ -0,0 +1,70 @@ +--- +name: Fmt Check +on: + workflow_dispatch: + pull_request: + push: + branches: + - main +jobs: + fmtcheck: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Find Pull Request + id: find-pull-request + uses: jwalton/gh-find-current-pr@v1 + with: + # Can be "open", "closed", or "all". Defaults to "open". + state: open + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ steps.find-pull-request.outputs.number }} + comment-author: 'github-actions[bot]' + body-includes: There are some formatting issues in your code. + - name: Delete previous comment + if: steps.fc.outputs.comment-id != '' + uses: actions/github-script@v6 + with: + script: | + github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: ${{ steps.fc.outputs.comment-id }} + }) + - name: Install prerequisites + run: pip install -r requirements.txt + - name: Run Fmtcheck + id: fmtcheck + continue-on-error: true + run: | + set +e + set +x + make fmtcheck >fmtcheck.log 2>&1 + echo "exit_code=$?" >> $GITHUB_OUTPUT + OUTPUT=$(cat fmtcheck.log) + cat fmtcheck.log + echo "report<> $GITHUB_OUTPUT + - name: Create comment + if: steps.fmtcheck.outputs.exit_code != 0 + id: create-comment + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ steps.find-pull-request.outputs.number }} + body: | + There are some formatting issues in your code. Please fix them to ensure the quality of your code. + ${{steps.fmtcheck.outputs.report}} + reactions: rocket + + - name: Fail if fmtcheck run had errors + if: steps.fmtcheck.outputs.exit_code != 0 + run: exit 1 diff --git a/Makefile b/Makefile index b6383a523..abea7b491 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,24 @@ fmt: yamlfmt . +fmtcheck: + autoflake --check plugins/modules/*.py + autoflake --check plugins/module_utils/*.py + autoflake --check tools/module_generator.py + autoflake --check --recursive tests/ + + black --check plugins/modules/*.py + black --check plugins/module_utils/*.py + black --check tools/module_generator.py + black --check tests/ + + isort --check-only plugins/modules/*.py + isort --check-only plugins/module_utils/*.py + isort --check-only tools/module_generator.py + isort --check-only tests/ + + yamllint . + fmt_tools: # ignore if file not found -autoflake tools/generated_modules/*.py diff --git a/pyproject.toml b/pyproject.toml index 26bb9f218..7b367b742 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ multi_line_output = 3 in-place = true remove-unused-variables = true remove-all-unused-imports = true +quiet = true [tool.docformatter] in-place = true \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2037686d6..7f3b01e79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,7 @@ sphinx_rtd_theme antsibull-docs sphinx sphinx-ansible-theme -galaxy-importer \ No newline at end of file +autoflake +black +isort +pycodestyle From bfad6d1d2f6b1a6140ed9c43fe0e78b67e6f1743 Mon Sep 17 00:00:00 2001 From: Sumanth Lingappa Date: Fri, 23 Feb 2024 10:42:17 +0530 Subject: [PATCH 2/3] removed fmt and fmtcheck for tools directory Signed-off-by: Sumanth Lingappa --- Makefile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Makefile b/Makefile index abea7b491..b59b3fb2f 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,14 @@ fmt: autoflake plugins/modules/*.py autoflake plugins/module_utils/*.py - autoflake tools/module_generator.py autoflake --recursive tests/ black plugins/modules/*.py black plugins/module_utils/*.py - black tools/module_generator.py black tests/ isort plugins/modules/*.py isort plugins/module_utils/*.py - isort tools/module_generator.py isort tests/ yamlfmt . @@ -19,17 +16,14 @@ fmt: fmtcheck: autoflake --check plugins/modules/*.py autoflake --check plugins/module_utils/*.py - autoflake --check tools/module_generator.py autoflake --check --recursive tests/ black --check plugins/modules/*.py black --check plugins/module_utils/*.py - black --check tools/module_generator.py black --check tests/ isort --check-only plugins/modules/*.py isort --check-only plugins/module_utils/*.py - isort --check-only tools/module_generator.py isort --check-only tests/ yamllint . From 29ecf22cfd5463604bbe2627adf702ef9768d0c7 Mon Sep 17 00:00:00 2001 From: Sumanth Lingappa Date: Fri, 23 Feb 2024 10:44:37 +0530 Subject: [PATCH 3/3] restricted push target to only main branch. this will make actions not to run on pull_request for push. there is already pull_request target running for pull_request Signed-off-by: Sumanth Lingappa --- .github/workflows/bandit.yml | 2 ++ .github/workflows/lint.yml | 2 ++ .github/workflows/test.yml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/.github/workflows/bandit.yml b/.github/workflows/bandit.yml index e3faf1f6c..d275b2d5f 100644 --- a/.github/workflows/bandit.yml +++ b/.github/workflows/bandit.yml @@ -7,6 +7,8 @@ on: - plugins/** - tests/** push: + branches: + - main paths: - plugins/** - tests/** diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f52d910af..eaedc4ab3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,8 @@ on: workflow_dispatch: pull_request: push: + branches: + - main jobs: ansible-lint: name: ansible-lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a2b2b780..4ab9f78b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,8 @@ on: - plugins/** - tests/** push: + branches: + - main paths: - plugins/** - tests/**