DEV Community

Nasrul Hazim Bin Mohamad
Nasrul Hazim Bin Mohamad

Posted on

Automate Linting Python Scripts

Create a Github Action to lint your Python scripts, simply copy & paste the following snippet and place it in your repository - .github/workflows/lint.yml.

TLDR;

name: Lint
on: 
  - push
jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: autopep8
        id: autopep8
        uses: peter-evans/autopep8@v1
        with:
          args: --exit-code --recursive --in-place --aggressive --aggressive .
      - name: Commit autopep8 changes
        if: steps.autopep8.outputs.exit-code == 2
        run: |
          git config --global user.name '<your-name>'
          git config --global user.email '<your-email-address>'
          git commit -am "Automated autopep8 fixes"
          git push
Enter fullscreen mode Exit fullscreen mode

Do update the <your-name> and <your-email-address> accordingly and you are good to go.

Top comments (0)