Giter Club home page Giter Club logo

action-black's Introduction

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 rickstaa#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.

name: black-action
on: [push, pull_request]
jobs:
  linter_name:
    name: runner / black formatter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: rickstaa/action-black@v1
        with:
          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).

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: Annotate diff changes using reviewdog
        if: steps.action_black.outputs.is_formatted == 'true'
        uses: reviewdog/action-suggester@v1
        with:
          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.

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

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. ๐Ÿš€ Please consult the contribution guidelines for more information.

action-black's People

Contributors

rickstaa avatar karbassi avatar renovate-bot avatar bwc9876 avatar gabrys avatar renovate[bot] avatar tarukumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.