Search code examples
github-actions

black formatter complains that a file should be formatted but fails to do so


I'm having trouble getting actions to format any files that are not black formatting compatible. I have the following actions:

name: Neptune-AI WorkFlow

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
      
      - name: Install Python Dependencies
        run: |
            if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

      - name: Lint with flake8
        run: |
          flake8 . --max-line-length=85 --statistics
        continue-on-error: false
      
      - name: black formatter
        uses: rickstaa/action-black@v1
        with:
          black_args: ". --check"
      - name: Annotate diff changes using reviewdog
        if: steps.action_black.outputs.is_formatted == 'true'
        uses: reviewdog/action-suggester@v1
        with:
          tool_name: blackfmt

My actions fails with the following error:

[action-black] Checking python code using the black formatter...
would reformat /github/workspace/neptunelearn/markov_models/markov_switch.py

Oh no! 💥 💔 💥
1 file would be reformatted, 24 files would be left unchanged.

How do I tell actions to reformat the file as it sees necessary? Thanks!


Solution

  • I see in the README that if the output of is_formatted is true you can use reviewdog with the id of the step, which you don't have

      - name: black formatter
        uses: rickstaa/action-black@v1
        id: action_black /// call it whatever you like
        with:
          black_args: ". --check"
      - name: Annotate diff changes using reviewdog
        if: steps.action_black.outputs.is_formatted == 'true' /// action_black is the id of the previous step as your example
        uses: reviewdog/action-suggester@v1
        with:
          tool_name: blackfmt