CI Unit tests #103
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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: CI Unit tests | |
on: | |
workflow_dispatch: | |
inputs: | |
archive_webhost_logging: | |
description: "For debugging purposes, archive test webhost logs" | |
required: false | |
default: "false" | |
schedule: | |
# Monday to Thursday 3 AM CST build | |
# * is a special character in YAML so you have to quote this string | |
- cron: "0 8 * * 1,2,3,4" | |
push: | |
pull_request: | |
branches: [ dev, main, release/* ] | |
jobs: | |
build: | |
name: "Python UT CI Run" | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ] | |
permissions: read-all | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Set up Dotnet 8.0.x | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "8.0.x" | |
- name: Install dependencies and the worker | |
run: | | |
retry() { | |
local -r -i max_attempts="$1"; shift | |
local -r cmd="$@" | |
local -i attempt_num=1 | |
until $cmd | |
do | |
if (( attempt_num == max_attempts )) | |
then | |
echo "Attempt $attempt_num failed and there are no more attempts left!" | |
return 1 | |
else | |
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..." | |
sleep 1 | |
fi | |
done | |
} | |
python -m pip install --upgrade pip | |
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U azure-functions --pre | |
python -m pip install -U -e .[dev] | |
if [[ "${{ matrix.python-version }}" != "3.7" ]]; then | |
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --pre -U -e .[test-http-v2] | |
fi | |
# Retry a couple times to avoid certificate issue | |
retry 5 python setup.py build | |
retry 5 python setup.py webhost --branch-name=dev | |
retry 5 python setup.py extension | |
mkdir logs | |
- name: Test with pytest | |
env: | |
AzureWebJobsStorage: ${{ secrets.LinuxStorageConnectionString310 }} # needed for installing azure-functions-durable while running setup.py | |
ARCHIVE_WEBHOST_LOGS: ${{ github.event.inputs.archive_webhost_logging }} | |
run: | | |
python -m pytest -q -n auto --dist loadfile --reruns 4 --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch tests/unittests | |
- name: Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.xml # optional | |
flags: unittests # optional | |
name: codecov # optional | |
fail_ci_if_error: false # optional (default = false) | |
- name: Publish Logs to Artifact | |
if: failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Test WebHost Logs ${{ github.run_id }} ${{ matrix.python-version }} | |
path: logs/*.log | |
if-no-files-found: ignore |