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

Add Pylint to Workflow #373

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Changes from 2 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
79 changes: 79 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to use python 3.9? pylint doesn't seem to yet work with 3.12, but 3.11 works fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can change it to 3.11


- name: Store the PR branch
run: |
echo "SHA=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_OUTPUT
id: git

- name: Get RC branch name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to grab the merging PR branch name. Let me look into that and see if that's possible

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 }}

- name: Install tobac and pylint
run: |
pip install .
pip install --upgrade pylint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to use conda/mamba to create the environment, consistent with other actions, rather than pip?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some trouble getting pylint to work with the conda environment but I'll take another look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah fair, if it causes more work then it's probably not worth changing it. Seems to work fine for me via conda locally as long as it isn't using python 3.12

Also good to check that we can install tobac with pip!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's working now. I just forgot to specify the shell in which pylint is supposed to run.


- name: Get pylint score of RC branch
run: |
pylint tobac --disable=C --exit-zero
id: main_score

- name: Checkout 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}}
<sub>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.<sup>
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
Loading