From 1083ada28fe446c910370bac470d05959a905523 Mon Sep 17 00:00:00 2001 From: Sean Freeman Date: Wed, 29 Nov 2023 16:10:13 -0600 Subject: [PATCH 1/5] test pylint action --- .github/workflows/pylint.yml | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 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..bdf42306 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,69 @@ +name: Linting +on: + pull_request: + branches: + - '*' +permissions: + pull-requests: write + +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: 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: 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 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_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: | + Linting results by Pylint: + -------------------------- + ${{ steps.pr_score.outputs.MESSAGE}} + 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 383e9f70983742e236a11034cdd6d17f08043044 Mon Sep 17 00:00:00 2001 From: Fabian <97912636+fziegner@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:51:53 +0100 Subject: [PATCH 2/5] changed comparison from main to RC branch --- .github/workflows/pylint.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index bdf42306..f7dad81d 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -23,21 +23,31 @@ jobs: echo "SHA=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_OUTPUT id: git - - name: Switch to main branch + - name: Get RC branch name + run: | + git fetch --all + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "RC_BRANCH<<$EOF" >> $GITHUB_OUTPUT + echo "$(git branch -r --list 'origin/RC*' --sort=-committerdate | head -n 1 | sed 's/origin\///' | xargs)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + id: branch_name + + - name: Checkout RC branch uses: actions/checkout@v3 with: - ref: main + ref: ${{ steps.branch_name.outputs.RC_BRANCH }} - name: Install tobac and pylint run: | pip install . pip install --upgrade pylint - - name: Get pylint score of main branch + + - name: Get pylint score of RC branch run: | pylint tobac --disable=C --exit-zero id: main_score - - name: Switch to PR branch + - name: Checkout PR branch uses: actions/checkout@v3 with: ref: "${{ steps.git.outputs.SHA}}" @@ -62,7 +72,7 @@ jobs: Linting results by Pylint: -------------------------- ${{ steps.pr_score.outputs.MESSAGE}} - 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. + 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 ${{ steps.branch_name.outputs.RC_BRANCH}} 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 From 26768f5bf10e269121c6748f89eef1296a23d9da Mon Sep 17 00:00:00 2001 From: Fabian <97912636+fziegner@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:34:37 +0100 Subject: [PATCH 3/5] changed environment to mamba --- .github/workflows/pylint.yml | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index f7dad81d..6e172d7f 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -9,14 +9,27 @@ permissions: jobs: build: runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} steps: - name: Check out Git repository uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v3 + - name: Set up conda + uses: conda-incubator/setup-miniconda@v2 with: - python-version: '3.9' + miniforge-version: latest + miniforge-variant: mambaforge + channel-priority: strict + channels: conda-forge + show-channel-urls: true + use-only-tar-bz2: true + + - name: Install tobac and pylint + run: | + mamba install --yes pylint + pip install . - name: Store the PR branch run: | @@ -36,11 +49,6 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ steps.branch_name.outputs.RC_BRANCH }} - - - name: Install tobac and pylint - run: | - pip install . - pip install --upgrade pylint - name: Get pylint score of RC branch run: | @@ -50,12 +58,12 @@ jobs: - name: Checkout PR branch uses: actions/checkout@v3 with: - ref: "${{ steps.git.outputs.SHA}}" + 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 2) + OUTPUT_PART=$(pylint tobac --disable=C --exit-zero | tail -n 2) # but post entire output in the action details pylint tobac --disable=C --exit-zero # define random delimiter for multiline string @@ -71,8 +79,8 @@ jobs: message: | Linting results by Pylint: -------------------------- - ${{ steps.pr_score.outputs.MESSAGE}} - 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 ${{ steps.branch_name.outputs.RC_BRANCH}} branch. + ${{ steps.pr_score.outputs.MESSAGE }} + 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 ${{ steps.branch_name.outputs.RC_BRANCH }} 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 From b0f7f6027200efba020aa7badc90fe50c46628a2 Mon Sep 17 00:00:00 2001 From: Sean Freeman Date: Fri, 1 Dec 2023 11:38:46 -0600 Subject: [PATCH 4/5] update to use target branch name --- .github/workflows/pylint.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 6e172d7f..dca11561 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -36,19 +36,10 @@ jobs: echo "SHA=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_OUTPUT id: git - - name: Get RC branch name - run: | - git fetch --all - EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) - echo "RC_BRANCH<<$EOF" >> $GITHUB_OUTPUT - echo "$(git branch -r --list 'origin/RC*' --sort=-committerdate | head -n 1 | sed 's/origin\///' | xargs)" >> $GITHUB_OUTPUT - echo "$EOF" >> $GITHUB_OUTPUT - id: branch_name - - name: Checkout RC branch uses: actions/checkout@v3 with: - ref: ${{ steps.branch_name.outputs.RC_BRANCH }} + ref: ${{ github.base_ref }} - name: Get pylint score of RC branch run: | From fe1bad80ebe9e92db3755440dff78afe346b5bc0 Mon Sep 17 00:00:00 2001 From: Fabian <97912636+fziegner@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:19:21 +0100 Subject: [PATCH 5/5] changed linting message creation to updating exisiting comment --- .github/workflows/pylint.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index dca11561..bf25d384 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -64,15 +64,23 @@ jobs: echo "$EOF" >> "$GITHUB_OUTPUT" id: pr_score + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Linting results by Pylint + - name: Post result to PR - uses: mshick/add-pr-comment@v1 + uses: peter-evans/create-or-update-comment@v3 with: - message: | + issue-number: ${{ github.event.pull_request.number }} + comment-id: ${{ steps.comment.outputs.comment-id }} + edit-mode: replace + body: | Linting results by Pylint: -------------------------- ${{ steps.pr_score.outputs.MESSAGE }} - 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 ${{ steps.branch_name.outputs.RC_BRANCH }} branch. + 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 ${{ github.base_ref }} 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