@@ -59,19 +59,28 @@ runs:
5959 - name : Run Python Lint
6060 run : |
6161 echo "::notice::Using python version ${INPUTS_PYTHON_VERSION}"
62- echo "::debug::Debug is ${RUNNER_DEBUG}"
62+
63+ # set python command
6364 if [[ "${OSTYPE}" == "msys" ]]; then
6465 PYTHON_CMD=python
6566 else
6667 PYTHON_CMD="python${INPUTS_PYTHON_VERSION}"
6768 fi
69+
70+ # upgrade pip
6871 "${PYTHON_CMD}" -mpip install --upgrade pip
72+
73+ # set up linter variables
6974 linters=('ruff' 'flake8' 'pylint' 'mypy' 'pyright' 'pytype' 'fixit')
7075 install_flake8_formatter_linters=('ruff', 'flake8')
7176 EXTRA_PIP_FLAGS=''
7277 LINTER_VERSION_CONSTRAINT=''
7378 EXTRA_LINTER_SCRIPT_FLAGS=''
79+
80+ # check we're using a valid linter
7481 if [[ "${linters[*]}" =~ (^|[^[:alpha:]])${INPUTS_LINTER}([^[:alpha:]]|$) ]]; then
82+
83+ # collect version choices, if they've been made
7584 if [[ "${INPUTS_LINTER}" == "fixit" ]]; then
7685 if [[ "${INPUTS_FIXIT_VERSION}" == "latest" ]]; then
7786 LINTER_VERSION_CONSTRAINT=' >1'
@@ -106,21 +115,30 @@ runs:
106115 fi
107116 fi
108117 fi
109- "${PYTHON_CMD}" -mpip install "${INPUTS_LINTER}${LINTER_VERSION_CONSTRAINT}" ${EXTRA_PIP_FLAGS} || ( echo "::error::${INPUTS_LINTER}${LINTER_VERSION_CONSTRAINT} failed to install for Python ${INPUTS_PYTHON_VERSION}" && exit 1 )
118+
119+ # install linter
120+ if ! "${PYTHON_CMD}" -mpip install "${INPUTS_LINTER}${LINTER_VERSION_CONSTRAINT}" ${EXTRA_PIP_FLAGS}; then
121+ echo "::error::${INPUTS_LINTER}${LINTER_VERSION_CONSTRAINT} failed to install for Python ${INPUTS_PYTHON_VERSION}"
122+ # if it is fixit on 3.7, just exit 0, we know it's not available
123+ if [[ "${INPUTS_LINTER}" == "fixit" && "${INPUTS_PYTHON_VERSION}" == "3.7" ]]; then
124+ exit 0
125+ fi
126+ exit 1
127+ fi
128+
129+ # install flake8-sarif-formatter if needed
110130 if [[ "${install_flake8_formatter_linters[*]}" =~ (^|[^[:alpha:]])${INPUTS_LINTER}([^[:alpha:]]|$) ]]; then
111131 echo "::notice::installing flake8_sarif_formatter for ${INPUTS_LINTER}"
112132 "${PYTHON_CMD}" -mpip install flake8-sarif-formatter || ( echo "::error::flake8-sarif-formatter failed to install for Python ${INPUTS_PYTHON_VERSION}" && exit 1 )
113133 fi
114134
135+ # set debug output
115136 if [[ "${RUNNER_DEBUG}" == "1" ]]; then
116137 EXTRA_LINTER_SCRIPT_FLAGS=" --debug"
117138 fi
118139
119- "${PYTHON_CMD}" "${GITHUB_ACTION_PATH}"/python_lint.py "${INPUTS_LINTER}" --target="${INPUTS_TARGET}" --output="${GITHUB_WORKSPACE}/${INPUTS_OUTPUT}" ${EXTRA_LINTER_SCRIPT_FLAGS}
120-
121- retval=$?
122-
123- if [[ $retval -ne 0 ]]; then
140+ # run linter
141+ if ! "${PYTHON_CMD}" "${GITHUB_ACTION_PATH}"/python_lint.py "${INPUTS_LINTER}" --target="${INPUTS_TARGET}" --output="${GITHUB_WORKSPACE}/${INPUTS_OUTPUT}" ${EXTRA_LINTER_SCRIPT_FLAGS}; then
124142 # don't fail "hard" if it's known failures that we cannot account for (yet)
125143 # pytype doesn't support 3.11+ yet
126144 if [[ "${INPUTS_LINTER}" == "pytype" && "${INPUTS_PYTHON_VERSION}" =~ ^3\.(1[1-9]|[2-9][0-9])$ ]]; then
0 commit comments