From 1747afb656b4762619906b4c9db94bca4242b0a6 Mon Sep 17 00:00:00 2001 From: Juli Date: Tue, 9 May 2023 15:07:37 -0600 Subject: [PATCH 1/9] add action for linting and posting score to PR --- .github/workflows/pylint.yml | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 00000000..3c48ccc5 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,41 @@ +name: Linting +on: + pull_request: + branches: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out Git repository + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.9' + - name: Install tobac and pylint + run: | + pip install . + pip install --upgrade pylint + + - name: Lint with pylint + # omit conventions, for minimum score use: --fail-under= + run: | + # use shell script to save only tail of output + OUTPUT_PART=$(pylint tobac --disable=C | tail -n 3) + # but post entire output in the action details + pylint tobac --disable=C --exit-zero + # define random delimiter for multiline string + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "MESSAGE<<$EOF" >> "$GITHUB_ENV" + echo "$OUTPUT_PART" >> "$GITHUB_ENV" + echo "$EOF" >> "$GITHUB_ENV" + + - name: Post result to PR + uses: mshick/add-pr-comment@v1 + with: + message: ${{ env.MESSAGE }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub token + allow-repeats: false # This is the default From 82a03298bc727adc78de5f61b1d6fdea08893a57 Mon Sep 17 00:00:00 2001 From: Juli Date: Wed, 10 May 2023 16:16:42 -0600 Subject: [PATCH 2/9] fixed unused imports in main modules --- tobac/feature_detection.py | 2 +- tobac/segmentation.py | 4 ---- tobac/tracking.py | 3 --- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tobac/feature_detection.py b/tobac/feature_detection.py index d36b83bc..ad178c01 100644 --- a/tobac/feature_detection.py +++ b/tobac/feature_detection.py @@ -316,7 +316,7 @@ def feature_detection_threshold( from skimage.measure import label from skimage.morphology import binary_erosion - from copy import deepcopy + if min_num != 0: warnings.warn( diff --git a/tobac/segmentation.py b/tobac/segmentation.py index dc379c1b..7d34a5a1 100644 --- a/tobac/segmentation.py +++ b/tobac/segmentation.py @@ -31,11 +31,7 @@ """ import logging - -import skimage import numpy as np - -from . import utils as tb_utils from .utils import internal as internal_utils diff --git a/tobac/tracking.py b/tobac/tracking.py index 0b7e2c1c..3f8b1ddb 100644 --- a/tobac/tracking.py +++ b/tobac/tracking.py @@ -20,12 +20,9 @@ """ import logging -from operator import is_ import numpy as np import pandas as pd import warnings -import math -from . import utils as tb_utils from .utils import internal as internal_utils from packaging import version as pkgvsn From bc223645c588759880e71de4f5a0dce2734721c1 Mon Sep 17 00:00:00 2001 From: Fabian <97912636+fziegner@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:05:17 +0100 Subject: [PATCH 3/9] fixed score comparison of branches and added short description --- .github/workflows/pylint.yml | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 3c48ccc5..92f97259 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -10,32 +10,59 @@ jobs: steps: - name: Check out Git repository uses: actions/checkout@v3 + - name: Set up Python uses: actions/setup-python@v3 with: python-version: '3.9' + + - name: Store the PR branch + run: | + echo "SHA=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_OUTPUT + id: git + + - name: Switch to main branch + uses: actions/checkout@v3 + with: + ref: main + - name: Install tobac and pylint run: | pip install . pip install --upgrade pylint - - name: Lint with pylint - # omit conventions, for minimum score use: --fail-under= + - name: Get pylint score of main branch + run: | + pylint tobac --disable=C --exit-zero + id: main_score + + - name: Switch to PR branch + uses: actions/checkout@v3 + with: + ref: "${{ steps.git.outputs.SHA}}" + + - name: Get pylint score of PR branch run: | # use shell script to save only tail of output - OUTPUT_PART=$(pylint tobac --disable=C | tail -n 3) + OUTPUT_PART=$(pylint tobac --disable=C | tail -n 2) # but post entire output in the action details pylint tobac --disable=C --exit-zero # define random delimiter for multiline string EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) - echo "MESSAGE<<$EOF" >> "$GITHUB_ENV" - echo "$OUTPUT_PART" >> "$GITHUB_ENV" - echo "$EOF" >> "$GITHUB_ENV" + echo "MESSAGE<<$EOF" >> "$GITHUB_OUTPUT" + echo "$OUTPUT_PART" >> "$GITHUB_OUTPUT" + echo "$EOF" >> "$GITHUB_OUTPUT" + id: pr_score - name: Post result to PR uses: mshick/add-pr-comment@v1 with: - message: ${{ env.MESSAGE }} + message: | + Linting results by Pylint: + -------------------------- + ${{ steps.pr_score.outputs.MESSAGE}} + The linting score is an indicator that reflects how well the code adheres to Pylint’s coding standards and quality metrics. + A decrease usually indicates new code was added that does not meet style guidelines or has potential errors. repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub token allow-repeats: false # This is the default From d1aad9c048e067df673bebac3d70e7d163d7c5d6 Mon Sep 17 00:00:00 2001 From: Fabian <97912636+fziegner@users.noreply.github.com> Date: Thu, 23 Nov 2023 19:43:58 +0100 Subject: [PATCH 4/9] updated linting explanation --- .github/workflows/pylint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 92f97259..0522bdeb 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -61,8 +61,8 @@ jobs: Linting results by Pylint: -------------------------- ${{ steps.pr_score.outputs.MESSAGE}} - The linting score is an indicator that reflects how well the code adheres to Pylint’s coding standards and quality metrics. - A decrease usually indicates new code was added that does not meet style guidelines or has potential errors. + The linting score is an indicator that reflects how well your code version follows Pylint’s coding standards and quality metrics with respect to the main branch. + A decrease usually indicates your new code does not fully meet style guidelines or has potential errors. repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub token allow-repeats: false # This is the default From d80d6cb7650488adff38f644047080fd6ac59163 Mon Sep 17 00:00:00 2001 From: kukulies Date: Tue, 28 Nov 2023 06:31:10 -0700 Subject: [PATCH 5/9] fixed import issues --- tobac/feature_detection.py | 2 +- tobac/segmentation.py | 2 ++ tobac/tracking.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tobac/feature_detection.py b/tobac/feature_detection.py index ad178c01..d36b83bc 100644 --- a/tobac/feature_detection.py +++ b/tobac/feature_detection.py @@ -316,7 +316,7 @@ def feature_detection_threshold( from skimage.measure import label from skimage.morphology import binary_erosion - + from copy import deepcopy if min_num != 0: warnings.warn( diff --git a/tobac/segmentation.py b/tobac/segmentation.py index 7d34a5a1..a717d8b6 100644 --- a/tobac/segmentation.py +++ b/tobac/segmentation.py @@ -31,7 +31,9 @@ """ import logging +import skimage import numpy as np +from . import utils as tb_utils from .utils import internal as internal_utils diff --git a/tobac/tracking.py b/tobac/tracking.py index 3f8b1ddb..0b7e2c1c 100644 --- a/tobac/tracking.py +++ b/tobac/tracking.py @@ -20,9 +20,12 @@ """ import logging +from operator import is_ import numpy as np import pandas as pd import warnings +import math +from . import utils as tb_utils from .utils import internal as internal_utils from packaging import version as pkgvsn From fd367f38596511f98a93c2964b901814a8451419 Mon Sep 17 00:00:00 2001 From: Julia Kukulies <44163060+JuliaKukulies@users.noreply.github.com> Date: Tue, 28 Nov 2023 07:37:46 -0700 Subject: [PATCH 6/9] Update imports in segmentation.py --- tobac/segmentation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tobac/segmentation.py b/tobac/segmentation.py index 21113d55..3fcab9f6 100644 --- a/tobac/segmentation.py +++ b/tobac/segmentation.py @@ -31,11 +31,10 @@ """ import copy import logging -import skimage import numpy as np import iris.cube -import numpy as np +import skimage import pandas as pd from typing_extensions import Literal from typing import Union, Callable From ce726fbe1ba2cc4dc92264928cf63a9b23644403 Mon Sep 17 00:00:00 2001 From: Sean Freeman Date: Wed, 29 Nov 2023 15:45:36 -0600 Subject: [PATCH 7/9] test adding permissions explicitly to workflow --- .github/workflows/pylint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 0522bdeb..ad10cc21 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -6,6 +6,7 @@ on: jobs: build: + permissions: write-all runs-on: ubuntu-latest steps: - name: Check out Git repository From 337621ed426161b4376ea02ebd029300bb88e9ae Mon Sep 17 00:00:00 2001 From: Sean Freeman Date: Wed, 29 Nov 2023 15:51:13 -0600 Subject: [PATCH 8/9] update permissions --- .github/workflows/pylint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index ad10cc21..44bbc430 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -6,8 +6,9 @@ on: jobs: build: - permissions: write-all runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - name: Check out Git repository uses: actions/checkout@v3 From db341060ce6388f82794227d59950fb4109cf26b Mon Sep 17 00:00:00 2001 From: Sean Freeman Date: Wed, 29 Nov 2023 15:58:54 -0600 Subject: [PATCH 9/9] update permissions to be workflow-wide --- .github/workflows/pylint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 44bbc430..17d8c66a 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -3,12 +3,12 @@ on: pull_request: branches: - '*' +permissions: + pull-requests: write jobs: build: runs-on: ubuntu-latest - permissions: - pull-requests: write steps: - name: Check out Git repository uses: actions/checkout@v3