ci-unittest #120
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: ci-unittest | |
# This workflow runs unittests on multiple Python versions, | |
# and uploads the coverage report to Codecov. | |
# | |
# This workflow is triggered by: | |
# - a manual trigger | |
# - a push to the repository with changes in the certain paths | |
# - a pull request to the master branch | |
# - a monthly schedule | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- '**' | |
paths: | |
- '.github/workflows/ci-unittest.yml' | |
- 'bin/**' | |
- 'shadowsocks_manager/**' | |
- '!shadowsocks_manager/uwsgi.ini' | |
- 'pyproject.toml' | |
- 'setup.cfg' | |
- 'setup.py' | |
- 'tox.ini' | |
tags-ignore: | |
- "**" | |
pull_request: | |
branches: | |
- master | |
schedule: | |
- cron: '23 11 1 * *' | |
jobs: | |
check-run-history: | |
runs-on: ubuntu-latest | |
outputs: | |
RUN_HISTORY: ${{ steps.check-run.outputs.RUN_HISTORY }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Check run history | |
id: check-run | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
run_history=$(gh api repos/:owner/:repo/actions/workflows/ci-unittest.yml/runs --jq '.workflow_runs | map(select(.head_sha == "${{ github.sha }}" and .id != '${{ github.run_id }}')) | length') | |
echo "$run_history run(s) found." | |
echo "RUN_HISTORY=$run_history" >> $GITHUB_OUTPUT | |
unittest: | |
runs-on: ubuntu-latest | |
needs: check-run-history | |
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' || github.event_name == 'schedule' || (github.event_name == 'push' && needs.check-run-history.outputs.RUN_HISTORY == '0') }} | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] | |
steps: | |
- name: Install system packages | |
run: | | |
echo -e '#!/usr/bin/env bash\n' | sudo tee /usr/sbin/sendmail | |
sudo chmod 755 /usr/sbin/sendmail | |
- name: Set up Python for tox | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install tox | |
run: | | |
pip install --upgrade pip | |
pip install tox | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python for test ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Run Django testcases | |
run: | | |
undotted_py_version=$(echo "${{ matrix.python-version }}" | tr -d .) | |
echo "UNDOTTED_PY_VERSION=${undotted_py_version}" >> $GITHUB_ENV | |
tox run -e "py${undotted_py_version}" | |
- name: Upload coverage data as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-py${{ env.UNDOTTED_PY_VERSION }} | |
path: .tox/.coverage.py${{ env.UNDOTTED_PY_VERSION }}* | |
codecov: | |
runs-on: ubuntu-latest | |
needs: unittest | |
steps: | |
- name: Set up Python for tox | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install tox | |
run: | | |
pip install --upgrade pip | |
pip install tox | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download all coverage data from artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: coverage-py* | |
path: .tox | |
merge-multiple: true | |
- run: ls -la .tox/.coverage.py* | |
- name: Combine coverage data and Generate coverage report | |
run: tox run -e cov | |
- name: Upload coverage report to Codecov | |
continue-on-error: true # codecov uploader occasionally fails, e.g.: upstream request timeout | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
run: tox run -e codecov |