From 5204f788f9374244c497f3d8a9099d77c4dfbc24 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 29 Aug 2024 11:23:43 +0200 Subject: [PATCH] Use MegaLinter for linting in workflows --- .github/workflows/linter.yml | 45 ++++++++++++++++++++++++++++++++++++ .github/workflows/python.yml | 29 ----------------------- .mega-linter.yml | 14 +++++++++++ pyproject.toml | 3 ++- 4 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/linter.yml create mode 100644 .mega-linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 000000000..aeaae1195 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,45 @@ +--- + # MegaLinter GitHub Action configuration file + # More info at https://megalinter.io + name: MegaLinter + on: + push: + branches: "master" + pull_request: + + jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + permissions: + # Give the linter write permission to comment on PRs (if PR is not from fork) + issues: write + pull-requests: write + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + # MegaLinter + - name: MegaLinter + id: ml + # You can override MegaLinter flavor used to have faster performances + # More info at https://megalinter.io/flavors/ + uses: oxsecurity/megalinter/flavors/python@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Validate whole codebase on pushes and only changes on pull requests + # VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push'}} + VALIDATE_ALL_CODEBASE: true + + # Upload MegaLinter artifacts + - name: Archive production artifacts + if: success() || failure() + uses: actions/upload-artifact@v4 + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c55f53af5..e43dea684 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -6,36 +6,7 @@ on: pull_request: jobs: - lint: - runs-on: ubuntu-latest - name: Lint - steps: - - uses: actions/checkout@v4 - - - uses: actions/cache@v4 - id: cache - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.11 - - - name: Install dependencies - run: | - pip install -U pip - pip install tox flake8 - - - name: flake8 critical lint - run: tox -e flake8-critical - test: - needs: lint - name: "Python ${{ matrix.python-version }}" runs-on: ubuntu-latest diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 000000000..c821cc9c8 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,14 @@ +# All available variables are described in documentation +# https://megalinter.io/configuration/ + +LINTER_RULES_PATH: . + +ENABLE_LINTERS: + - PYTHON_BLACK + - PYTHON_FLAKE8 + +# Make workflow fail even on non blocking errors +FORMATTERS_DISABLE_ERRORS: false + +PYTHON_BLACK_CONFIG_FILE: pyproject.toml +PYTHON_FLAKE8_CONFIG_FILE: tox.ini diff --git a/pyproject.toml b/pyproject.toml index 67fbabe0f..a7814eef5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,7 +89,8 @@ write_to = "src/argus/version.py" [tool.black] line-length = 120 -exclude = ''' +# Exclude files even when passed directly as argument (for MegaLinter) +force-exclude = ''' ( /( \.eggs # exclude a few common directories in the