peter-evans / autopep8

A GitHub action for autopep8, a tool that automatically formats Python code to conform to the PEP 8 style guide.
MIT License
84 stars 15 forks source link

Action fails on "Commit autopep8 changes" #34

Closed PuneetKohli closed 4 years ago

PuneetKohli commented 4 years ago

We have often got this failure and are unable to debug it:

image

Our workflow:

  1. Submit PR
  2. Run Autopep8 action
  3. Immediately commit code to the same branch/PR

The action code is attached below for reference:

name: autopep8
on: pull_request
jobs:
  autopep8:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1.1.0
      - name: autopep8
        id: autopep8
        uses: peter-evans/autopep8@v1.1.0
        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 'Redacted'
          git config --global user.email 'redacted@users.noreply.github.com'
          git remote set-url origin https://x-access-token:${{ secrets.self_lint }}@github.com/$GITHUB_REPOSITORY
          git checkout $GITHUB_HEAD_REF
          git commit -am "self: lint fix"
          git push
PuneetKohli commented 4 years ago

This is based on : https://github.com/peter-evans/autopep8#direct-push-with-on-pull_request-workflows

peter-evans commented 4 years ago

Hi @PuneetKohli, thank you for opening this issue.

I think this is due to some recent changes to the actions/checkout action. Please try this updated workflow that should fix the problem.

name: autopep8
on: pull_request
jobs:
  autopep8:
    # Check if the PR is not from a fork
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
        with:
          ref: ${{ github.head_ref }}
      - name: autopep8
        id: autopep8
        uses: peter-evans/autopep8@v1.1.0
        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 'Peter Evans'
          git config --global user.email 'peter-evans@users.noreply.github.com'
          git remote set-url origin https://x-access-token:${{ secrets.REPO_ACCESS_TOKEN }}@github.com/${{ github.repository }}
          git commit -am "Automated autopep8 fixes"
          git push

I will update the documentation to reflect this new change.

peter-evans commented 4 years ago

By the way, it's not recommend to use actions/checkout@v1.1.0. That is an unreleased version. It's best to follow the major version with actions/checkout@v1.

See https://github.com/actions/checkout#v110-unreleased Comments in an unmerged changelog also confirm it's not a good idea to use that version. https://github.com/actions/checkout/pull/64/files#diff-4ac32a78649ca5bdd8e0ba38b7006a1e

PuneetKohli commented 4 years ago

We had the issue with checkout@v1 which upgrading to v1.1.0 fixed in a particular repo. That probably wasn't the root cause which is why it cropped up again.

We will try downgrading with the new workflow

PuneetKohli commented 4 years ago

Also does aggressive need to be there twice for autopep8 or is that a bug/typo?

peter-evans commented 4 years ago

Also does aggressive need to be there twice for autopep8 or is that a bug/typo?

It's not a typo, that's the way autopep8 specifies "aggressive level 2." You are free to change the autopep8 arguments to whatever you like. Check the documentation out here: https://github.com/hhatto/autopep8#usage

PuneetKohli commented 4 years ago

Thanks for that.

The fix does work for us!