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

Suggest push to repository action in README #13

Closed thedrow closed 4 years ago

thedrow commented 4 years ago

Here's the workflow I've been thinking about introducing to my repositories: 1) Someone opens a PR. 2) This action is run. 3) We push the correctly formatted code to their branch if the branch isn't their master branch.

The github-push-action can assist us in doing so. Would you like me to try and let you know if that workflow works?

peter-evans commented 4 years ago

I think the workflow you describe is totally doable. To be honest, the main reason I put this autopep8 action together (which is just a simple wrapper) was to test and showcase another action I wrote, create-pull-request. That can be used for a similar workflow:

  1. A PR is created and autopep8 action runs
  2. A second PR is created by create-pull-request, the base of which is the first PR's branch.
  3. The second PR is merged into the first PR to pass the autopep8 check

I should probably improve the README and add some more realistic example workflows.

peter-evans commented 4 years ago

I worked on this and updated the README with a more realistic workflow similar to the one you describe. Had to make some changes to the action and expose the exit code of autopep8 for it to work.

I also had a think about your suggestion to commit directly to the branch and remembered why it wouldn't work so well. There is a deliberate limitation imposed by GitHub Actions that an action cannot trigger other workflows. From the documentation:

An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

https://help.github.com/en/articles/events-that-trigger-workflows#example-using-more-than-one-event

I contacted GitHub support for clarification on a similar issue that you can read about here. https://github.com/peter-evans/create-pull-request/issues/48

So what would happen is that when you commit the fixed code directly to the pull request branch, that event would not trigger the on: pull_request checks to run again. I think this is why having it raise a PR works better. The action of merging the PR allows the on: pull_request checks to run again and verify that the original PR passes the autopep8 check.

thedrow commented 4 years ago

That's exactly why I'm not giving up on other CI services and use actions only for automation.

peter-evans commented 4 years ago

I have a workflow example for direct push to the pull request branch working. Please see the following section of the README.

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

thedrow commented 4 years ago

Yes that works wonderfully!