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

Add black to workflow #44

Closed
gcattan opened this issue Apr 17, 2022 · 5 comments · Fixed by #136
Closed

Add black to workflow #44

gcattan opened this issue Apr 17, 2022 · 5 comments · Fixed by #136
Labels
question Further information is requested

Comments

@gcattan
Copy link
Collaborator

gcattan commented Apr 17, 2022

@qbarthelemy @sylvchev
There is an issue on pyriemann repo about using black to auto format the code.
I wonder if we could tried this here. What do you think?

name: black-action
on: [push, pull_request]
jobs:
  linter_name:
    name: runner / black
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Check files using the black formatter
        uses: rickstaa/action-black@v1
        id: action_black
        with:
          black_args: "."
      - name: Create Pull Request
        if: steps.action_black.outputs.is_formatted == 'true'
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          title: "Format Python code with psf/black push"
          commit-message: ":art: Format Python code with psf/black"
          body: |
            There appear to be some python formatting errors in ${{ github.sha }}. This pull request
            uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
          base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch
          branch: actions/black
@gcattan
Copy link
Collaborator Author

gcattan commented Apr 17, 2022

@toncho FYI

@sylvchev
Copy link
Member

Yes, we speak about this. It is possible to convert the repo to use black formatting, the major drawback is that it messes up with the history of commits and that tools like git blame are obscured afterwards.
What is you take on this @qbarthelemy?

@gcattan
Copy link
Collaborator Author

gcattan commented Apr 19, 2022

In the example above, when we will open a PR, the action will open a new pull request against the branch on which is based the initial PR. Once reviewed, the changes will be merged into this initial PR and included in the commit history of the PR.

@sylvchev
Copy link
Member

Thanks for the explanation. This action seems a little bit complicated, especially for a tool like black that is made to be automatic and straightforward. If we want to use black, it is better to simply use it in pre-commit or as a linting test (as proposed in the official doc)

@gcattan
Copy link
Collaborator Author

gcattan commented Apr 19, 2022

A pre-commit hook could be complicated to share because they are not included into version control (except may be with Husky).
The example runs two actions in two different steps: one for black, the other to create a pull request. It is documented here:
https://github.com/rickstaa/action-black/
An a live example in my sample repository: gcattan/git-quality-check#11
That said, we could keep it simple, and just push black formatting as a commit inside the same branch of the PR.

@gcattan gcattan added the question Further information is requested label Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants