From 13885968e3e79eda93dd88454acd00c0ac2ec672 Mon Sep 17 00:00:00 2001 From: kpj Date: Sun, 27 Feb 2022 15:21:09 +0100 Subject: [PATCH] Add GitHub Actions workflow to check black formatting --- .../workflow-scripts/check-trailing-newline | 37 ------------------- .../check-trailing-whitespace | 26 ------------- .github/workflows/ci.yml | 15 ++++---- 3 files changed, 7 insertions(+), 71 deletions(-) delete mode 100755 .github/workflow-scripts/check-trailing-newline delete mode 100755 .github/workflow-scripts/check-trailing-whitespace diff --git a/.github/workflow-scripts/check-trailing-newline b/.github/workflow-scripts/check-trailing-newline deleted file mode 100755 index 6973a5e3e..000000000 --- a/.github/workflow-scripts/check-trailing-newline +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# Verify that all text files end in a trailing newline. - -# Exit on first failing command. -set -e - -# Exit on unset variable. -set -u - -success=0 - -function is_plaintext_file() { - local file="$1" - if [[ $file == *.svg ]]; then - echo "" - return - fi - file --brief "${file}" | grep text -} - -# Split strings on newlines. -IFS=' -' -for file in $(git ls-files) -do - if [[ -z $(is_plaintext_file "${file}") ]]; then - continue - fi - - if ! [[ -z "$(tail -c 1 "${file}")" ]]; then - printf "File must end in a trailing newline: %s\n" "${file}" >&2 - success=255 - fi -done - -exit "${success}" diff --git a/.github/workflow-scripts/check-trailing-whitespace b/.github/workflow-scripts/check-trailing-whitespace deleted file mode 100755 index fe7a2bdd6..000000000 --- a/.github/workflow-scripts/check-trailing-whitespace +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# Check for trailing whitespace at end of lines. - -# Exit on first failing command. -set -e -# Exit on unset variable. -set -u - -FOUND_TRAILING_WHITESPACE=0 - -while read -r line; do - if grep \ - "\s$" \ - --line-number \ - --with-filename \ - --binary-files=without-match \ - --exclude="*.svg" \ - --exclude="*.eps" \ - "${line}"; then - echo "ERROR: Found trailing whitespace" >&2; - FOUND_TRAILING_WHITESPACE=1 - fi -done < <(git ls-files) - -exit "${FOUND_TRAILING_WHITESPACE}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13dc2c74c..38a4754f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,20 +81,19 @@ jobs: run: | cd src/ pycodestyle - whitespace: + formatting: runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v2 - - name: Ensure there are no trailing spaces - run: | - .github/workflow-scripts/check-trailing-whitespace - - - name: Ensure all text files end with a trailing newline - run: | - .github/workflow-scripts/check-trailing-whitespace + name: Run black + uses: psf/black@stable + with: + options: "--check --diff --verbose" + src: "./src" + version: "22.1.0" tests: runs-on: ubuntu-20.04