From e13c60a43298e27bc9fe457a8bfd503c9a1f3c50 Mon Sep 17 00:00:00 2001 From: EC2 Default User Date: Wed, 29 Nov 2023 17:14:48 +0000 Subject: [PATCH] Created a Github Workflow that checks files with black upon pushing them to the repo --- .github/workflows/presubmit.yml | 12 ++++++++++++ check.sh | 27 +++++++++++++++++++++++++++ requirements-dev.txt | 1 + 3 files changed, 40 insertions(+) create mode 100644 .github/workflows/presubmit.yml create mode 100644 check.sh create mode 100644 requirements-dev.txt diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml new file mode 100644 index 00000000..4f88a650 --- /dev/null +++ b/.github/workflows/presubmit.yml @@ -0,0 +1,12 @@ +name: Presubmit +on: [push] +jobs: + Presubmit: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - uses: actions/checkout@v3 + - run: python3 -m pip install -r requirements-dev.txt + - run: ./check.sh diff --git a/check.sh b/check.sh new file mode 100644 index 00000000..2b9962a5 --- /dev/null +++ b/check.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +CHANGED=0 +if [[ $# = 1 ]] && [[ "$1" = "--fix" ]]; then + if ! black --check . &> /dev/null; then + black . || exit 1 + CHANGED=1 + fi + + if ! isort --check . &> /dev/null; then + isort . || exit 1 + CHANGED=1 + fi +elif [[ $# -gt 0 ]]; then + echo "Usage: $0 [--fix]" > /dev/stderr + exit 1 +fi + +# if this fails with "black: command not found" you need to install black +# python3 -m pip install black +echo Running black to check formatting... +if ! black --check --diff --quiet .; then + echo "FAIL: formatting" + exit 1 +fi + + diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..7e66a17d --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1 @@ +black