Skip to content

solved(python): programmers #38

solved(python): programmers

solved(python): programmers #38

Workflow file for this run

name: Run Tests for Python Problems
on:
push:
branches:
- main
env:
DEFAULT_PYTHON_VERSION: 3.12
PROGRAMMERS_PYTHON_VERSION: 3.8
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.detect-changes.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect changed files
id: detect-changes
run: |
git config core.quotepath false
if git rev-parse HEAD~1 >/dev/null 2>&1; then
base_commit="HEAD~1"
else
base_commit="HEAD"
fi
changed_dirs=$(git diff --name-only $base_commit HEAD | sed 's/^"//;s/"$//' | grep -E '.py$' | awk -F'/' '{OFS="/"; $NF=""; print $0}' | sed 's/\/$//' | sort -u || true)
json="["
for dir in $changed_dirs; do
if [ -d "$dir" ]; then
json+="{\"dir\":\"$dir\","
if [[ "$dir" == programmers* ]]; then
json+="\"python_version\":\"${{ env.PROGRAMMERS_PYTHON_VERSION }}\"},"
else
json+="\"python_version\":\"${{ env.DEFAULT_PYTHON_VERSION }}\"},"
fi
fi
done
json="${json%,}]"
echo "matrix=$json" >> $GITHUB_OUTPUT
shell: bash
run-tests:
needs: detect-changes
runs-on: ubuntu-latest
if: needs.detect-changes.outputs.matrix != '[]'
strategy:
matrix:
include: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest parameterized
- name: Run Tests
run: |
pytest ${{ matrix.dir }}/test_main.py