Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.

Commit c482899

Browse files
authored
Merge pull request #52 from davfive/copilot/add-reusable-workflow-python-tests
Add reusable workflow and composite actions for Python tests
2 parents 93fef8e + 6cdc5dc commit c482899

File tree

4 files changed

+150
-2
lines changed

4 files changed

+150
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "python-tests: WSL steps"
2+
description: "Reusable WSL-specific steps for tests: setup WSL, install Python, install deps, lint, test and conditional coverage upload."
3+
inputs:
4+
python-version:
5+
description: "Python version to install/run (e.g. 3.13)"
6+
required: true
7+
os:
8+
description: "OS name from the matrix (e.g. ubuntu-latest) - used for conditional uploads"
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Set up WSL
14+
uses: Vampire/setup-wsl@v3
15+
with:
16+
distribution: Ubuntu-22.04
17+
use-cache: false
18+
19+
- name: Set up Python (WSL)
20+
shell: wsl-bash {0}
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y software-properties-common
24+
sudo add-apt-repository -y ppa:deadsnakes/ppa
25+
sudo apt-get update
26+
if [ "${{ inputs.python-version }}" = "3.13" ] || [ "${{ inputs.python-version }}" = "3.12" ]; then
27+
sudo apt-get install -y python${{ inputs.python-version }} python${{ inputs.python-version }}-venv python3-pip python3-setuptools || {
28+
sudo apt-get install -y python${{ inputs.python-version }} python${{ inputs.python-version }}-venv python3-pip
29+
}
30+
else
31+
sudo apt-get install -y python${{ inputs.python-version }} python${{ inputs.python-version }}-venv python${{ inputs.python-version }}-distutils python3-pip
32+
fi
33+
python${{ inputs.python-version }} --version
34+
35+
- name: Install dependencies (WSL)
36+
shell: wsl-bash {0}
37+
run: |
38+
python${{ inputs.python-version }} -m ensurepip --default-pip 2>/dev/null || true
39+
python${{ inputs.python-version }} -m pip install --upgrade pip setuptools wheel
40+
python${{ inputs.python-version }} -m pip install -e .
41+
python${{ inputs.python-version }} -m pip install -r requirements-dev.txt
42+
43+
- name: Lint (WSL)
44+
shell: wsl-bash {0}
45+
run: |
46+
python${{ inputs.python-version }} -m flake8 src/gitspaces --count --select=E9,F63,F7,F82 --show-source --statistics
47+
python${{ inputs.python-version }} -m flake8 src/gitspaces --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
48+
49+
- name: Run tests (WSL)
50+
shell: wsl-bash {0}
51+
run: |
52+
python${{ inputs.python-version }} -m pytest tests/ -v --cov=src/gitspaces --cov-report=xml --cov-report=term
53+
54+
- name: Upload coverage to Codecov (WSL)
55+
if: ${{ inputs.os == 'ubuntu-latest' && inputs.python-version == '3.11' }}
56+
uses: codecov/codecov-action@v4
57+
with:
58+
file: ./coverage.xml
59+
flags: unittests
60+
name: codecov-umbrella
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "python-tests: non-WSL steps"
2+
description: "Reusable non-WSL steps for tests: setup-python, install deps, lint, test and conditional coverage upload."
3+
inputs:
4+
python-version:
5+
description: "Python version to use (e.g. 3.11)"
6+
required: true
7+
os:
8+
description: "OS name from the matrix (e.g. ubuntu-latest) - used for conditional uploads"
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Set up Python (non-WSL)
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: ${{ inputs.python-version }}
17+
18+
- name: Install dependencies (non-WSL)
19+
shell: bash
20+
run: |
21+
python -m pip install --upgrade pip setuptools wheel
22+
pip install -e .
23+
pip install -r requirements-dev.txt
24+
25+
- name: Lint (non-WSL)
26+
shell: bash
27+
run: |
28+
flake8 src/gitspaces --count --select=E9,F63,F7,F82 --show-source --statistics
29+
flake8 src/gitspaces --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
30+
31+
- name: Check code formatting with black (non-WSL)
32+
shell: bash
33+
run: |
34+
black --check src/gitspaces tests
35+
36+
- name: Run tests (non-WSL)
37+
shell: bash
38+
run: |
39+
pytest tests/ -v --cov=src/gitspaces --cov-report=xml --cov-report=term
40+
41+
- name: Upload coverage to Codecov (non-WSL)
42+
if: ${{ inputs.os == 'ubuntu-latest' && inputs.python-version == '3.11' }}
43+
uses: codecov/codecov-action@v4
44+
with:
45+
file: ./coverage.xml
46+
flags: unittests
47+
name: codecov-umbrella
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Reusable workflow: .github/workflows/python-tests-reusable.yml
2+
# Called by caller workflows via "uses: ./.github/workflows/python-tests-reusable.yml"
3+
on:
4+
workflow_call:
5+
inputs:
6+
matrix:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
test:
12+
strategy:
13+
fail-fast: false
14+
matrix: ${{ fromJson(inputs.matrix) }}
15+
runs-on: ${{ matrix.os }}
16+
permissions:
17+
contents: read
18+
19+
defaults:
20+
run:
21+
shell: ${{ matrix.shell == 'cmd' && 'cmd' || matrix.shell == 'pwsh' && 'pwsh' || matrix.shell == 'wsl-bash' && 'wsl-bash {0}' || 'bash' }}
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
# Delegate all WSL-specific steps into local composite action
28+
- name: WSL steps (composite)
29+
if: ${{ matrix.shell == 'wsl-bash' }}
30+
uses: ./.github/actions/python-tests/test-steps-wsl
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
os: ${{ matrix.os }}
34+
35+
# Delegate non-WSL steps into local composite action
36+
- name: Non-WSL steps (composite)
37+
if: ${{ matrix.shell != 'wsl-bash' }}
38+
uses: ./.github/actions/python-tests/test-steps
39+
with:
40+
python-version: ${{ matrix.python-version }}
41+
os: ${{ matrix.os }}

.github/workflows/python-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Python Tests
22

33
on:
44
workflow_dispatch:
5-
branches: [ main, d5.**, copilot/** ]
5+
branches: [ main, d5.**, copilot/**, ci/** ]
66
push:
7-
branches: [ main, d5.**, copilot/** ]
7+
branches: [ main, d5.**, copilot/**, ci/** ]
88
pull_request:
99
branches: [ main ]
1010
permissions:

0 commit comments

Comments
 (0)