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

implementing precommit hooks as a github action #23

Open
GavinHuttley opened this issue Feb 14, 2023 · 4 comments
Open

implementing precommit hooks as a github action #23

GavinHuttley opened this issue Feb 14, 2023 · 4 comments
Assignees
Labels

Comments

@GavinHuttley
Copy link
Collaborator

We want to avoid code style issues when doing reviews of PRs.

We need black and isort linters to start with. Setup with a GitHub action run on each PR.

Ideally, these would be applied by developers before the push to their own GitHub fork of cogent3.

Question: If these are setup on cogent3#develop, do forks also run them?

@khiron
Copy link
Collaborator

khiron commented Mar 20, 2023

github action that runs black and isort on all code on push to the repository

.github/workflows/linters.yml

name: Format code using black and isort
# modified from https://towardsdatascience.com/black-with-git-hub-actions-4ffc5c61b5fe
# caching https://stackoverflow.com/questions/59127258/how-can-i-use-pip-cache-in-github-actions
# black integration https://black.readthedocs.io/en/stable/integrations/github_actions.html
# isort integration https://pycqa.github.io/isort/docs/configuration/github_action.html



on:
  push:
    branches: [ master ]

jobs:
  linters:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Format code with black 
        run: |
          pip install black==21.12b0
          black .
      - name: Format code with isort
        run: |
          pip install  isort==5.10.1
          isort .
      - name: Commit changes
        uses: EndBug/add-and-commit@v9
        with:
          author_name: ${{ github.actor }}
          author_email: ${{ github.actor }}@users.noreply.github.com
          message: "Format code with black and sort imports with isort"
          add: "."

1 TODO: find a way to only lint changed code to improve performance

@khiron
Copy link
Collaborator

khiron commented Mar 20, 2023

Lint all code checked into local .git

#!/bin/sh

source ./env/Scripts/activate
black .
isort .

#echo "Black and isort ran successfully"
#exit 0

1: TODO: lint only changed code

@fredjaya
Copy link
Collaborator

fredjaya commented Nov 1, 2023

@GavinHuttley
Copy link
Collaborator Author

@khiron see my comments on #48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants