lgeiger / black-action

A GitHub action that runs black code formatter for Python
MIT License
190 stars 35 forks source link

Auto-push formatted code #2

Closed jneeven closed 4 years ago

jneeven commented 5 years ago

Implements #1, and should be seen as a minimal working product rather than finalized code. I got it working with the included example_workflow.yml file. Please ignore the many commits and only look at the end result.

Improvements are very welcome!

cclauss commented 5 years ago

It has been a month... What is the status of this PR?

@lgeiger Will you review/merge?

If not, @jneeven would you be willing to create a new Action in the Marketplace?

jneeven commented 5 years ago

@cclauss sure, would you be willing to do some testing beforehand? I merged a pull request from @Ahuge and was seeing some issues in one of my projects, but don't have time to look into the details right now (I think that it crashed on installing black or something). If you could verify that it works, I'd be happy to put it on the marketplace (though it is far from optimal yet).

Ahuge commented 5 years ago

Black updated and now requires the regex package. So we need gcc now. https://github.com/jneeven/black-action/compare/master...Ahuge:master

I followed a PR from https://github.com/lgeiger/black-action/pull/4

shahzebsiddiqui commented 4 years ago

I can't get my black workflow to autoformat python code. It looks like it tried to format but doesn't intercept this in precommit. Isn't there supposed to be a commit by some bot to make this happen otherwise how will change be applied. https://github.com/HPC-buildtest/buildtest-framework/blob/master/.github/workflows/black.yml

shahzebsiddiqui commented 4 years ago

So even if I push my code. The local branch has my code unformated. So a pull rebase doesn't change my code either. I can see when running black locally it formats all my code and then pushing it everything gets fixed. So it's not triggered properly on PR

cclauss commented 4 years ago

Look at the commits in this PR... https://github.com/TheAlgorithms/Python/pull/1779

The change to the first file was made by me in the first commit. The changes to the other three files was made in the second commit by the autoblack GitHub Action.

We use autoblack to add a second, automatic commit to a PR that black formats the code. This only succeeds if the author of the PR has write access to this repo.

Ahuge commented 4 years ago

Yeah I've got a fork that has things working too if you need. https://github.com/Ahuge/black-action

name: Black Code Formatting on PR

on: [pull_request]

jobs:
    pr-lint:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v1
              name: Checkout
            - uses: Ahuge/black-action@v1.0.3
              env:
                GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
                BLACK_ARGS: "."
shahzebsiddiqui commented 4 years ago

thanks @cclauss @Ahuge for quick response. I will certainly try out and see which one works. It would be nice to have it pushed to marketplace if it works.