tests #1907
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
# GitHub Actions configuration **EXAMPLE**, | |
# MODIFY IT ACCORDING TO YOUR NEEDS! | |
# Reference: https://docs.github.com/en/actions | |
name: tests | |
on: | |
push: | |
# Avoid using all the resources/limits available by checking only | |
# relevant branches and tags. Other branches can be checked via PRs. | |
branches: [main] | |
tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version | |
pull_request: # Run in every PR | |
workflow_dispatch: # Allow manually triggering the workflow | |
schedule: | |
# Run roughly every 15 days at 00:00 UTC | |
# (useful to check if updates on dependencies break the package) | |
- cron: '0 14,22 * * MON-SAT' | |
concurrency: | |
group: >- | |
${{ github.workflow }}-${{ github.ref_type }}- | |
${{ github.event.pull_request.number || github.sha }} | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
wheel-distribution: ${{ steps.wheel-distribution.outputs.path }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: {fetch-depth: 0} # deep clone for setuptools-scm | |
- uses: actions/setup-python@v4 | |
with: {python-version: "3.10"} | |
- name: Run static analysis and format checkers | |
run: pipx run pre-commit run --all-files --show-diff-on-failure | |
- name: Build package distribution files | |
run: pipx run --spec tox==3.27.1 tox -e clean,build -- --wheel | |
- name: Record the path of wheel distribution | |
id: wheel-distribution | |
run: echo "::set-output name=path::$(ls dist/*.whl)" | |
- name: Store the distribution files for use in other stages | |
# `tests` and `publish` will use the same pre-built distributions, | |
# so we make sure to release the exact same package that was tested | |
uses: actions/upload-artifact@v3 | |
with: | |
name: python-distribution-files | |
path: dist/ | |
retention-days: 1 | |
test: | |
needs: prepare | |
strategy: | |
matrix: | |
python: | |
- "3.8" | |
- "3.10" # newest Python that is stable | |
platform: | |
- ubuntu-latest | |
# - macos-latest | |
# - windows-latest | |
runs-on: ${{ matrix.platform }} | |
environment: pico-w-ids | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Retrieve pre-built distribution files | |
uses: actions/download-artifact@v3 | |
with: {name: python-distribution-files, path: dist/} | |
- name: Run tests | |
run: >- | |
pipx run --spec tox==3.27.1 tox | |
--installpkg '${{ needs.prepare.outputs.wheel-distribution }}' | |
-- -rFEx --durations 10 --color yes | |
- name: Generate coverage report | |
run: pipx run coverage lcov -o coverage.lcov | |
- name: Upload partial coverage report | |
uses: coverallsapp/github-action@master | |
with: | |
path-to-lcov: coverage.lcov | |
github-token: ${{ secrets.github_token }} | |
flag-name: ${{ matrix.platform }} - py${{ matrix.python }} | |
parallel: true | |
finalize: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Finalize coverage report | |
uses: coverallsapp/github-action@master | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
parallel-finished: true | |
publish: | |
needs: finalize | |
if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: {python-version: "3.10"} | |
- name: Retrieve pre-built distribution files | |
uses: actions/download-artifact@v3 | |
with: {name: python-distribution-files, path: dist/} | |
- name: Ensure main Jupyter notebook runs without error | |
run: | | |
pip install nbconvert | |
pip install -e . | |
jupyter nbconvert --to notebook --execute notebooks/4.2-paho-mqtt-colab-sdl-demo-test.ipynb | |
env: | |
HIVEMQ_USERNAME: ${{ secrets.HIVEMQ_USERNAME }} | |
HIVEMQ_PASSWORD: ${{ secrets.HIVEMQ_PASSWORD }} | |
HIVEMQ_HOST: ${{ secrets.HIVEMQ_HOST }} | |
- name: Publish Package | |
env: | |
# TODO: Set your PYPI_TOKEN as a secret using GitHub UI | |
# - https://pypi.org/help/#apitoken | |
# - https://docs.github.com/en/actions/security-guides/encrypted-secrets | |
TWINE_REPOSITORY: pypi | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
run: pipx run --spec tox==3.27.1 tox -e publish | |
- name: Prepare device code zip file | |
run: | | |
mkdir light-release | |
cp -r src/public_mqtt_sdl_demo/lib/ light-release/ | |
cp src/public_mqtt_sdl_demo/main.py light-release/ | |
cp src/public_mqtt_sdl_demo/hivemq-com-chain.der light-release/ | |
cp src/public_mqtt_sdl_demo/sample_secrets.py light-release/secrets.py | |
cd light-release | |
zip -r sdl_demo.zip * | |
cd .. | |
mkdir liquid-release | |
cp -r src/public_mqtt_sdl_demo/lib/ liquid-release/ | |
cp src/public_mqtt_sdl_demo/main_liquid.py liquid-release/main.py # rename to main.py | |
cp src/public_mqtt_sdl_demo/hivemq-com-chain.der liquid-release/ | |
cp src/public_mqtt_sdl_demo/sample_secrets.py liquid-release/secrets.py | |
cd liquid-release | |
zip -r sdl_demo_liquid.zip * | |
- name: Create Release # https://github.com/softprops/action-gh-release | |
uses: softprops/action-gh-release@v1 | |
with: | |
body: ${{steps.build_changelog.outputs.changelog}} | |
files: | | |
light-release/sdl_demo.zip | |
liquid-release/sdl_demo_liquid.zip |