77 update zhinstzipython package to zhinstcore #281
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: QMI Python CI runner on pull request | |
# This runner runs on a pull request to main. | |
on: | |
pull_request: | |
branches: [ "main" ] | |
paths-ignore: | |
- README.md | |
- CHANGELOG.md | |
- .gitignore | |
- ACKNOWLEDGEMENTS.md | |
- LICENSE.md | |
- CONTRIBUTING.md | |
- TESTING.md | |
env: | |
# minimum pylint code quality score (max. 10) | |
PYLINT_MIN_SCORE: "9.00" | |
# minimum code coverage (goal: 90%; max. 100%) | |
COVERAGE_MIN_PERC: "90" | |
# maximum code complexity (goal: <= 30; unbounded) | |
COMPLEXITY_MAX_SCORE: "30" | |
# this should be a comma separated list | |
SOURCE_DIRS: "qmi/" | |
BADGES_DIR: ".github/badges" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
max-parallel: 3 | |
matrix: | |
python-version: ["3.8", "3.9", "3.10"] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
sudo apt-get update -qy | |
sudo apt-get install -y bc | |
pip install --upgrade pip | |
pip install -e '.[dev]' | |
pip install anybadge | |
- name: setup git config | |
run: | | |
git config user.name "Badge Bot" | |
git config user.mail "<>" | |
chmod u+w $BADGES_DIR | |
- name: pylint | |
if: always() | |
run: | | |
pylint --score=yes --load-plugins=pylint.extensions.mccabe --max-complexity=$COMPLEXITY_MAX_SCORE $SOURCE_DIRS | tee pylint.log | |
SCORE=$( tail -n 2 pylint.log | grep -o '[0-9]\{1,2\}\.[0-9]\{2\}' | head -n 1 ) | |
echo "Pylint score: $SCORE" | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l pylint -v $SCORE -f $BADGES_DIR/pylint.svg 2=red 4=orange 8=yellow 10=green; fi | |
exit $( echo "$SCORE < $PYLINT_MIN_SCORE" | bc ) | |
- name: upload pylint test results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pylint-results | |
path: pylint.log | |
- name: mypy | |
if: always() | |
run: | | |
mypy --namespace-packages $SOURCE_DIRS | tee mypy.log | |
if [ -n "$( tail -n 1 mypy.log | grep -e '^Succes' )" ]; then RESULT="pass"; else RESULT="fail"; fi | |
echo "Mypy result: $RESULT" | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l mypy -v $RESULT -f $BADGES_DIR/mypy.svg fail=red pass=green; fi | |
if [[ "$RESULT" = *"pass"* ]]; then exit 0; else exit 1; fi | |
- name: upload mypy test results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: mypy-results | |
path: mypy.log | |
- name: coverage | |
if: always() | |
run: | | |
if coverage run --branch --source=$SOURCE_DIRS -m unittest discover --start-directory=tests --pattern="test_*.py"; then RESULT="pass"; else RESULT="fail"; fi | |
coverage report --show-missing --fail-under=$COVERAGE_MIN_PERC | tee coverage.log | |
COVERAGE_PERC=$(grep "TOTAL" coverage.log | grep -Eo '[0-9.]+%' | sed 's/%//') | |
echo "Coverage: $COVERAGE_PERC%" | |
exit $( echo "$COVERAGE_PERC < $COVERAGE_MIN_PERC" | bc ) | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l coverage -v $COVERAGE_PERC -f $BADGES_DIR/coverage.svg 60=red 80=orange 100=green; fi | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l tests -v $RESULT -f $BADGES_DIR/tests.svg fail=red pass=green; fi | |
- name: upload coverage results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-results | |
path: coverage.log | |
- name: push all internal commits | |
if: always() | |
run: | | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/pylint.svg; fi | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/mypy.svg; fi | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/coverage.svg; fi | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/tests.svg; fi | |
if [ "${{ matrix.python-version }}" = "3.10" ]; then if git commit -m "commit badges" 2>/dev/null; then git push; fi; fi |