diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2cc2e967f..6702eb85d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,3 +39,32 @@ jobs: - name: Run tests run: | pytest + + black: + strategy: + matrix: + version: [3.11] + os: [ubuntu-latest] + runs-on: ${{matrix.os}} + steps: + - name: Checking out repository + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 + - name: Setting up python + uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0 + - name: Fetching Base Branch + # We have to explicitly fetch the base branch as well + run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}" + - name: Install black + run: | + python3 -m pip install black==23.3 + - name: Check if modified files are formatted + run: | + # The filter lowercase `d` means to exclude deleted files. + git diff "${GITHUB_BASE_REF?}" --name-only --diff-filter=d \ + -- '*.py' \ + | xargs --no-run-if-empty black --check --diff --verbose + - name: Instructions for fixing the above linting errors + if: failure() + run: | + printf "You can fix formatting by running 'black' on the modified python files:\n" + printf " git diff ${GITHUB_BASE_REF?} --name-only -- '*.py' ':!third_party' | xargs black\n" \ No newline at end of file