Skip to content

.github/workflows/main.yml: Fix coverage upload to Coveralls #649

.github/workflows/main.yml: Fix coverage upload to Coveralls

.github/workflows/main.yml: Fix coverage upload to Coveralls #649

Workflow file for this run

# actions can be run locally using act and docker, on Fedora 37 also with podman, using:
# https://github.com/nektos/act
# sudo dnf install -y act-cli podman-docker
# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml
name: Unit tests
concurrency: # On new workflow, cancel old workflows from the same PR, branch or tag:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# Checks can be skipped by adding "skip-checks: true" to a commit message,
# or requested by adding "request-checks: true" if disabled by default for pushes:
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#skipping-and-requesting-checks-for-individual-commits
on: [push, pull_request]
env:
PYTHONWARNINGS: "ignore:DEPRECATION"
PIP_ROOT_USER_ACTION: "ignore" # For local testing using act-cli
PIP_NO_WARN_SCRIPT_LOCATION: "0" # For local testing using act-cli
PIP_DISABLE_PIP_VERSION_CHECK: "1" # Reduce noise in logs
jobs:
test:
strategy:
# See: https://github.com/xenserver/python-libs/pull/26#discussion_r1179482169
# max-parallel: 1
# Want to get the results of all the tests, don't terminate all on a fail:
fail-fast: false
matrix:
include:
- python-version: '3.6'
os: ubuntu-20.04
- python-version: '3.10'
os: ubuntu-22.04
- python-version: '3.11'
os: ubuntu-22.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed by diff-cover to get the changed lines: origin/master..HEAD
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python 2.7 from Ubuntu 20.04 using apt-get install
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: sudo apt-get update && sudo apt-get install -y python2-dev
- name: Install missing cpio in containers of nektos/act
if: ${{ github.actor == 'nektos/act'}}
run: apt-get update && apt-get install -y cpio
- name: Run of tox on ubuntu-latest
if: ${{ startsWith(matrix.python-version, '3.') && matrix.python-version != 3.6 }}
run: |
pip install 'virtualenv<20.22' 'tox==4.5.1' tox-gh-actions
tox --workdir .github/workflows/.tox --recreate
# tox >= 4.0.0 is needed for using optional-dependencies from pyproject.toml, which is
# is not available for python <= 3.6, so use the python3.8 of Ubuntu-20.04 to install it:
- name: Run tox for 3.6 and 3.8 on ${{ matrix.os }}'s 3.8 to get 'extras' from pyproject.toml)
if: ${{ matrix.python-version == 2.7 || matrix.python-version == 3.6 }}
run: |
set -xv;curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py
# The alternative is installing python3-pip but we don't need full pip function for now:
# sudo apt-get update && sudo apt-get install -y python3-pip
# Let tox-gh-actions get the environment(s) to run tests with from tox.ini:
# Use tox==4.5.1: tox>=4 is needed for reading the extras from pyproject.toml
# Warning: tox>=4.5.2 depends on virutalenv>=20.23, which breaks Python 2.7:
python3.8 -m pip install 'virtualenv<20.22' 'tox==4.5.1' tox-gh-actions
tox --workdir .github/workflows/.tox --recreate
- name: Select the coverage file for upload
if: |
( matrix.python-version = '3.6' || matrix.python-version == '3.11' ) &&
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
id: coverage
run: >
mv $( ls -t .github/workflows/.tox/*/log/.coverage | head -1 ) .;
mv $( ls -t .github/workflows/.tox/*/log/coverage.xml | head -1 ) .
# The new reliable Codecov upload requires Codecov to query the GitHub API to check
# the repo and the commit. The repo (or organisation) owner needs to login to
# codev, generated the CODECOV_TOKEN and save it as a secret in the ORG or the repo:
# https://docs.codecov.com/docs/adding-the-codecov-token
# Links to get and set the token:
# Get the CODECOV_TOKEN: https://app.codecov.io/gh/xenserver/python-libs/settings
# Set the CODE_COV_TOKEN: https://github.com/xenserver/python-libs/settings/secrets/actions
# Without it, the API calls are rate-limited by GitHub, and the upload may fail:
# https://github.com/codecov/feedback/issues/126#issuecomment-1932658904
#
- name: Upload coverage reports to Codecov (fallback, legacy Node.js 16 action)
needs: coverage

Check failure on line 98 in .github/workflows/main.yml

View workflow run for this annotation

GitHub Actions / Unit tests

Invalid workflow file

The workflow is not valid. .github/workflows/main.yml (Line: 98, Col: 9): Unexpected value 'needs' .github/workflows/main.yml (Line: 115, Col: 9): Unexpected value 'needs'
# If CODECOV_TOKEN is not set, use the legacy tokenless Codecov action:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: ( !env.CODECOV_TOKEN && !cancelled() && github.actor != 'nektos/act' )
uses: codecov/codecov-action@v3
with:
env_vars: OS,PYTHON
# Use fail_ci_if_error: false as explained the big comment above:
# Not failing this job in this case is ok because the tox CI checks also contain
# a diff-cover check which would fail on changed lines missing coverage.
fail_ci_if_error: false
flags: ${{ matrix.python-version }}
name: Python${{ matrix.python-version }}
verbose: true
- name: Upload coverage reports to Codecov (used when secrets.CODECOV_TOKEN is set)
needs: coverage
# If CODECOV_TOKEN is set, use the new Codecov CLI to upload the coverage reports
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: env.CODECOV_TOKEN && !cancelled() && github.actor != 'nektos/act'
run: >
set -euxv;
curl -O https://cli.codecov.io/latest/linux/codecov; sudo chmod +x codecov;
./codecov upload-process --report-type coverage
--name "CLI Upload for ${{ env.PYTHON_VERSION }}"
--git-service github --fail-on-error
--flag python${{ env.PYTHON_VERSION }}
continue-on-error: false # Fail the job if the upload with CODECOV_TOKEN fails
- name: Send coverage to Coveralls (parallel)
uses: coverallsapp/github-action@v1
with:
parallel: true
finish:
needs: test
if: $
runs-on: ubuntu-latest
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v1
with:
parallel-finished: true