项目作者: rickstaa

项目描述 :
Runs the psf/black formatter to check/format your python code.
高级语言: Shell
项目地址: git://github.com/rickstaa/action-black.git
创建时间: 2021-01-06T14:52:37Z
项目社区:https://github.com/rickstaa/action-black

开源协议:MIT License

下载


Action-black GitHub Action

Test
release
GitHub release (latest SemVer)
action-bumpr supported

[!IMPORTANT]\
The official psf/black action has been released! 🚀 - Because of this, this repository’s action is no longer trivial. Therefore, you are advised to use the official black action. Some features in this action are not in the official action. The differences between the two actions are documented in https://github.com/rickstaa/action-black/issues/10. If you think features are missing, please open a pull request.

This action runs the black formatter to check/format your python code on a push or pull request. It is similar to reviewdog/action-black that can annotate the black changes required with Reviewdog. However, this version also allows you to format the code using GitHub actions (see #advanced-use-cases).

Quickstart

In it’s simplest form this action can be used to check/format your code using the black formatter.

  1. name: black-action
  2. on: [push, pull_request]
  3. jobs:
  4. linter_name:
  5. name: runner / black formatter
  6. runs-on: ubuntu-latest
  7. steps:
  8. - uses: actions/checkout@v4
  9. - uses: rickstaa/action-black@v1
  10. with:
  11. black_args: ". --check"

Inputs

black_args

optional: Black input arguments. Defaults to . --check --diff.

fail_on_error

optional: Exit code when black formatting errors are found [true, false]. Defaults to ‘true’.

Outputs

is_formatted

Boolean specifying whether any files were formatted using the black formatter.

Advanced use cases

Annotate changes

This action can be combined with reviewdog/action-suggester also to annotate any possible changes (uses git diff).

  1. name: black-action
  2. on: [push, pull_request]
  3. jobs:
  4. linter_name:
  5. name: runner / black
  6. runs-on: ubuntu-latest
  7. steps:
  8. - uses: actions/checkout@v4
  9. - name: Check files using the black formatter
  10. uses: rickstaa/action-black@v1
  11. id: action_black
  12. with:
  13. black_args: "."
  14. - name: Annotate diff changes using reviewdog
  15. if: steps.action_black.outputs.is_formatted == 'true'
  16. uses: reviewdog/action-suggester@v1
  17. with:
  18. tool_name: blackfmt

Commit changes or create a pull request

This action can be combined with peter-evans/create-pull-request to also apply the annotated changes to the repository.

  1. name: black-action
  2. on: [push, pull_request]
  3. jobs:
  4. linter_name:
  5. name: runner / black
  6. runs-on: ubuntu-latest
  7. steps:
  8. - uses: actions/checkout@v4
  9. - name: Check files using the black formatter
  10. uses: rickstaa/action-black@v1
  11. id: action_black
  12. with:
  13. black_args: "."
  14. - name: Create Pull Request
  15. if: steps.action_black.outputs.is_formatted == 'true'
  16. uses: peter-evans/create-pull-request@v6
  17. with:
  18. token: ${{ secrets.GITHUB_TOKEN }}
  19. title: "Format Python code with psf/black push"
  20. commit-message: ":art: Format Python code with psf/black"
  21. body: |
  22. There appear to be some python formatting errors in ${{ github.sha }}. This pull request
  23. uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
  24. base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch
  25. branch: actions/black

Contributing

Feel free to open an issue if you have ideas on how to make this GitHub action better or if you want to report a bug! All contributions are welcome. :rocket: Please consult the contribution guidelines for more information.