File: syntax.sh

package info (click to toggle)
baler 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 207,900 kB
  • sloc: python: 2,468; sh: 98; makefile: 7
file content (50 lines) | stat: -rwxr-xr-x 1,250 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

# This script is used to run the code quality tools on the codebase.

# Variables
CODEBASE="baler"
BLACK_OPTIONS="--check"
BLACK_APPLY_OPTIONS=""

# Function to check if the script is running in a CI environment
function is_ci() {
  if [ -n "$CI" ]; then
    return 0
  else
    return 1
  fi
}

# Function to run Black code formatter
function run_black() {
  echo "Running Black on the codebase..."
  if poetry run black ${BLACK_OPTIONS} ${CODEBASE}; then
    echo "Black completed successfully."
  else
    if is_ci; then
      echo "Black found issues in the codebase. Please fix them before committing."
      exit 1
    else
      local apply_fix
      echo "Black found issues in the codebase."
      read -p "Would you like to apply Black to fix the issues? (Y/n) " apply_fix

      if [[ "$apply_fix" =~ ^([yY][eE][sS]|[yY])$ ]] || [[ -z "$apply_fix" ]]; then
        echo "Applying Black to the codebase..."
        poetry run black ${BLACK_APPLY_OPTIONS} ${CODEBASE}
        echo "Black successfully applied to the codebase."
      else
        echo "Skipping Black auto-fix. Please fix the issues manually before committing."
      fi
    fi
  fi
}

# Main script
function main() {
  run_black
}

# Run the main function
main