Merge pull request #25 from PyMoDAQ/malik-irain-patch-1 #9
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: tests | |
on: | |
workflow_call: | |
pull_request: | |
push: | |
branches: | |
- '*' | |
- '!badges' # to exclude execution if someone pushes on this branch (shouldn't happen) | |
concurrency: | |
# github.workflow: name of the workflow | |
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
# Cancel in-progress runs when a new workflow with the same group name is triggered | |
cancel-in-progress: true | |
jobs: | |
tests: | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: | |
os: ["ubuntu-latest", "windows-latest"] | |
python-version: ["3.9", "3.10", "3.11", "3.12"] | |
runs-on: ${{ matrix.os }} | |
steps: | |
# Get the branch name for the badge generation | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_REF#refs/heads/}" >> "${GITHUB_OUTPUT}" | |
id: extract_branch | |
- name: Checkout the repo | |
uses: actions/[email protected] | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/[email protected] | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install flake8 pytest pytest-cov pytest-xdist wheel numpy h5py | |
pip install -e . | |
# Create folder and set permissions on Ubuntu | |
- name: Create local pymodaq folder (Ubuntu) | |
if: runner.os == 'Linux' | |
run: | | |
sudo mkdir -p /etc/.pymodaq | |
sudo chmod uo+rw /etc/.pymodaq | |
- name: Linting with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=docs | |
- name: Tests with ${{ matrix.os }} ${{ matrix.python-version }} | |
id: tests | |
run: | | |
mkdir coverage | |
pytest --cov=pymodaq_data -n 1 | |
mv .coverage coverage/coverage_${{ matrix.os }}_${{ matrix.python-version }} | |
- name: Upload coverage artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-${{ matrix.os }}-${{ matrix.python-version }} | |
path: coverage/coverage_${{ matrix.os }}_${{ matrix.python-version }} | |
- name: Create destination directory | |
if: ${{ always() }} | |
run: | | |
mkdir -p "${{ steps.extract_branch.outputs.branch }}" | |
- name: generate badge (success) | |
if: ${{ success() }} | |
uses: emibcn/[email protected] | |
with: | |
label: '' | |
status: 'passing' | |
color: 'green' | |
path: '${{ steps.extract_branch.outputs.branch }}/tests_${{runner.os}}_${{matrix.python-version}}.svg' | |
- name: generate badge (fail) | |
if: ${{ failure() }} | |
uses: emibcn/[email protected] | |
with: | |
label: '' | |
status: 'failing' | |
color: 'red' | |
path: '${{ steps.extract_branch.outputs.branch }}/tests_${{runner.os}}_${{matrix.python-version}}.svg' | |
- name: Upload badge artifact | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tests_${{runner.os}}_${{matrix.python-version}} | |
path: '${{ steps.extract_branch.outputs.branch }}/tests_${{runner.os}}_${{matrix.python-version}}.svg' | |
if-no-files-found: error | |
outputs: | |
branch: ${{ steps.extract_branch.outputs.branch }} | |
badge-update: | |
runs-on: ubuntu-latest | |
needs: tests # Ensure this job runs after all matrix jobs complete | |
steps: | |
# switch to badges branches to commit | |
- uses: actions/checkout@v4 | |
with: | |
ref: badges | |
- name: Download badges | |
uses: actions/download-artifact@v4 | |
- name: Reorganize badges | |
run: | | |
rm -rf coverage* || true | |
rm -rf $(git ls-files ${{ needs.tests.outputs.branch }}/*) || true | |
git rm $(git ls-files ${{ needs.tests.outputs.branch }}/*) || true | |
mkdir -p '${{ needs.tests.outputs.branch }}' | |
mv tests_*/*.svg '${{ needs.tests.outputs.branch }}' | |
- name: Commit badges | |
continue-on-error: true | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add ${{ needs.tests.outputs.branch }} | |
git commit --allow-empty -m "Add/Update badge" | |
- name: Push badges | |
uses: ad-m/github-push-action@master | |
if: ${{ success() }} | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: badges | |
coverage-update: | |
runs-on: ubuntu-latest | |
needs: tests # Ensure this job runs after all matrix jobs complete | |
steps: | |
- name: Checkout the repo | |
uses: actions/[email protected] | |
- name: Download all coverage artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./coverage-reports | |
- name: Reorganize reports | |
run: | | |
cd coverage-reports | |
rm -rf tests_* | |
for folder in *; do | |
mv "${folder}"/* .; | |
done; | |
rmdir --ignore-fail-on-non-empty * || true | |
cd .. | |
# We only combine linux reports otherwise the tool complains about windows directories ... | |
- name: Combine coverage reports | |
run: | | |
python -m pip install coverage | |
coverage combine ./coverage-reports/coverage_* | |
coverage xml -i | |
- name: Upload combined coverage report to Codecov | |
uses: codecov/[email protected] | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: coverage.xml |