add a type hint #75
This file contains hidden or 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
| # This workflow will install Python dependencies, run tests and lint with a single version of Python | |
| name: Python application | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| paths: [ '**/*.py' ] | |
| pull_request: | |
| branches: [ "main" ] | |
| paths: [ '**/*.py' ] | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: [ "3.7", "3.8", "3.9", "3.10" ] | |
| steps: | |
| - | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch the entire Git history to ensure all commits are available | |
| - | |
| name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - | |
| name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 pytest pylint | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - | |
| name: Lint with flake8 | |
| run: | | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - | |
| name: Lint directories with pylint | |
| run: | | |
| for dir in heatmaps chmutils chmengine tooltips tests; do | |
| if [ -d "$dir" ]; then | |
| pylint "$dir" --exit-zero | |
| fi | |
| done | |
| if [ -f main.py ]; then pylint main.py --exit-zero; fi | |
| - | |
| name: Debug GITHUB_EVENT_PATH (remove in production) | |
| run: cat $GITHUB_EVENT_PATH | |
| - | |
| name: Get changed files | |
| id: get_files | |
| run: | | |
| CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} || echo "") | |
| if [ -z "$CHANGED_FILES" ]; then | |
| echo "No changed files found." | |
| echo "files=" >> $GITHUB_ENV | |
| else | |
| # Convert newline-separated file list to space-separated | |
| echo "Changed files: $CHANGED_FILES" | |
| echo "files=$(echo $CHANGED_FILES | tr '\n' ' ')" >> $GITHUB_ENV | |
| fi | |
| - | |
| name: Run affected unit tests | |
| run: | | |
| python .github/scripts/scripts_analyze_dependencies.py "${{ env.files }}" | while read test_file; do | |
| if [ -f "$test_file" ]; then | |
| echo "Running $test_file" | |
| python -m unittest "$test_file" | |
| else | |
| echo "Test file $test_file does not exist. Skipping." | |
| fi | |
| done |