Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run fmtcheck for every pullrequest #371

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- plugins/**
- tests/**
push:
branches:
- main
paths:
- plugins/**
- tests/**
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/fmtcheck.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF"$'\n'"$OUTPUT"$'\n'EOF >> $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
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
workflow_dispatch:
pull_request:
push:
branches:
- main
jobs:
ansible-lint:
name: ansible-lint
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- plugins/**
- tests/**
push:
branches:
- main
paths:
- plugins/**
- tests/**
Expand Down
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
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 .

fmtcheck:
autoflake --check plugins/modules/*.py
autoflake --check plugins/module_utils/*.py
autoflake --check --recursive tests/

black --check plugins/modules/*.py
black --check plugins/module_utils/*.py
black --check tests/

isort --check-only plugins/modules/*.py
isort --check-only plugins/module_utils/*.py
isort --check-only tests/

yamllint .

fmt_tools:
# ignore if file not found
-autoflake tools/generated_modules/*.py
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ sphinx_rtd_theme
antsibull-docs
sphinx
sphinx-ansible-theme
galaxy-importer
autoflake
black
isort
pycodestyle
Loading