Skip to content

Update install_requires #266

Update install_requires

Update install_requires #266

Workflow file for this run

name: Build Test and Release
on:
push:
paths-ignore: [docs/**, README.md, examples/**]
branches: [ 0.4.X.X ]
pull_request:
branches: [ 0.4.X.X ]
jobs:
# ----------------------------------
# BUILD
# ----------------------------------
build:
name: Build on Python ${{matrix.python_version}}
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ['3.7', '3.8', '3.9', '3.10']
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup Python ${{matrix.python_version}}
uses: actions/setup-python@v2
with:
python-version: ${{matrix.python_version}}
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build artifact
run: python setup.py sdist bdist_wheel
# -----------------------------------
# Turn on ENV
# -----------------------------------
turn-on-env:
name: Turn on test environment
runs-on: ubuntu-latest
env:
HOMEASSISTANT_TOKEN: ${{ secrets.HOMEASSISTANT_TOKEN }}
steps:
- name: Powering on the dev-environment
run: |
curl -X POST -k --header "Content-Type: application/json" --header "Authorization: Bearer $HOMEASSISTANT_TOKEN" https://milano.geniola.it/api/services/switch/turn_on -d "{\"entity_id\":\"switch.meross_lab\"}"
# ---------------------------------
# Testing
# ---------------------------------
test:
name: Testing
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ['3.7', '3.8', '3.9', '3.10']
max-parallel: 1
outputs:
failure_rate_python_3_7: ${{steps.pytest.outputs.failure_rate_3_7}}
failure_rate_python_3_8: ${{steps.pytest.outputs.failure_rate_3_8}}
failure_rate_python_3_9: ${{steps.pytest.outputs.failure_rate_3_9}}
failure_rate_python_3_10: ${{steps.pytest.outputs.failure_rate_3_10}}
needs: [build, turn-on-env]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{matrix.python_version}}
uses: actions/setup-python@v2
with:
python-version: ${{matrix.python_version}}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest --upgrade
pip install pytest-html --upgrade
pip install pytest-cov --upgrade
pip install pytest-json-report --upgrade
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Wait a bit before running tests
run: |
echo "Waiting 120 seconds before starting..."
sleep 120
echo "Waiting done."
- name: Test with pytest
id: pytest
env:
MEROSS_EMAIL: ${{ secrets.MEROSS_EMAIL }}
MEROSS_PASSWORD: ${{ secrets.MEROSS_PASSWORD }}
run: |
pip install .
pip install -r requirements-dev.txt
# Set credentials into memory
TOKEN=$(meross_api_cli auth login --email $MEROSS_EMAIL --password "$MEROSS_PASSWORD" --api-base-url "https://iotx-us.meross.com" | base64 -w0)
# Run test
__MEROSS_CREDS=$TOKEN pytest tests --suppress-tests-failed-exit-code --json-report --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html --html=junit/test-results.html --self-contained-html
# Invalidate token
__MEROSS_CREDS=$TOKEN meross_api_cli auth logout
# Parse test outcomes
total_tests=`cat .report.json | jq .summary.total`
failed_tests=`cat .report.json | jq .summary.failed`
failure_rate=`echo $failed_tests/$total_tests*100 | bc -l`
pythonv=`echo failure_rate_${{ matrix.python_version }} | sed 's/\./_/'`
echo "Setting pythonv=$pythonv"
echo "::set-output name=$pythonv::$failure_rate"
echo "Python ${{ matrix.python_version }}: $failure_rate %" > results-${{ matrix.python_version }}.txt
continue-on-error: true
- name: Upload pytest test TXT results
uses: actions/upload-artifact@v2
with:
name: test-report-${{ matrix.python_version }}
path: results-${{ matrix.python_version }}.txt
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload pytest test RAW results
uses: actions/upload-artifact@v2
with:
name: pytest-results-${{ matrix.python_version }}
path: junit/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload pytest HTML test results
uses: actions/upload-artifact@v2
with:
name: pytest-results-html-${{ matrix.python_version }}
path: htmlcov/
- name: Upload pytest JSON test json results
uses: actions/upload-artifact@v2
with:
name: pytest-results-json-${{ matrix.python_version }}
path: .report.json
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
# ------------------------------
# Turn off ENV
# ------------------------------
turn-off-env:
name: Turn off test environment
runs-on: ubuntu-latest
env:
HOMEASSISTANT_TOKEN: ${{ secrets.HOMEASSISTANT_TOKEN }}
steps:
- name: Powering on the dev-environment
run: |
curl -X POST -k --header "Content-Type: application/json" --header "Authorization: Bearer $HOMEASSISTANT_TOKEN" https://milano.geniola.it/api/services/switch/turn_off -d "{\"entity_id\":\"switch.meross_lab\"}"
if: ${{ always() }}
# -----------------------------
# Release checks
# -----------------------------
release_checks:
runs-on: ubuntu-latest
needs: [ test ]
outputs:
should_publish: ${{ steps.release_decision.outputs.should_release }}
steps:
- name: Print current configuration
run: |
echo "Python 3.7: ${{ needs.test.outputs.failure_rate_python_3_7 }}%"
echo "Python 3.8: ${{ needs.test.outputs.failure_rate_python_3_8 }}%"
echo "Python 3.9: ${{ needs.test.outputs.failure_rate_python_3_9 }}%"
echo "Python 3.10: ${{ needs.test.outputs.failure_rate_python_3_10 }}%"
- name: Save test output artifacts
run: |
touch "test_pass_rates.txt"
echo "Python 3.7: ${{ needs.test.outputs.failure_rate_python_3_7 }}%" >> "test_pass_rates.txt"
echo "Python 3.8: ${{ needs.test.outputs.failure_rate_python_3_8 }}%" >> "test_pass_rates.txt"
echo "Python 3.9: ${{ needs.test.outputs.failure_rate_python_3_9 }}%" >> "test_pass_rates.txt"
echo "Python 3.10: ${{ needs.test.outputs.failure_rate_python_3_10 }}%" >> "test_pass_rates.txt"
- name: Upload test pass rates
uses: actions/upload-artifact@v2
with:
name: test-pass-rates
path: test_pass_rates.txt
- name: Take release decision
id: release_decision
run: |
failure_threshold=10
echo "Current minimum pass-threshold: $failure_threshold %"
should_release=`echo "${{ needs.test.outputs.failure_rate_python_3_7 }} < $failure_threshold && ${{ needs.test.outputs.failure_rate_python_3_8 }} < $failure_threshold && ${{ needs.test.outputs.failure_rate_python_3_9 }} < $failure_threshold && ${{ needs.test.outputs.failure_rate_python_3_10 }} < $failure_threshold" | bc -l`
echo "::set-output name=should_release::$should_release"
echo "Release decision: $should_release"
if [[ $should_release -ne 1 ]]; then
echo "Failing as one of the tests did hit the maximum failure threshold."
exit 1
fi
# -----------------------------
# Build and Release
# -----------------------------
release:
runs-on: ubuntu-latest
needs: [release_checks]
if: ${{ success() }}
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install twine
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build artifact
run: python setup.py sdist bdist_wheel --universal
- name: Calculate Version
id: tag
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: |
TAG=$(cat $GITHUB_WORKSPACE/.version)
echo "Tag: $TAG"
echo "tag=$TAG" >> $GITHUB_ENV
- name: Release on GitHub
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{env.tag}}
release_name: Version ${{env.tag}}
- name: Release on Pypi
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: |
twine upload -u "$TWINE_USERNAME" -p "$TWINE_PASSWORD" dist/*