Skip to content

Close coroutine if container coro is cancelled, attempt to fix #352 #210

Close coroutine if container coro is cancelled, attempt to fix #352

Close coroutine if container coro is cancelled, attempt to fix #352 #210

Workflow file for this run

name: Development Build
on:
push:
paths-ignore: [docs/**, README.md]
branches: [ "development-0.4.X.X" ]
jobs:
# ------------------------------
# Builds the code
# ------------------------------
build:
name: Build on node Python 3.9
outputs:
tag: ${{steps.tag.outputs.tag}}
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- 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
- name: Calculate Version
id: tag
run: |
TAG=$(cat $GITHUB_WORKSPACE/.version)$GITHUB_RUN_NUMBER
echo "Tag: $TAG"
echo "::set-output name=tag::$TAG"
# ------------------------------
# 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
needs: [build, turn-on-env]
outputs:
failure_rate: ${{steps.pytest.outputs.failure_rate}}
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.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
continue-on-error: true
id: pytest
env:
MEROSS_EMAIL: ${{ secrets.MEROSS_EMAIL }}
MEROSS_EMAIL_MFA: ${{ secrets.MEROSS_EMAIL_MFA }}
MEROSS_PASSWORD: ${{ secrets.MEROSS_PASSWORD }}
run: |
pip install .
# 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`
passed_tests=`cat .report.json | jq .summary.passed`
failed_tests=`cat .report.json | jq .summary.failed`
failure_rate=`echo $failed_tests/$total_tests*100 | bc -l`
echo "::set-output name=failure_rate::$failure_rate"
- name: Upload pytest test results
uses: actions/upload-artifact@v2
with:
name: pytest-results
path: junit/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload pytest test results
uses: actions/upload-artifact@v2
with:
name: pytest-results-html
path: htmlcov/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
# Upload to CODECOV
- name: codecov-upload
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-merossiot-python-dev
flags: unittests
verbose: true
# ------------------------------
# Turn off ENV
# ------------------------------
turn-off-env:
runs-on: ubuntu-latest
needs: [test]
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\"}"
name: Turn off test environment
if: ${{ always() }}
# ------------------------------
# Pre-Release on DEV
# ------------------------------
pre-release:
name: Pre-Release on GitHub
runs-on: ubuntu-latest
needs: [build, test]
# Only publish release if the failure rate is < 10 %
if: needs.test.outputs.failure_rate < 10
steps:
- uses: actions/checkout@v2
- name: Calculate Version
id: tag
run: |
TAG=$(cat $GITHUB_WORKSPACE/.version)
echo "Tag: $TAG"
echo "tag=$TAG" >> $GITHUB_ENV
- name: Create a Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag
tag_name: ${{env.tag}}-${{github.RUN_NUMBER}}
# The name of the release. For example, `Release v1.0.1`
release_name: Development release ${{env.tag}}-${{github.RUN_NUMBER}}
# `true` to identify the release as a prerelease. `false` to identify the release as a full release. Default: `false`
prerelease: true